Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.util
Class FastSet<E>

    java.lang.Object
      javolution.util.FastCollection<E>
          javolution.util.FastSet<E>

All Implemented Interfaces:
  java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, Realtime, Reusable, XMLSerializable

    public class FastSet<E>

extends FastCollection<E>
implements java.util.Set<E>, Reusable

This class represents a set collection backed by a `FastMap`; smooth capacity increase and no rehashing ever performed.

`FastSet`, as for any `FastCollection` sub-class, supports thread-safe fast iterations without using iterators. For example:``

         for (FastSet.Record r = set.head(), end = set.tail(); (r = r.getNext()) != end;) {
             Object value = set.valueOf(r);
         }

Version:
  4.2, December 18, 2006
Author:
  Jean-Marie Dautelle
See Also:
  Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class javolution.util.FastCollection
`FastCollection.Record`

Constructor Summary
`FastSet()` Creates a set of small initial capacity.
`FastSet(int capacity)` Creates a set of specified initial capacity; unless the set size reaches the specified capacity, operations on this set will not allocate memory (no lazy object creation).
`FastSet(java.util.Set<? extends E> elements)` Creates a set containing the specified elements, in the order they are returned by the set iterator.
`FastSet(java.lang.String id)` Creates a persistent set associated to the specified unique identifier (convenience method).

Method Summary
`boolean` | `add(E value)` Adds the specified value to this set if it is not already present.
`void` | `clear()` Removes all of the values from this collection (optional operation).
`boolean` | `contains(java.lang.Object o)` Indicates if this collection contains the specified value.
`void` | `delete(FastCollection.Record record)` Deletes the specified record from this collection.
`FastComparator<? super E>` | `getValueComparator()` Returns the value comparator for this collection (default `FastComparator.DEFAULT`).
`FastCollection.Record` | `head()` Returns the head record of this collection; it is the record such as `head().getNext()` holds the first collection value.
`java.util.Iterator<E>` | `iterator()` Returns an iterator over the elements in this set (allocated on the stack when executed in a `StackContext`).
`static
`<E> FastSet<E>`
` | `newInstance()` Returns a new, preallocated or `recycled` set instance (on the stack when executing in a `StackContext`).
`static void` | `recycle(FastSet instance)` Recycles a set `instance` immediately (on the stack when executing in a `StackContext`).
`boolean` | `remove(java.lang.Object o)` Removes the first occurrence in this collection of the specified value (optional operation).
`void` | `reset()` Resets the internal state of this object to its default values.
`FastSet<E>` | `setValueComparator(FastComparator<? super E> comparator)` Sets the comparator to use for value equality.
`int` | `size()` Returns the number of elements in this set (its cardinality).
`FastCollection.Record` | `tail()` Returns the tail record of this collection; it is the record such as `tail().getPrevious()` holds the last collection value.
`java.util.Set<E>` | `unmodifiable()` Returns the unmodifiable view associated to this collection.
`E` | `valueOf(FastCollection.Record record)` Returns the collection value for the specified record.

Methods inherited from class javolution.util.FastCollection
`addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray, toString, toText`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Set
`addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray`

Constructor Detail

### FastSet

    public FastSet()

  Creates a set of small initial capacity.

### FastSet

    public FastSet(java.lang.String id)

  Creates a persistent set associated to the specified unique identifier (convenience method).

  Parameters:
    `id` - the unique identifier for this map.
  Throws:
    `java.lang.IllegalArgumentException` - if the identifier is not unique.
  See Also:
    `PersistentContext.Reference`

### FastSet

    public FastSet(int capacity)

  Creates a set of specified initial capacity; unless the set size reaches the specified capacity, operations on this set will not allocate memory (no lazy object creation).

  Parameters:
    `capacity` - the initial capacity.

### FastSet

    public FastSet(java.util.Set<? extends E> elements)

  Creates a set containing the specified elements, in the order they are returned by the set iterator.

  Parameters:
    `elements` - the elements to be placed into this fast set.

Method Detail

### newInstance

    public static <E> FastSet<E> newInstance()

  Returns a new, preallocated or `recycled` set instance (on the stack when executing in a `StackContext`).

  Returns:
    a new, preallocated or recycled set instance.

### recycle

    public static void recycle(FastSet instance)

  Recycles a set `instance` immediately (on the stack when executing in a `StackContext`).

### size

    public final int size()

  Returns the number of elements in this set (its cardinality).

  Specified by:
    `size` in interface `java.util.Collection<E>`
  Specified by:
    `size` in interface `java.util.Set<E>`
  Specified by:
    `size` in class `FastCollection<E>`
  Returns:
    the number of elements in this set (its cardinality).

### add

    public final boolean add(E value)

  Adds the specified value to this set if it is not already present.

  Specified by:
    `add` in interface `java.util.Collection<E>`
  Specified by:
    `add` in interface `java.util.Set<E>`
  Overrides:
    `add` in class `FastCollection<E>`
  Parameters:
    `value` - the value to be added to this set.
  Returns:
    `true` if this set did not already contain the specified element.
  Throws:
    `java.lang.NullPointerException` - if the value is `null`.

### iterator

    public java.util.Iterator<E> iterator()

  Returns an iterator over the elements in this set (allocated on the stack when executed in a `StackContext`).

  Specified by:
    `iterator` in interface `java.lang.Iterable<E>`
  Specified by:
    `iterator` in interface `java.util.Collection<E>`
  Specified by:
    `iterator` in interface `java.util.Set<E>`
  Overrides:
    `iterator` in class `FastCollection<E>`
  Returns:
    an iterator over this set values.

### unmodifiable

    public java.util.Set<E> unmodifiable()

  Description copied from class: `FastCollection`
  Returns the unmodifiable view associated to this collection. Attempts to modify the returned collection result in an `UnsupportedOperationException` being thrown. The view is always a `FastCollection` instance.

  Overrides:
    `unmodifiable` in class `FastCollection<E>`
  Returns:
    the unmodifiable view over this collection.

### clear

    public final void clear()

  Description copied from class: `FastCollection`
  Removes all of the values from this collection (optional operation).

  Specified by:
    `clear` in interface `java.util.Collection<E>`
  Specified by:
    `clear` in interface `java.util.Set<E>`
  Overrides:
    `clear` in class `FastCollection<E>`

### contains

    public final boolean contains(java.lang.Object o)

  Description copied from class: `FastCollection`
  Indicates if this collection contains the specified value.

  Specified by:
    `contains` in interface `java.util.Collection<E>`
  Specified by:
    `contains` in interface `java.util.Set<E>`
  Overrides:
    `contains` in class `FastCollection<E>`
  Parameters:
    `o` - the value whose presence in this collection is to be tested.
  Returns:
    `true` if this collection contains the specified value;`false` otherwise.

### remove

    public final boolean remove(java.lang.Object o)

  Description copied from class: `FastCollection`
  Removes the first occurrence in this collection of the specified value (optional operation).

  Specified by:
    `remove` in interface `java.util.Collection<E>`
  Specified by:
    `remove` in interface `java.util.Set<E>`
  Overrides:
    `remove` in class `FastCollection<E>`
  Parameters:
    `o` - the value to be removed from this collection.
  Returns:
    `true` if this collection contained the specified value; `false` otherwise.

### setValueComparator

    public FastSet<E> setValueComparator(FastComparator<? super E> comparator)

  Sets the comparator to use for value equality.

  Parameters:
    `comparator` - the value comparator.
  Returns:
    `this`

### getValueComparator

    public FastComparator<? super E> getValueComparator()

  Description copied from class: `FastCollection`
  Returns the value comparator for this collection (default `FastComparator.DEFAULT`).

  Overrides:
    `getValueComparator` in class `FastCollection<E>`
  Returns:
    the comparator to use for value equality (or ordering if the collection is ordered)

### reset

    public void reset()

  Description copied from interface: `Reusable`
  Resets the internal state of this object to its default values.

  Specified by:
    `reset` in interface `Reusable`

### head

    public final FastCollection.Record head()

  Description copied from class: `FastCollection`
  Returns the head record of this collection; it is the record such as `head().getNext()` holds the first collection value.

  Specified by:
    `head` in class `FastCollection<E>`
  Returns:
    the head record.

### tail

    public final FastCollection.Record tail()

  Description copied from class: `FastCollection`
  Returns the tail record of this collection; it is the record such as `tail().getPrevious()` holds the last collection value.

  Specified by:
    `tail` in class `FastCollection<E>`
  Returns:
    the tail record.

### valueOf

    public final E valueOf(FastCollection.Record record)

  Description copied from class: `FastCollection`
  Returns the collection value for the specified record.

  Specified by:
    `valueOf` in class `FastCollection<E>`
  Parameters:
    `record` - the record whose current value is returned.
  Returns:
    the current value.

### delete

    public final void delete(FastCollection.Record record)

  Description copied from class: `FastCollection`
  Deletes the specified record from this collection.

  Implementation must ensure that removing a record from the collection does not affect in any way the records preceding the record being removed (it might affect the next records though, e.g. in a list collection, the indices of the subsequent records will change).

  Specified by:
    `delete` in class `FastCollection<E>`
  Parameters:
    `record` - the record to be removed.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2009 Javolution.