Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.openide.util 6.8.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.openide.util
Class Enumerations

    java.lang.Object
      org.openide.util.Enumerations

    public final class Enumerations

extends Object

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.

Since:
  4.37

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

### empty

    public static final Enumeration empty()

  An empty enumeration. Always returns `false` from `empty().hasMoreElements()` and throws `NoSuchElementException` from `empty().nextElement()`.

  Returns:
    the enumeration

### singleton

    public static Enumeration singleton(Object obj)

  Creates an enumeration with one element.

  Parameters:
    `obj` - the element to be present in the enumeration.
  Returns:
    enumeration

### concat

    public static Enumeration concat(Enumeration en1,
                                     Enumeration en2)

  Concatenates the content of two enumerations into one. Until the end of `en1` is reached its elements are being served. As soon as the `en1` has no more elements, the content of `en2` is being returned.

  Parameters:
    `en1` - first enumeration
    `en2` - second enumeration
  Returns:
    enumeration

### concat

    public static Enumeration concat(Enumeration enumOfEnums)

  Concatenates the content of many enumerations. The input value is enumeration of Enumeration elements and the result is composed all their content. Each of the provided enumeration is fully read and their content returned before the next enumeration is asked for their elements.

  Parameters:
    `enumOfEnums` - Enumeration of Enumeration elements
  Returns:
    enumeration

### removeDuplicates

    public static Enumeration removeDuplicates(Enumeration en)

  Filters the input enumeration to new one that should contain each of the provided elements just once. The elements are compared using their default `equals` and `hashCode` methods.

  Parameters:
    `en` - enumeration to filter
  Returns:
    enumeration without duplicated items

### array

    public static Enumeration array(Object[] arr)

  Returns an enumeration that iterates over provided array.

  Parameters:
    `arr` - the array of object
  Returns:
    enumeration of those objects

### removeNulls

    public static Enumeration removeNulls(Enumeration en)

  Removes all `null`s from the input enumeration.

  Parameters:
    `en` - enumeration that can contain nulls
  Returns:
    new enumeration without null values

### convert

    public static Enumeration convert(Enumeration en,
                                      Enumerations.Processor processor)

  For each element of the input enumeration `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);

  Parameters:
    `en` - enumeration of any objects
    `processor` - a callback processor for the elements (its toAdd arguments is always null)
  Returns:
    new enumeration where all elements has been processed

### filter

    public static Enumeration filter(Enumeration en,
                                     Enumerations.Processor filter)

  Filters some elements out from the input enumeration. Just make the `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);

  Parameters:
    `en` - enumeration of any objects
    `filter` - a callback processor for the elements (its toAdd arguments is always null)
  Returns:
    new enumeration which does not include non-processed (returned null from processor) elements

### queue

    public static Enumeration queue(Enumeration en,
                                    Enumerations.Processor filter)

  Support for breadth-first enumerating. Before any element is returned for the resulting enumeration it is processed in the `Enumerations.Processor` and the processor is allowed to modify it and also add additional elements at the (current) end of the queue by 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);

  Parameters:
    `en` - initial content of the resulting enumeration
    `filter` - 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
  Returns:
    enumeration with the initial and queued content (it can contain `null` if the filter returned `null` from its `Enumerations.Processor.process(java.lang.Object, java.util.Collection)` method.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.openide.util 6.8.22
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Built on December 7 2006. | Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.