public void incr(final Attribute attr, final Object value) { _changes.put(attr.field.getName(), new Ternary<>(attr, true, value)); }
public static byte[] buildAndSaveKeystore(final List<Ternary<String, String, String>> certs, final String storePassword) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, InvalidKeySpecException { final KeyStore ks = KeyStore.getInstance("JKS"); ks.load(null, storePassword != null ? storePassword.toCharArray() : null); //name,cert,key for (final Ternary<String, String, String> cert : certs) { if (cert.third() == null) { final Certificate c = buildCertificate(cert.second()); ks.setCertificateEntry(cert.first(), c); } else { final Certificate[] c = new Certificate[certs.size()]; int i = certs.size(); for (final Ternary<String, String, String> ct : certs) { c[i - 1] = buildCertificate(ct.second()); i--; } ks.setKeyEntry(cert.first(), buildPrivateKey(cert.third()), storePassword != null ? storePassword.toCharArray() : null, c); } } final ByteArrayOutputStream os = new ByteArrayOutputStream(); ks.store(os, storePassword != null ? storePassword.toCharArray() : null); os.close(); return os.toByteArray(); }
public static StringBuilder buildMysqlUpdateSql(final String joins, final Collection<Ternary<Attribute, Boolean, Object>> setters) { if (setters.size() == 0) { return null; } final StringBuilder sql = new StringBuilder("UPDATE "); sql.append(joins); sql.append(" SET "); for (final Ternary<Attribute, Boolean, Object> setter : setters) { final Attribute attr = setter.first(); sql.append(attr.table).append(".").append(attr.columnName).append("="); if (setter.second() != null) { sql.append(attr.table).append(".").append(attr.columnName).append(setter.second() ? "+" : "-"); } sql.append("?, "); } sql.delete(sql.length() - 2, sql.length()); sql.append(" WHERE "); return sql; }
@Test public void testEquals() { Assert.assertEquals(new Ternary<>("a", "b", "c"), new Ternary<>("a", "b", "c")); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(new Ternary<>("a", "b", "d"))); Assert.assertFalse(new Ternary<>("a", "b", "c").equals("")); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(null)); Assert.assertFalse(new Ternary<>("a", "b", "c").equals(new Pair<>("a", "b"))); } }
@Override public void execute() { ListResponse<HostResponse> response = null; if (getVirtualMachineId() == null) { response = _queryService.searchForServers(this); } else { final Pair<List<? extends Host>, Integer> result; final Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>> hostsForMigration = _mgr.listHostsForMigrationOfVM(getVirtualMachineId(), getStartIndex(), getPageSizeVal(), null); result = hostsForMigration.first(); final List<? extends Host> hostsWithCapacity = hostsForMigration.second(); response = new ListResponse<>(); final List<HostResponse> hostResponses = new ArrayList<>(); for (final Host host : result.first()) { final HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails()); Boolean suitableForMigration = false; if (hostsWithCapacity.contains(host)) { suitableForMigration = true; } hostResponse.setSuitableForMigration(suitableForMigration); hostResponse.setObjectName("host"); hostResponses.add(hostResponse); } response.setResponses(hostResponses, result.second()); } response.setResponseName(getCommandName()); setResponseObject(response); }
public void decr(final Attribute attr, final Object value) { _changes.put(attr.field.getName(), new Ternary<>(attr, false, value)); }
protected Attribute makeChange(final String field, final Object value) { final Attribute attr = _dao._allAttributes.get(field); assert (attr == null || attr.isUpdatable()) : "Updating an attribute that's not updatable: " + field; if (attr != null) { if (attr.attache == null) { _changes.put(field, new Ternary<>(attr, null, value)); } else { if (_collectionChanges == null) { _collectionChanges = new HashMap<>(); } _collectionChanges.put(attr, value); } } return attr; }
public void set(final Object entity, final Attribute attr, final Object value) { _changes.put(attr.field.getName(), new Ternary<>(attr, null, value)); try { attr.field.set(entity, value); } catch (final IllegalArgumentException e) { throw new CloudRuntimeException("Unable to update " + attr.field.getName() + " with " + value, e); } catch (final IllegalAccessException e) { throw new CloudRuntimeException("Unable to update " + attr.field.getName() + " with " + value, e); } }