Package net.cscott.jutil
Class Default
java.lang.Object
net.cscott.jutil.Default
Default contains one-off or 'standard, no-frills'
implementations of simple Iterators,
Collections, and Comparators.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ComparatorDeprecated.static final SortedMapDeprecated.static final MultiMapDeprecated.UseEMPTY_MULTIMAP(), which is parameterized.static final SortedSetDeprecated.static final IteratorDeprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final <T extends Comparable<T>>
Comparator<T> Deprecated.static final <E> List<E> Deprecated.UseCollections.emptyList(), which this returns.static final <K,V> SortedMap <K, V> Deprecated.static final <K,V> MultiMap <K, V> An empty multi-map, parameterized to play nicely with Java's type system.static final <E> SortedSet<E> Deprecated.static <K,V> Map.Entry <K, V> entry(K key, V value) Deprecated.UseAbstractMap.SimpleImmutableEntry, which this method now returns, orMap.entry(Object,Object), which does not permitnulls.static final <E> Iterator<E> Deprecated.static <A,B> Default.PairList <A, B> pair(A left, B right) Deprecated.UsePair, an immutable record:new Pair<>(left, right).static final <E> Iterator<E> singletonIterator(E o) AnIteratorover a singleton set.static <A> Collection<A> unmodifiableCollection(Collection<? extends A> cc) ImprovedunmodifiableCollection()class that helps w/ covariant subtyping.static final <E> Iterator<E> unmodifiableIterator(Iterator<? extends E> i) An unmodifiable version of the given iterator: itsremove()method throwsUnsupportedOperationException.
-
Field Details
-
comparator
Deprecated.UseComparator.nullsFirst(Comparator.naturalOrder()), which this is. PlainComparator.naturalOrder()is not a replacement: it throwsNullPointerExceptionwhen it comparesnull.AComparatorfor objects that implementComparable(checked dynamically at run-time).nullis less than everything else. -
nullIterator
Deprecated.UseCollections.emptyIterator(). Unlike this iterator, theremove()method ofCollections.emptyIterator()throwsIllegalStateException, notUnsupportedOperationException.AnIteratorover the empty set. -
EMPTY_SET
Deprecated.An empty set.- Since:
- 1.2
-
EMPTY_MAP
Deprecated.An empty map. Missing fromCollectionsin Java 1.2. -
EMPTY_MULTIMAP
Deprecated.UseEMPTY_MULTIMAP(), which is parameterized.An empty multi-map.
-
-
Constructor Details
-
Default
public Default()
-
-
Method Details
-
comparator
Deprecated.UseComparator.nullsFirst(Comparator.naturalOrder()), which this returns. PlainComparator.naturalOrder()is not a replacement: it throwsNullPointerExceptionwhen it comparesnull.AComparatorfor objects that implementComparable(checked dynamically at run-time).nullis less than everything else. This version is parameterized to play nicely with Java's type system.- Since:
- 1.2
-
nullIterator
Deprecated.UseCollections.emptyIterator(). Unlike this iterator, theremove()method ofCollections.emptyIterator()throwsIllegalStateException, notUnsupportedOperationException.AnIteratorover the empty set, parameterized to play nicely with Java's type system. -
singletonIterator
AnIteratorover a singleton set. -
unmodifiableIterator
An unmodifiable version of the given iterator: itsremove()method throwsUnsupportedOperationException. -
EMPTY_SET
Deprecated.An empty set; the parameterized version. Plays nicely with Java's type system. -
EMPTY_LIST
Deprecated.UseCollections.emptyList(), which this returns.An empty list. The parameterized version. Made necessary by limitations in GJ's type system. -
EMPTY_MAP
Deprecated.An empty map, parameterized to play nicely with Java's type system.- Since:
- 1.2
-
EMPTY_MULTIMAP
An empty multi-map, parameterized to play nicely with Java's type system.- Since:
- 1.2
-
unmodifiableCollection
ImprovedunmodifiableCollection()class that helps w/ covariant subtyping. -
pair
Deprecated.UsePair, an immutable record:new Pair<>(left, right). For an immutable list, useList.of(Object,Object), which does not permitnulls.A pair constructor method. Pairs implementhashCode()andequals()"properly" so they can be used as keys in hashtables and etc. They are implemented as mutable lists of fixed size 2. -
entry
Deprecated.UseAbstractMap.SimpleImmutableEntry, which this method now returns, orMap.entry(Object,Object), which does not permitnulls.A pair constructor method more appropriate forSetviews ofMaps andMultiMaps. The returned object is an instance ofMap.Entry; the only (real) difference from the pairs returned byDefault.pair()is the definition ofhashCode(), which corresponds toMap.Entry(beingkey.hashCode() ^ value.hashCode()) rather thanList(which would be31*(31+key.hashCode())+value.hashCode()). This is an annoying distinction; I wish the JDK API authors had made these consistent. TheMap.Entryreturned is immutable.
-
Pair, an immutable record whosePair.left()andPair.right()replace the methods of the same name.