static SortedSet<String> getUnmodifiableSortedSet(String[] array, Comparator<Object> collator) { if(array==null || array.length==0) return AoCollections.emptySortedSet(); if(array.length==1) return AoCollections.singletonSortedSet(array[0]); SortedSet<String> sortedSet = new TreeSet<String>(collator); sortedSet.addAll(Arrays.asList(array)); return Collections.unmodifiableSortedSet(sortedSet); }
static SortedSet<String> getUnmodifiableSortedSet(Collection<String> collection, Comparator<Object> collator) { if(collection==null || collection.isEmpty()) return AoCollections.emptySortedSet(); if(collection.size()==1) return AoCollections.singletonSortedSet(collection.iterator().next()); SortedSet<String> sortedSet = new TreeSet<String>(collator); sortedSet.addAll(collection); return Collections.unmodifiableSortedSet(sortedSet); }
@Override public SortedSet<E> headSet(E toElement) { if(ObjectUtils.equals(element, toElement)) return emptySortedSet(); throw new IllegalArgumentException(); }
/** * Gets the optimal implementation for unmodifiable sorted set. * If sorted set is empty, uses <code>emptySortedSet</code>. * If sorted set has one element, uses <code>singletonSortedSet</code>. * Otherwise, wraps the sorted set with <code>Collections.unmodifiableSortedSet</code>. */ public static <T> SortedSet<T> optimalUnmodifiableSortedSet(SortedSet<T> sortedSet) { int size = sortedSet.size(); if(size==0) return emptySortedSet(); Class<?> clazz = sortedSet.getClass(); for(int i=0, len=unmodifiableSortedSetClasses.length; i<len; i++) if(unmodifiableSortedSetClasses[i]==clazz) return sortedSet; if(size==1) return singletonSortedSet(sortedSet.first()); return Collections.unmodifiableSortedSet(sortedSet); }
/** * Performs defensive shallow copy and returns unmodifiable sorted set. */ public static <T> SortedSet<T> unmodifiableCopySortedSet(Collection<? extends T> collection) { int size = collection.size(); if(size==0) return emptySortedSet(); // TODO: Create an unmodifiable collection that can only be populated here, and reused. // TODO: Goal is to protect from changes to original collection, while also not having // TODO: to copy repeatedly when different components use this same method for protection. // TODO: Also allow standard Collections singleton //Class<?> clazz = collection.getClass(); //for(int i=0, len=unmodifiableSortedSetClasses.length; i<len; i++) if(unmodifiableSortedSetClasses[i]==clazz) return (SortedSet<T>)collection; if(size==1) return singletonSortedSet(collection.iterator().next()); SortedSet<T> copy; if(collection instanceof SortedSet) { copy = new TreeSet<T>((SortedSet<? extends T>)collection); } else { copy = new TreeSet<T>(collection); } return Collections.unmodifiableSortedSet(copy); }
@Override public SortedSet<E> subSet(E fromElement, E toElement) { if(ObjectUtils.equals(element, fromElement) && ObjectUtils.equals(element, toElement)) return emptySortedSet(); throw new IllegalArgumentException(); }
SortedSet<String> newAddresses = newDnsLookupResult.getAddresses(); SortedSet<String> oldAddresses = oldDnsLookupResult==null ? null : oldDnsLookupResult.getAddresses(); if(oldAddresses==null) oldAddresses = AoCollections.emptySortedSet(); if(!newAddresses.equals(oldAddresses)) { logger.log( if(oldStatusMessages==null) oldStatusMessages = AoCollections.emptySortedSet(); if(!newStatusMessages.equals(oldStatusMessages)) { for(String statusMessage : newStatusMessages) { SortedSet<String> newAddresses = newDnsLookupResult.getAddresses(); SortedSet<String> oldAddresses = oldDnsLookupResult==null ? null : oldDnsLookupResult.getAddresses(); if(oldAddresses==null) oldAddresses = AoCollections.emptySortedSet(); if(!newAddresses.equals(oldAddresses)) { logger.log( if(oldStatusMessages==null) oldStatusMessages = AoCollections.emptySortedSet(); if(!newStatusMessages.equals(oldStatusMessages)) { for(String statusMessage : newStatusMessages) {