@Override public SortBehavior getSortBehavior() { return la.getSortBehavior(); }
/** * Returns an implementation of collection for the sort behavior of this bean. This implementation returns HashSet for * {@link SortBehavior#UNORDERED}, LinkedHashSet for {@link SortBehavior#ORDERED}, and TreeSet for {@link * SortBehavior#SORTED}. * * @param <E> contained in the collection * @param c type contained in the collection * * @return collection corresponding to the sort behavior */ protected <E> Collection<E> createSortBehaviorCollection(final Class<E> c) { Collection<E> values = null; if (SortBehavior.UNORDERED == getSortBehavior()) { values = new HashSet<>(); } else if (SortBehavior.ORDERED == getSortBehavior()) { values = new LinkedHashSet<>(); } else if (SortBehavior.SORTED == getSortBehavior()) { if (!c.isAssignableFrom(Comparable.class)) { values = new TreeSet<>(getComparator(c)); } else { values = new TreeSet<>(); } } return values; }
/** * Returns an implementation of collection for the sort behavior of this bean. This implementation returns HashSet for * {@link SortBehavior#UNORDERED}, LinkedHashSet for {@link SortBehavior#ORDERED}, and TreeSet for {@link * SortBehavior#SORTED}. * * @param <E> contained in the collection * @param c type contained in the collection * * @return collection corresponding to the sort behavior */ protected <E> Collection<E> createSortBehaviorCollection(final Class<E> c) { Collection<E> values = null; if (SortBehavior.UNORDERED == getSortBehavior()) { values = new HashSet<>(); } else if (SortBehavior.ORDERED == getSortBehavior()) { values = new LinkedHashSet<>(); } else if (SortBehavior.SORTED == getSortBehavior()) { if (!c.isAssignableFrom(Comparable.class)) { values = new TreeSet<>(getComparator(c)); } else { values = new TreeSet<>(); } } return values; }
/** * Returns an implementation of collection for the sort behavior of this bean. This implementation returns HashSet for * {@link SortBehavior#UNORDERED}, LinkedHashSet for {@link SortBehavior#ORDERED}, and TreeSet for {@link * SortBehavior#SORTED}. * * @param <E> contained in the collection * @param c type contained in the collection * * @return collection corresponding to the sort behavior */ protected <E> Collection<E> createSortBehaviorCollection(final Class<E> c) { Collection<E> values = null; if (SortBehavior.UNORDERED == getSortBehavior()) { values = new HashSet<>(); } else if (SortBehavior.ORDERED == getSortBehavior()) { values = new LinkedHashSet<>(); } else if (SortBehavior.SORTED == getSortBehavior()) { if (!c.isAssignableFrom(Comparable.class)) { values = new TreeSet<>(getComparator(c)); } else { values = new TreeSet<>(); } } return values; }
newAttr = new LdapAttribute(la.getSortBehavior(), la.isBinary()); newAttr.setName(attrTypeName); entry.addAttribute(newAttr);
newAttr = new LdapAttribute(la.getSortBehavior(), la.isBinary()); newAttr.setName(attrTypeName); entry.addAttribute(newAttr);
newAttr = new LdapAttribute(la.getSortBehavior(), la.isBinary()); newAttr.setName(attrTypeName); entry.addAttribute(newAttr);
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { if (attributeName.equalsIgnoreCase(la.getName())) { if (la.isBinary()) { final LdapAttribute newAttr = new LdapAttribute(la.getSortBehavior()); newAttr.setName(la.getName()); for (byte[] b : la.getBinaryValues()) { newAttr.addStringValue(convertValue(b)); } entry.addAttribute(newAttr); logger.debug("Processed attribute {}", newAttr); handleAttribute(conn, request, newAttr); } else { logger.warn("Attribute {} must be set as a binary attribute", attributeName); handleAttribute(conn, request, la); } } else { handleAttribute(conn, request, la); } } }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { if (attributeName.equalsIgnoreCase(la.getName())) { if (la.isBinary()) { final LdapAttribute newAttr = new LdapAttribute(la.getSortBehavior()); newAttr.setName(la.getName()); for (byte[] b : la.getBinaryValues()) { newAttr.addStringValue(convertValue(b)); } entry.addAttribute(newAttr); logger.debug("Processed attribute {}", newAttr); handleAttribute(conn, request, newAttr); } else { logger.warn("Attribute {} must be set as a binary attribute", attributeName); handleAttribute(conn, request, la); } } else { handleAttribute(conn, request, la); } } }
@Override protected void handleAttributes(final Connection conn, final SearchRequest request, final SearchEntry entry) throws LdapException { for (LdapAttribute la : entry.getAttributes()) { if (attributeName.equalsIgnoreCase(la.getName())) { if (la.isBinary()) { final LdapAttribute newAttr = new LdapAttribute(la.getSortBehavior()); newAttr.setName(la.getName()); for (byte[] b : la.getBinaryValues()) { newAttr.addStringValue(convertValue(b)); } entry.addAttribute(newAttr); logger.debug("Processed attribute {}", newAttr); handleAttribute(conn, request, newAttr); } else { logger.warn("Attribute {} must be set as a binary attribute", attributeName); handleAttribute(conn, request, la); } } else { handleAttribute(conn, request, la); } } }
/** Tests ordered sort behavior. */ @Test(groups = {"bean"}) public void orderedSortBehavior() { final LdapAttribute la = new LdapAttribute(SortBehavior.ORDERED); AssertJUnit.assertEquals(SortBehavior.ORDERED, la.getSortBehavior()); la.addStringValue("William", "Bill"); final String[] values = la.getStringValues().toArray(new String[2]); AssertJUnit.assertEquals("William", values[0]); AssertJUnit.assertEquals("Bill", values[1]); la.clear(); AssertJUnit.assertEquals(0, la.size()); }
/** Tests sorted sort behavior. */ @Test(groups = {"bean"}) public void sortedSortBehavior() { final LdapAttribute la = new LdapAttribute(SortBehavior.SORTED); AssertJUnit.assertEquals(SortBehavior.SORTED, la.getSortBehavior()); la.addStringValue("William", "Bill"); final String[] values = la.getStringValues().toArray(new String[2]); AssertJUnit.assertEquals("Bill", values[0]); AssertJUnit.assertEquals("William", values[1]); la.clear(); AssertJUnit.assertEquals(0, la.size()); }
/** Tests default sort behavior. */ @Test(groups = {"bean"}) public void defaultSortBehavior() { final LdapAttribute la = new LdapAttribute("givenName"); AssertJUnit.assertEquals(SortBehavior.getDefaultSortBehavior(), la.getSortBehavior()); AssertJUnit.assertEquals(0, la.size()); AssertJUnit.assertNull(la.getStringValue()); AssertJUnit.assertNull(la.getBinaryValue()); AssertJUnit.assertEquals("givenName", la.getName()); la.setName("sn"); AssertJUnit.assertEquals("sn", la.getName()); la.clear(); AssertJUnit.assertEquals(0, la.size()); }