|
org.openide.util 7.9.0 1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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.
NbCollections.checkedEnumerationByFilter(java.util.Enumeration, java.lang.Class, boolean)
,
NbCollections.iterable(Enumeration)
Nested Class Summary | |
---|---|
static interface |
Enumerations.Processor<T,R>
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
|
array(T... arr)
Returns an enumeration that iterates over provided array. |
|
static
|
concat(Enumeration<? extends Enumeration<? extends T>> enumOfEnums)
Concatenates the content of many enumerations. |
|
static
|
concat(Enumeration<? extends T> en1,
Enumeration<? extends T> en2)
Concatenates the content of two enumerations into one. |
|
static
|
convert(Enumeration<? extends T> en,
Enumerations.Processor<T,R> processor)
For each element of the input enumeration en asks the
Enumerations.Processor to provide a replacement. |
|
static
|
empty()
An empty enumeration. |
|
static
|
filter(Enumeration<? extends T> en,
Enumerations.Processor<T,R> filter)
Filters some elements out from the input enumeration. |
|
static
|
queue(Enumeration<? extends T> en,
Enumerations.Processor<T,R> filter)
Support for breadth-first enumerating. |
|
static
|
removeDuplicates(Enumeration<T> en)
Filters the input enumeration to new one that should contain each of the provided elements just once. |
|
static
|
removeNulls(Enumeration<T> en)
Removes all null s from the input enumeration. |
|
static
|
singleton(T 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 <T> Enumeration<T> empty()
false
from
empty().hasMoreElements()
and throws NoSuchElementException
from empty().nextElement()
.
public static <T> Enumeration<T> singleton(T obj)
obj
- the element to be present in the enumeration.
public static <T> Enumeration<T> concat(Enumeration<? extends T> en1, Enumeration<? extends T> 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 <T> Enumeration<T> concat(Enumeration<? extends Enumeration<? extends T>> enumOfEnums)
enumOfEnums
- Enumeration of Enumeration elements
public static <T> Enumeration<T> removeDuplicates(Enumeration<T> en)
equals
and hashCode
methods.
en
- enumeration to filter
public static <T> Enumeration<T> array(T... arr)
arr
- the array of object
public static <T> Enumeration<T> removeNulls(Enumeration<T> en)
null
s from the input enumeration.
en
- enumeration that can contain nulls
public static <T,R> Enumeration<R> convert(Enumeration<? extends T> en, Enumerations.Processor<T,R> 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 <T,R> Enumeration<R> filter(Enumeration<? extends T> en, Enumerations.Processor<T,R> 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)
NbCollections.checkedEnumerationByFilter(java.util.Enumeration, java.lang.Class, boolean)
public static <T,R> Enumeration<R> queue(Enumeration<? extends T> en, Enumerations.Processor<T,R> 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(T, java.util.Collection)
method.
|
org.openide.util 7.9.0 1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |