Collections Concepts


It can be difficult to get a handle on the Collections package due to the sheer number of classes and interfaces provided (as shown in Figure 11-1), some of which are new or unfamiliar to many Java developers. Despite this initial overwhelming complexity, these classes can be broken down into several core concepts, each of which is presented in this chapter. The various utility classes are used to help generate the appropriate combinations of various items. For example, a typed, sorted bag can be returned from the appropriate static BagUtils.

Figure 11-1. Collection class overview.


Generating Output

The various examples in this chapter make use of a method echo(). This method is simply a utility method that writes the contents of the collection to System.out.


Bag

A Bag is an unordered collection that may contain duplicate elements. The Bag maintains counts for the duplicate items, managing each count and performing operations against this count. The Commons Bag hierarchy is shown in Figure 11-2.

Figure 11-2. Bag classes.


For example, imagine a Bag containing the objects a, a, b, and c. Calling getCount(Object) passing in the a object would return 2. Calling uniqueSet() would return a, b, and c. This is an important consideration with the Bag interface, as multiple calls to add an object will increment that object count. The remove(Object) method removes the object completely from the Bag, regardless of the current count. To decrement the count, remove(Object, int) is used, with the second parameter indicating the number of items to be removed.

For example, the code:

 org.apache.commons.collections.Bag myBag = new org.apache.commons.collections.bag.HashBag(); myBag.add("Test1", 3); myBag.add("Test2"); echo(myBag); System.out.println(); myBag.remove("Test1"); echo(myBag); 

. . . produces the output:

 Test2 Test1 Test1 Test1 Test2 

Warning:

The Bag interface changes the interpretation of the Collection methods. This change in behavior can be a rude shock if you are not precisely familiar with the changes. Although changed methods are marked in the javadoc as being in violation, the changes are all related to the notion of Bag's count tracking behavior.


Note that some of the following classes are not actually subclasses but are instead intended to serve as wrappers for a Bag to add additional behavior. For example, the TypedBag class allows you to add type checking to a Bag.

Related Classes: AbstractBagDecorator, AbstractMapBag, AbstractSortedBagDecorator, Bag BagUtils, DefaultMapBag, HashBag, PredicatedBag, PredicatedSortedBag, SortedBag, SynchronizedBag, SynchronizedSortedBag, TransformedBag, TransformedSortedBag, TreeBag, TypedBag, TypedSortedBag, UnmodifiableBag, UnmodifiableSortedBag

Bean

The BeanMap class allows you to wrap and present a JavaBean as a java.util.Map. The various properties of the JavaBean are treated as keys, with the property values exposed as Map properties.

For more information on JavaBeans, see BeanUtils.

For example, the code:

 java.awt.Button myButton = new java.awt.Button(); java.util.Map myMap = new org.apache.commons.collections.BeanMap(         myButton); myMap.put("label", "hello"); java.util.Set myKeys = myMap.keySet(); System.out.println("Keys:"); echo(myKeys); System.out.println(); System.out.println("Values:"); echo(myMap.values()); 

. . . produces the output:

 Keys: accessibleContext focusable actionListeners label enabled actionCommand visible background name foreground font Values: java.awt.Button$AccessibleAWTButton@17fa65e true [Ljava.awt.event.ActionListener;@18385e3 hello true hello true null button0 null null 

Related Classes: BeanMap

BidiMap

The BidiMap classes allow for bidirectional use of map. The default Map interface allows you to retrieve a value from a map with the key, but not the other way around (it is necessary to iterate through the keys and values to identify the value from the key, unless there is some other contract in play). The Commons BidiMap hierarchy is shown in Figure 11-3.

Figure 11-3. BidiMap classes.


The code:

 org.apache.commons.collections.BidiMap myBidiMap = new org.apache.commons.collections.bidimap.TreeBidiMap(); myBidiMap.put("Example", "1"); myBidiMap.put("Another", "2"); // Note easy (and fast) access to key from value System.out.println(myBidiMap.getKey("1")); System.out.println(myBidiMap.get("Another")); echo(myBidiMap); System.out.println("Notice the now missing Example key:"); myBidiMap.put("Another", "1"); echo(myBidiMap); 

. . . produces the output:

 Example 2 Another=2 Example=1 Notice the now missing Example key: Another=1 

Warning:

BidiMap enforces a strict 1:1 relationship between the keys and values. If one side of the key/value pair exists when a new key/value pair is added, the existing key/value pair will be removed. For example, if an A/B key/value pair exists, adding either A/C or C/B will cause the A/B value pair to be removed.


Related Classes: AbstractBidiMapDecorator, AbstractDualBidiMap, AbstractOrderedBidiMapDecorator, AbstractSortedBidiMapDecorator, BidiMap, DualHashBidiMap, DualTreeBidiMap, OrderedBidiMap, SortedBidiMap, TreeBidiMap, UnmodifiableBidiMap, UnmodifiableOrderedBidiMap, UnmodifiableSortedBidiMap

Blocking

Used to decorate another Buffer class to make the get() and remove() methods block if the Buffer is empty. Note that this class extends SynchronizedBuffer and is thread-safe.

Related Classes: BlockingBuffer

Bounded

The various Bounded collections are used to indicate that a maximum number of elements are allowed in the collection. An exception is thrown if an attempt is made to add an element to a full collection.

The code:

 java.util.Map myMap = new java.util.HashMap(); myMap.put("One", "1"); myMap.put("Two", "2"); myMap.put("Three", "3"); myMap = org.apache.commons.collections.map.FixedSizeMap         .decorate(myMap); try {     myMap.put("Four", "4"); } catch (Exception e) {     System.out.println(e.getMessage()); } 

... produces the output:

 Cannot put new key/value pair - Map is fixed size 

Related Classes: BoundedCollection, BoundedFifoBuffer, BoundedMap, UnmodifiableBoundedCollection

Buffer

A buffer is used to describe a collection that expects to remove objects in a specific order. Last-in-first-out (LIFO) buffer (ArrayStack), first-in-first-out (FIFO) buffer (UnboundedFifoBuffer), and java.util.Comparator-based (PriorityBuffer) implementations are provided, among others. The Commons Buffer hierarchy is shown in Figure 11-4.

Figure 11-4. Buffer classes.


Related Classes: AbstractBufferDecorator, BlockingBuffer, BoundedFifoBuffer, BoundedFifoBuffer, Buffer, BufferOverflowException, BufferUnderflowException, BufferUtils, CircularFifoBuffer, PredicatedBuffer, PriorityBuffer, SynchronizedBuffer, TransformedBuffer, TypedBuffer, UnboundedFifoBuffer, UnboundedFifoBuffer, UnmodifiableBuffer

Circular

CircularFifoBuffer is a first-in-first-out buffer with a fixed size that replaces the least recently added element if full. It is both a bounded collection and a buffer.

Related Classes: CircularFifoBuffer

Closure

A closure simply provides a simple interface with a single void execute(java.lang.Object input) method. The only failure signal is a thrown exception, implying that a closure method is not expected to fail. A closure is useful in conjunction with a transformer.

See the Functor entry for more information.

For example, the code:

 org.apache.commons.collections.Closure myEchoClosure = new org.apache.commons.collections.Closure() {     public void execute(Object in)     {         System.out.println(in.toString());     } }; org.apache.commons.collections.Closure mySizeClosure = new org.apache.commons.collections.Closure() {     public void execute(Object in)     {         System.out.println(in.toString()                 .length());     } }; java.util.Map myMap = new java.util.HashMap(); myMap = org.apache.commons.collections.map.TransformedMap         .decorate(                 myMap,                 org.apache.commons.collections.functors.ClosureTransformer                         .getInstance(myEchoClosure),                 org.apache.commons.collections.functors.ClosureTransformer                         .getInstance(mySizeClosure)); myMap.put("Hello", "World"); myMap.put("Apple", "Orange"); myMap.put("One", "Example of a String"); 

... generates the output:

 Hello 5 Apple 6 One 19 

You'll notice in this example that the closures are used to echo values when elements are added to the Map. The first closure writes the value of the object to System.out, and the second closure writes the length of the String representation.

Related Classes: ChainedClosure, Closure, ClosureTransformer, ClosureUtils, ExceptionClosure, ForClosure, IfClosure, NOPClosure, SwitchClosure, TransformerClosure, WhileClosure

Collating

A CollatingIterator can be used to sort an Iterator according to a particular Comparator. Even more powerful, a CollatingIterator can seamlessly weave together two or more Iterators as a single Iterator using the comparator provided.

The code:

 java.util.SortedMap myMap = new java.util.TreeMap(); myMap.put("Hello", "World"); myMap.put("Apple", "Orange"); myMap.put("One", "Example of a String"); java.util.SortedSet mySet = new java.util.TreeSet(); mySet.add("Example"); mySet.add("Bingo"); org.apache.commons.collections.iterators.CollatingIterator myIterator = new org.apache.commons.collections.iterators.CollatingIterator(); myIterator.setComparator(java.text.Collator         .getInstance()); myIterator.addIterator(myMap.keySet()         .iterator()); myIterator.addIterator(mySet.iterator()); while (myIterator.hasNext())     System.out.println(myIterator.next()); 

... produces the output:

 Apple Bingo Example Hello One 

Note that the iterators supplied to the CollatingIterator are already sorted. Although CollatingIterator can be used to weave together an arbitrary number of iterators into a single iterator, it will only produce properly sorted results if the supplied iterators are already sorted.

Related Classes: CollatingIterator

Comparator

The built-in JDK comparator functionality is used to provide a relative order for two objects. This order is given an integer value. For example, the order between "A" and "D" might be expressed as 3, and "D" and "A" as -3. The Collections package makes heavy use of the Comparator interface, and it provides a rich set of additional comparators, including comparators for handling null values, reversing a comparator, and chaining comparators (for example, combining the natural comparator with the null comparator).

Related Classes: BooleanComparator, ComparableComparator, ComparatorChain, ComparatorUtils, FixedOrderComparator, NullComparator, ReverseComparator, TransformingComparator

Composite

This allows you to join a set of collections and provide them as a single, unified view. For example, given a map of cats and a map of dogs, you may want to present them as a single map. Changes to objects may be performed directly, but add and remove operations require the use of a custom CompositeCollection.CollectionMutator implementation to determine which collection will actually remove or add the object.

Related Classes: CompositeCollection, CompositeMap, CompositeSet

Cursorable

Typically, changes to the owning collection are not possible from an iterator. The CursorableLinkedList class provides an exception to this rulemodifications to the collection are possible from the iterator. As long as the CursorableLinkedList is operated on from a single thread, you can make modifications from either the owning collection or the iterator as needed.

For example:

 org.apache.commons.collections.list.CursorableLinkedList myList = new org.apache.commons.collections.list.CursorableLinkedList(); myList.add("1 (original)"); myList.add("2 (original)"); myList.add("3 (original)"); myList.add("4 (original)"); myList.add("5 (original)"); myList.add("6 (original)"); java.util.ListIterator myIterator = myList         .listIterator(); while (myIterator.hasNext()) {     System.out.println(myIterator.next());     int nextIndexValue = myIterator             .nextIndex();     if (nextIndexValue < 5)         myList.add((myList.size() + 1)                 + " (added)"); } 

... produces the output:

 1 (original) 2 (original) 3 (original) 4 (original) 5 (original) 6 (original) 7 (added) 8 (added) 9 (added) 10 (added) 

Notice that changes made to the list while processing the iterator actually cause the iterator to update.

Related Classes: CursorableLinkedList

Factory

This is an interface corresponding to the popular design pattern. Default Factory implementations are provided for a variety of scenarios, including no-arg constructor classes, or even a factory for objects with a specific constructor and set of arguments.

Factory implementations are useful in conjunction with Lazy collections.

Related Classes: ConstantFactory, ExceptionFactory, Factory, FactoryTransformer, FactoryUtils, InstantiateFactory, PrototypeFactory

Fast

The various Fast classes are intended for use in multi-threaded environments in which the vast majority of the access is intended to be read-only. After a collection is created and the data is added, calling setFast(true) puts the collection in a high performance mode.

There is no advantage to using a "Fast" implementation on a single thread.

If you have a Map that is expected to have three or fewer elements and performance is a consideration, you may want to consider the Flat3Map implementation.

Related Classes: FastArrayList, FastHashMap, FastTreeMap

Fifo

Describes a first-in-first-out buffer. See Buffer for more information.

Related Classes: BoundedFifoBuffer, BoundedFifoBuffer, CircularFifoBuffer, UnboundedFifoBuffer, UnboundedFifoBuffer

FixedSize

Allows you to decorate a given collection to indicate that the size of the collection is fixedany attempt to add or remove an element is prohibited. An element may be replaced, however (as this would not change the size of the collection).

Related Classes: FixedOrderComparator, FixedSizeList, FixedSizeMap, FixedSizeSortedMap

Flat3

Describes a Map highly optimized for read/write access when less than three elements are present. When more than three elements are present, this class defaults to the HashMap implementation, with a slight penalty for the extra methods.

Related Classes: Flat3Map

Functor

Functors describe a set of interfaces defining a single operation. For example, a closure simply provides an execute method, a predicate provides a function for boolean evaluation, a transformer provides a single method to produce an object given an object, and a factory provides a single method for creating a new object. Closures and predicates are only useful in conjunction with other classes, in particular a transformer. Custom functors are often passed as anonymous inner objects. When combined with the functors provided by the Collections package, complex operations can be wrapped and handled in conjunction with a collection.

See Closure, Predicate, transformer, and Factory for more information.

Hash

All Java objects extend java.lang.Object, which defines a method int hashCode(). This hash code is used by various hash implementations as values for optimizing access. For a more detailed explanation of the meaning and use of a hash-based collection, see http://www.linuxgazette.com/issue57/tindale.html.

Note that the various hash collections rely on a "good" value to be returned by the hashCode() function. The org.apache.commons.lang.builder .HashCodeBuilder, part of the Lang package, can assist in creating hashCode() implementations.

Related Classes: AbstractHashedMap, DualHashBidiMap, FastHashMap, HashBag, HashedMap, MultiHashMap, SequencedHashMap

Identity

Most collections use the Object.equals() method to determine if two objects are equal. The identity classes use the == operation to determine equality instead. The == operation compares the object reference identity of two objects. Two objects created independently with identical data may or may not have the same object reference identity, depending on the situation and compiler. Generally speaking, the == operation is useful for lower-level object comparisons more concerned with the underlying thread, compiler, and class loader, whereas the equals() method is useful for business operations.

Related Classes: IdentityMap, IdentityPredicate, ReferenceIdentityMap

Lazy

The Lazy classes allow you to decorate a collection, defining factories that will be used to automatically create objects when a null value would otherwise be returned. For example, if the tenth element of a lazy list with a size of six was requested, the lazy list would grow the size of the list to ten, create a new object at the tenth slot, and return the new object.

For example, the code:

 org.apache.commons.collections.Factory factory = new org.apache.commons.collections.Factory() {     public Object create()     {         return new java.util.Date();     } }; java.util.Map lazy = org.apache.commons.collections.map.LazyMap         .decorate(new java.util.HashMap(),                 factory); String current = lazy.get("NOW").toString(); String second = lazy.get("SECOND").toString(); System.out.println(lazy.size()); 

... outputs the value 2.

Related Classes: LazyList, LazyMap, LazySortedMap

Linked

A linked list simply provides bidirectional access to a list, allowing for easy retrieval of objects in either order.

Related Classes: AbstractLinkedList, AbstractLinkedMap, CursorableLinkedList, CursorableLinkedList, LinkedMap, NodeCachingLinkedList

List

This is an ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list) and search for elements in the list. A list is the next step up from a simple array. A list is particularly useful in conjunction with a transformer. The Commons List hierarchy is shown in Figure 11-5.

Figure 11-5. List classes.


Related Classes: AbstractLinkedList, AbstractListDecorator, AbstractListIteratorDecorator, AbstractSerializableListDecorator, ArrayListIterator, CursorableLinkedList, CursorableLinkedList, EmptyListIterator, FastArrayList, FilterListIterator, FixedSizeList, LazyList, ListIteratorWrapper, ListOrderedMap ListOrderedSet, ListUtils, NodeCachingLinkedList, ObjectArrayListIterator, PredicatedList ProxyListIterator, ResettableListIterator, SetUniqueList, SingletonListIterator, SynchronizedList, TransformedList, TreeList, TypedList, UnmodifiableList, UnmodifiableListIterator

LRU

Refers to the notion that the fixed size map maintains a notion of the frequency of use, removing the "least recently used" entry when the map is full and a new entry is submitted. Only the put and get operations affect the tracking of itemsiteration and queries to verify the presence of a key or value do not affect the map.

For example, the code:

 java.util.Map myMap = new org.apache.commons.collections.map.LRUMap(3); myMap.put("One", "1"); myMap.put("Two", "2"); myMap.put("Three", "3"); myMap.get("One"); myMap.get("Three"); myMap.put("Four", "4"); echo(myMap.keySet()); 

... produces the results:

 One Three Four 

Related Classes: LRUMap

Map

This is an object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. A sorted map will maintain the keys in order. One of the most popular types of collection, the vast majority of the classes in the Collection package involve maps in one way or another. The Commons Map hierarchy is shown in Figure 11-6.

Figure 11-6. Map classes.


Keep in mind that many of the map classes merely act as decorators for other map instances. For example, the MapUtils.typedSortedMap(java.util .SortedMap map, java.lang.Class keyType, java.lang.Class valueType) method allows you to take an existing HashMap, sort it using a comparator, and apply runtime type-checks to both the keys and values.

Multi

A Multi map is used to track a map of maps. In other words, each element requires two identifying key values.

For example, the code:

 String first = "Will"; String last = "Iverson"; String phone = "(321) 555-1212"; java.util.Map myMap = new java.util.HashMap(); org.apache.commons.collections.keyvalue.MultiKey multiKey = new org.apache.commons.collections.keyvalue.MultiKey(         first, last); myMap.put(multiKey, phone); System.out.println(myMap.get(multiKey)); System.out.println(); echo(myMap); 

. . . produces the result:

 (321) 555-1212 MultiKey[Will, Iverson]=(321) 555-1212 

Related Classes: MultiHashMap, MultiKey, MultiKeyMap, MultiMap

NodeCaching

By default, a List will use Node objects to maintain the items within. The NodeCachingLinkedList implementation attempts to reuse these Nodes to avoid excessive object creation and garbage collection. It is therefore particularly useful as a long-lived object that expects significant addition and removal of objects over time.

Related Classes: NodeCachingLinkedList

ObjectGraph

Creates a single Iterator to walk down a complex graph of objects. This may be an Iterator that in turn contains an arbitrarily deep number of nested Iterators and objects, or a root object with a custom transformer (which returns either objects or Iterators as appropriate).

For example, the code:

 org.apache.commons.collections.Transformer myTransformer = new org.apache.commons.collections.Transformer() {     public Object transform(Object input)     {         if (input instanceof java.util.Collection)         {             return ((java.util.Collection) input)                     .iterator();         } else             return input;     } }; java.util.Set firstSet = new java.util.HashSet(); java.util.Set secondSet = new java.util.HashSet(); java.util.Set thirdSet = new java.util.HashSet(); firstSet.add("Orange"); firstSet.add("Apple"); secondSet.add("Radio"); secondSet.add("Television"); thirdSet.add("Fire"); thirdSet.add("Water"); firstSet.add(secondSet); firstSet.add(thirdSet); org.apache.commons.collections.iterators.ObjectGraphIterator myIterator = new org.apache.commons.collections.iterators.ObjectGraphIterator(         firstSet, myTransformer); while (myIterator.hasNext())     System.out.println(myIterator.next()); 

. . . produces the output:

 Water Fire Apple Radio Television Orange 

Related Classes: ObjectArrayIterator, ObjectArrayListIterator, ObjectGraphIterator

Ordered

An ordered collection allows for both forward and backward iteration over the elements in the collection. This includes quick access to the first, last, next, and previous element.

Related Classes: AbstractOrderedBidiMapDecorator, AbstractOrderedMapDecorator, AbstractOrderedMapIteratorDecorator, DoubleOrderedMap, EmptyOrderedIterator, EmptyOrderedMapIterator, ListOrderedMap, ListOrderedSet, OrderedBidiMap, OrderedIterator, OrderedMap, OrderedMapIterator, UnmodifiableOrderedBidiMap, UnmodifiableOrderedMap, UnmodifiableOrderedMapIterator

Predicate

A simple interface used to perform a testa single method, boolean evaluate (java.lang.Object object). Unlike a closure, it returns true/false. For more information, see Functor.

Related Classes: AllPredicate, AndPredicate, AnyPredicate, EqualPredicate, ExceptionPredicate, FalsePredicate, IdentityPredicate, InstanceofPredicate, NonePredicate, NotNullPredicate, NotPredicate, NullIsExceptionPredicate, NullIsFalsePredicate, NullIsTruePredicate, NullPredicate, OnePredicate, OrPredicate, Predicate, PredicatedBag, PredicatedBuffer, PredicatedCollection, PredicateDecorator, PredicatedList, PredicatedMap, PredicatedSet, PredicatedSortedBag, PredicatedSortedMap, PredicatedSortedSet, PredicateTransformer, PredicateUtils, TransformedPredicate, TransformerPredicate, TruePredicate, UniquePredicate

Reference

The various reference map collections allow you to specify that entries may be removed by the garbage collector. In other words, references from this collection "don't count" when the Java virtual machine is assessing an object as still being in use for purposes of garbage collection.

Related Classes: AbstractReferenceMap, ReferenceIdentityMap, ReferenceMap

Set

This is a collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. A sorted set will maintain the elements in order. The Commons Map hierarchy is shown in Figure 11-7.

Figure 11-7. Set classes.


Related Classes: AbstractSerializableSetDecorator, AbstractSetDecorator, AbstractSortedSetDecorator, CompositeSet, EntrySetMapIterator, ListOrderedSet, MapBackedSet, PredicatedSet, PredicatedSortedSet, SetUniqueList, SetUtils SynchronizedSet, SynchronizedSortedSet, TransformedSet, TransformedSortedSet, TypedSet, TypedSortedSet, UnmodifiableEntrySet, UnmodifiableSet, UnmodifiableSortedSet

Singleton

This is a collection that may contain one and only one element. The element may be changed, but no operation that would result in zero or more than one element is allowed.

Related Classes: SingletonIterator, SingletonListIterator, SingletonMap

StaticBucket

An efficient, thread-safe Map, designed for situations in which the Map is expected to be accessed frequently by multiple threads. If you expect to only access the put, get, remove, and containsKey methods, this class will dramatically reduce thread contentions. Bulk operations, however, are not atomic, meaning that two or more threads operating on the same collection can have indeterminate results.

Related Classes: StaticBucketMap

Synchronized

The various Synchronized collection classes allow you to decorate a collection, providing synchronized implementations of the collection methods, which are then passed along to the underlying collection.

Related Classes: SynchronizedBag, SynchronizedBuffer, SynchronizedCollection, SynchronizedList, SynchronizedPriorityQueue, SynchronizedSet, SynchronizedSortedBag, SynchronizedSortedSet

Transformed/Transformer

The transformed classes allow a transform operation to be performed on objects as they are added to the collection. These classes merely decorate another implementationthey are not intended to serve as standalone implementations.

The java.lang.Object transform(java.lang.Object input) method of the transformer interface is used to perform the operation. Note that the input object is generally expected to be unchanged, and a new output object is generated.

For an example of a transformation, see the previous entries on Closure and ObjectGraph.

Related Classes: ChainedTransformer, CloneTransformer, ClosureTransformer, ConstantTransformer, ExceptionTransformer, FactoryTransformer, InstantiateTransformer, InvokerTransformer, MapTransformer, NOPTransformer, PredicateTransformer, StringValueTransformer, SwitchTransformer, TransformedBag, TransformedBuffer, TransformedCollection, TransformedList, TransformedMap, TransformedPredicate, TransformedSet, TransformedSortedBag, TransformedSortedMap, TransformedSortedSet, Transformer, TransformerClosure, TransformerPredicate, TransformerUtils, TransformingComparator, TransformIterator

Typed

Decorators that allow runtime type checks to be applied to a collection. Note that the addition of generics to Java 5.0 (also known as JDK 1.5) reduces the need for these type wrappers. For more information on generics, see http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html.

For example, the code:

 java.util.Set mySet = new java.util.HashSet(); mySet = org.apache.commons.collections.set.TypedSet         .decorate(mySet, Integer.class); mySet.add(new Integer(5)); mySet.add(new Integer(15)); try {     mySet.add(new Long(100000)); } catch (Exception e) {     System.out.println(e.getMessage()); } echo(mySet); 

. . . produces the result:

 Cannot add Object '100000' - Predicate rejected it 15 5 

Related Classes: TypedBag, TypedBuffer, TypedCollection, TypedList, TypedMap, TypedSet, TypedSortedBag, TypedSortedMap, TypedSortedSet

Unmodifiable

This is a decorator that wraps a collection as unmodifiable. For example, a configuration collection may be initialized at application launch and then shared with a variety of resources over the course of the application's life cycle, with changes to the configuration object disallowed by decorating the collection as unmodifiable.

Related Classes: UnmodifiableBag, UnmodifiableBidiMap, UnmodifiableBoundedCollection, UnmodifiableBuffer, UnmodifiableCollection, UnmodifiableEntrySet, UnmodifiableIterator, UnmodifiableList, UnmodifiableListIterator, UnmodifiableMap, UnmodifiableMapEntry, UnmodifiableMapIterator, UnmodifiableOrderedBidiMap, UnmodifiableOrderedMap, UnmodifiableOrderedMapIterator, UnmodifiableSet, UnmodifiableSortedBag, UnmodifiableSortedBidiMap, UnmodifiableSortedMap, UnmodifiableSortedSet



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net