|
org.openide.util 6.8.22 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openide.util.Enumerations
public final class Enumerations
Factory methods for various types of Enumeration
.
Allows composition of existing enumerations, filtering their contents, and/or modifying them.
All of this is designed to be done lazily, i.e. elements created on demand.
Nested Class Summary | |
---|---|
static interface |
Enumerations.Processor
Processor interface that can filter out objects from the enumeration, change them or add aditional objects to the end of the current enumeration. |
Method Summary | |
---|---|
static Enumeration |
array(Object[] arr)
Returns an enumeration that iterates over provided array. |
static Enumeration |
concat(Enumeration enumOfEnums)
Concatenates the content of many enumerations. |
static Enumeration |
concat(Enumeration en1,
Enumeration en2)
Concatenates the content of two enumerations into one. |
static Enumeration |
convert(Enumeration en,
Enumerations.Processor processor)
For each element of the input enumeration en asks the
Enumerations.Processor to provide a replacement. |
static Enumeration |
empty()
An empty enumeration. |
static Enumeration |
filter(Enumeration en,
Enumerations.Processor filter)
Filters some elements out from the input enumeration. |
static Enumeration |
queue(Enumeration en,
Enumerations.Processor filter)
Support for breadth-first enumerating. |
static Enumeration |
removeDuplicates(Enumeration en)
Filters the input enumeration to new one that should contain each of the provided elements just once. |
static Enumeration |
removeNulls(Enumeration en)
Removes all null s from the input enumeration. |
static Enumeration |
singleton(Object obj)
Creates an enumeration with one element. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final Enumeration empty()
false
from
empty().hasMoreElements()
and throws NoSuchElementException
from empty().nextElement()
.
public static Enumeration singleton(Object obj)
obj
- the element to be present in the enumeration.
public static Enumeration concat(Enumeration en1, Enumeration en2)
en1
is reached its elements are being served.
As soon as the en1
has no more elements, the content
of en2
is being returned.
en1
- first enumerationen2
- second enumeration
public static Enumeration concat(Enumeration enumOfEnums)
enumOfEnums
- Enumeration of Enumeration elements
public static Enumeration removeDuplicates(Enumeration en)
equals
and hashCode
methods.
en
- enumeration to filter
public static Enumeration array(Object[] arr)
arr
- the array of object
public static Enumeration removeNulls(Enumeration en)
null
s from the input enumeration.
en
- enumeration that can contain nulls
public static Enumeration convert(Enumeration en, Enumerations.Processor processor)
en
asks the
Enumerations.Processor
to provide a replacement.
The toAdd
argument of the processor is always null.
Example to convert any objects into strings:
Processor convertToString = new Processor() { public Object process(Object obj, Collection alwaysNull) { return obj.toString(); // converts to string } }; Enumeration strings = Enumerations.convert(elems, convertToString);
en
- enumeration of any objectsprocessor
- a callback processor for the elements (its toAdd arguments is always null)
public static Enumeration filter(Enumeration en, Enumerations.Processor filter)
Enumerations.Processor
return null
. Please notice the toAdd
argument of the processor is always null
.
Example to remove all objects that are not strings:
Processor onlyString = new Processor() { public Object process(Object obj, Collection alwaysNull) { if (obj instanceof String) { return obj; } else { return null; } } }; Enumeration strings = Enumerations.filter(elems, onlyString);
en
- enumeration of any objectsfilter
- a callback processor for the elements (its toAdd arguments is always null)
public static Enumeration queue(Enumeration en, Enumerations.Processor filter)
Enumerations.Processor
and
the processor is allowed to modify it and also add additional elements
at the (current) end of the queueby calling
toAdd.add
or toAdd.addAll
. No other methods can be called on the
provided toAdd
collection.
Example of doing breadth-first walk through a tree:
Processor queueSubnodes = new Processor() { public Object process(Object obj, Collection toAdd) { Node n = (Node)obj; toAdd.addAll (n.getChildrenList()); return n; } }; Enumeration strings = Enumerations.queue(elems, queueSubnodes);
en
- initial content of the resulting enumerationfilter
- the processor that is called for each element and can
add and addAll elements to its toAdd Collection argument and
also change the value to be returned
null
if the filter returned null
from its
Enumerations.Processor.process(java.lang.Object, java.util.Collection)
method.
|
org.openide.util 6.8.22 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |