@Test public void addStringValues() { final Set<String> commonNames = new HashSet<>(); commonNames.add("Bill Wallace"); commonNames.add("William Wallace"); final Set<byte[]> binaryCommonNames = new HashSet<>(); binaryCommonNames.add("Bill Wallace".getBytes(StandardCharsets.UTF_8)); binaryCommonNames.add("William Wallace".getBytes(StandardCharsets.UTF_8)); final LdapAttribute la = new LdapAttribute(); la.setName("cn"); la.addStringValues(commonNames); Assert.assertNotNull(la.getStringValue()); Assert.assertNotNull(la.getStringValues()); Assert.assertNotNull(la.getBinaryValue()); Assert.assertNotNull(la.getBinaryValues()); Assert.assertEquals(la.getStringValues().size(), 2); Assert.assertEquals(la.getBinaryValues().size(), 2); Assert.assertTrue(la.getStringValues().contains("Bill Wallace")); Assert.assertTrue(la.getStringValues().contains("William Wallace")); Assert.assertEqualsNoOrder(commonNames.toArray(new String[2]), la.getStringValues().toArray(new String[2])); Assert.assertEquals(binaryCommonNames.size(), la.getBinaryValues().size()); for (byte[] b : binaryCommonNames) { Assert.assertTrue(la.getBinaryValues().stream().anyMatch(a -> Arrays.equals(a, b))); } la.clear(); Assert.assertEquals(la.size(), 0); }
public void addStringValues(final String... value) { Stream.of(value) .filter(Objects::nonNull) .map(v -> { if (binary) { try { return LdapUtils.base64Decode(v); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Error decoding " + v + " for " + attributeName, e); } } return v.getBytes(StandardCharsets.UTF_8); }) .filter(Objects::nonNull) .map(ByteBuffer::wrap) .forEach(attributeValues::add); }
LdapAttribute { public void addStringValues(final String... value) { Stream.of(value) .filter(Objects::nonNull) .map(v -> { if (binary) { try { return LdapUtils.base64Decode(v); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Error decoding " + v + " for " + attributeName, e); } } return v.getBytes(StandardCharsets.UTF_8); }) .filter(Objects::nonNull) .map(ByteBuffer::wrap) .forEach(attributeValues::add); } }
LdapAttribute { public void addStringValues(final String... value) { Stream.of(value) .filter(Objects::nonNull) .map(v -> { if (binary) { try { return LdapUtils.base64Decode(v); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Error decoding " + v + " for " + attributeName, e); } } return v.getBytes(StandardCharsets.UTF_8); }) .filter(Objects::nonNull) .map(ByteBuffer::wrap) .forEach(attributeValues::add); } LdapAttribute();  LdapAttribute(final String type);  LdapAttribute(final String type, final byte[]... value);  LdapAttribute(final String type, final String... value); }
LdapAttribute { public void addStringValues(final String... value) { Stream.of(value) .filter(Objects::nonNull) .map(v -> { if (binary) { try { return LdapUtils.base64Decode(v); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Error decoding " + v + " for " + attributeName, e); } } return v.getBytes(StandardCharsets.UTF_8); }) .filter(Objects::nonNull) .map(ByteBuffer::wrap) .forEach(attributeValues::add); } LdapAttribute();  LdapAttribute(final String type);  LdapAttribute(final String type, final byte[]... value);  LdapAttribute(final String type, final String... value); void setName(final String type); boolean isBinary(); void setBinary(final boolean b); void configureBinary(final String... attrNames); String getName(); String getName(final boolean withOptions); List<String> getOptions(); byte[] getBinaryValue(); Collection<byte[]> getBinaryValues(); String getStringValue(); Collection<String> getStringValues(); T getValue(final Function<byte[], T> func); Collection<T> getValues(final Function<byte[] , T> func); void addBinaryValues(final byte[]... value); void addBinaryValues(final Collection<byte[]> values); void addStringValues(final String... value); void addStringValues(final Collection<String> values); void addBufferValues(final ByteBuffer... values); void addBufferValues(final Collection<ByteBuffer> values); @SuppressWarnings("unchecked") void addValues(final Function<T, byte[]> func, final T... value); void addValues(final Function<T, byte[]> func, final Collection<T> values); void removeBinaryValues(final byte[]... value); void removeBinaryValues(final Collection<byte[]> values); void removeStringValues(final String... value); void removeStringValues(final Collection<String> values); void removeBufferValues(final ByteBuffer... values); void removeBufferValues(final Collection<ByteBuffer> values); int size(); void clear(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); static LdapAttribute sort(final LdapAttribute la); static String escapeValue(final String value); static Builder builder(); }
LdapAttribute { public void addStringValues(final String... value) { Stream.of(value) .filter(Objects::nonNull) .map(v -> { if (binary) { try { return LdapUtils.base64Decode(v); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Error decoding " + v + " for " + attributeName, e); } } return v.getBytes(StandardCharsets.UTF_8); }) .filter(Objects::nonNull) .map(ByteBuffer::wrap) .forEach(attributeValues::add); } LdapAttribute();  LdapAttribute(final String type);  LdapAttribute(final String type, final byte[]... value);  LdapAttribute(final String type, final String... value); void setName(final String type); boolean isBinary(); void setBinary(final boolean b); void configureBinary(final String... attrNames); String getName(); String getName(final boolean withOptions); List<String> getOptions(); byte[] getBinaryValue(); Collection<byte[]> getBinaryValues(); String getStringValue(); Collection<String> getStringValues(); T getValue(final Function<byte[], T> func); Collection<T> getValues(final Function<byte[] , T> func); void addBinaryValues(final byte[]... value); void addBinaryValues(final Collection<byte[]> values); void addStringValues(final String... value); void addStringValues(final Collection<String> values); void addBufferValues(final ByteBuffer... values); void addBufferValues(final Collection<ByteBuffer> values); @SuppressWarnings("unchecked") void addValues(final Function<T, byte[]> func, final T... value); void addValues(final Function<T, byte[]> func, final Collection<T> values); void removeBinaryValues(final byte[]... value); void removeBinaryValues(final Collection<byte[]> values); void removeStringValues(final String... value); void removeStringValues(final Collection<String> values); void removeBufferValues(final ByteBuffer... values); void removeBufferValues(final Collection<ByteBuffer> values); int size(); void clear(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); static LdapAttribute sort(final LdapAttribute la); static String escapeValue(final String value); static Builder builder();  }