JUtil

net.cscott.jutil
Class Default

java.lang.Object
  extended by net.cscott.jutil.Default

public abstract class Default
extends Object

Default contains one-off or 'standard, no-frills' implementations of simple Iterators, Collections, and Comparators.

Version:
$Id: Default.java,v 1.8 2006-10-30 19:58:05 cananian Exp $
Author:
C. Scott Ananian

Nested Class Summary
static class Default.PairList<A,B>
          Pairs, implemented as a List.
 
Field Summary
static Comparator comparator
          A Comparator for objects that implement Comparable (checked dynamically at run-time).
static SortedMap EMPTY_MAP
          Deprecated. Use Collections.EMPTY_MAP
static MultiMap EMPTY_MULTIMAP
          An empty multi-map.
static SortedSet EMPTY_SET
          Deprecated. Use Collections.EMPTY_SET
static Iterator nullIterator
          An Iterator over the empty set.
 
Constructor Summary
Default()
           
 
Method Summary
static
<T extends Comparable<T>>
Comparator<T>
comparator()
          A Comparator for objects that implement Comparable (checked dynamically at run-time).
static
<E> List<E>
EMPTY_LIST()
          Deprecated. Use Collections.emptyList()
static
<K,V> SortedMap<K,V>
EMPTY_MAP()
          Deprecated. Use Collections.emptyMap()
static
<K,V> MultiMap<K,V>
EMPTY_MULTIMAP()
          An empty multi-map, parameterized to play nicely with Java's type system.
static
<E> SortedSet<E>
EMPTY_SET()
          Deprecated. Use Collections.emptySet()
static
<K,V> Map.Entry<K,V>
entry(K key, V value)
          A pair constructor method more appropriate for Set views of Maps and MultiMaps.
static
<E> Iterator<E>
nullIterator()
          An Iterator over the empty set, parameterized to play nicely with Java's type system.
static
<A,B> Default.PairList<A,B>
pair(A left, B right)
          A pair constructor method.
static
<E> Iterator<E>
singletonIterator(E o)
          An Iterator over a singleton set.
static
<A> Collection<A>
unmodifiableCollection(Collection<? extends A> cc)
          Improved unmodifiableCollection() class that helps w/ covariant subtyping.
static
<E> Iterator<E>
unmodifiableIterator(Iterator<E> i)
          An unmodifiable version of the given iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comparator

public static final Comparator comparator
A Comparator for objects that implement Comparable (checked dynamically at run-time).


nullIterator

public static final Iterator nullIterator
An Iterator over the empty set.


EMPTY_SET

public static final SortedSet EMPTY_SET
Deprecated. Use Collections.EMPTY_SET
An empty set.


EMPTY_MAP

public static final SortedMap EMPTY_MAP
Deprecated. Use Collections.EMPTY_MAP
An empty map. Missing from Collections in Java 1.2.


EMPTY_MULTIMAP

public static final MultiMap EMPTY_MULTIMAP
An empty multi-map.

Constructor Detail

Default

public Default()
Method Detail

comparator

public static final <T extends Comparable<T>> Comparator<T> comparator()
A Comparator for objects that implement Comparable (checked dynamically at run-time). This version is parameterized to play nicely with Java's type system.


nullIterator

public static final <E> Iterator<E> nullIterator()
An Iterator over the empty set, parameterized to play nicely with Java's type system.


singletonIterator

public static final <E> Iterator<E> singletonIterator(E o)
An Iterator over a singleton set.


unmodifiableIterator

public static final <E> Iterator<E> unmodifiableIterator(Iterator<E> i)
An unmodifiable version of the given iterator.


EMPTY_SET

public static final <E> SortedSet<E> EMPTY_SET()
Deprecated. Use Collections.emptySet()

An empty set; the parameterized version. Plays nicely with Java's type system.


EMPTY_LIST

public static final <E> List<E> EMPTY_LIST()
Deprecated. Use Collections.emptyList()

An empty list. The parameterized version. Made necessary by limitations in GJ's type system.


EMPTY_MAP

public static final <K,V> SortedMap<K,V> EMPTY_MAP()
Deprecated. Use Collections.emptyMap()

An empty map, parameterized to play nicely with Java's type system.


EMPTY_MULTIMAP

public static final <K,V> MultiMap<K,V> EMPTY_MULTIMAP()
An empty multi-map, parameterized to play nicely with Java's type system.


unmodifiableCollection

public static <A> Collection<A> unmodifiableCollection(Collection<? extends A> cc)
Improved unmodifiableCollection() class that helps w/ covariant subtyping.


pair

public static <A,B> Default.PairList<A,B> pair(A left,
                                               B right)
A pair constructor method. Pairs implement hashCode() and equals() "properly" so they can be used as keys in hashtables and etc. They are implemented as mutable lists of fixed size 2.


entry

public static <K,V> Map.Entry<K,V> entry(K key,
                                         V value)
A pair constructor method more appropriate for Set views of Maps and MultiMaps. The returned object is an instance of Map.Entry; the only (real) difference from the pairs returned by Default.pair() is the definition of hashCode(), which corresponds to Map.Entry (being key.hashCode() ^ value.hashCode() ) rather than Default.PairList (which would be 31*(31+key.hashCode())+value.hashCode() ). This is an annoying distinction; I wish the JDK API authors had made these consistent. The Map.Entry returned is immutable.


JUtil

Copyright (c) 2006 C. Scott Ananian