tyrex.util
Class ArraySet

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by tyrex.util.ArraySet
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.Set

public class ArraySet
extends java.util.AbstractSet

Implementation of a simple Set based on an array. Does not allow multiple entries, does not support null entries.


Nested Class Summary
protected  class ArraySet.ArraySetIterator
          AbstractSet requires an implementation for the iterator.
 
Field Summary
protected  java.lang.Object[] _table
          The table of all objects in this set.
 
Constructor Summary
ArraySet()
          Construct a new empty set.
ArraySet(java.util.Collection collection)
          Construct a new set from the specified set and linked to a subject.
 
Method Summary
 boolean add(java.lang.Object obj)
           
 boolean addAll(java.util.Collection collection)
          Add the items from the specified collection to the set.
protected  boolean canAdd(java.lang.Object object)
          Return true if the specified argument can be added to the set.
protected  java.lang.Object get(int index)
          Returns the element at the specified index, or null if the index is out of bounds.
 java.util.Iterator iterator()
           
 boolean remove(java.lang.Object obj)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
clear, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
clear, contains, containsAll, isEmpty, retainAll, toArray, toArray
 

Field Detail

_table

protected java.lang.Object[] _table
The table of all objects in this set.

Constructor Detail

ArraySet

public ArraySet()
Construct a new empty set.


ArraySet

public ArraySet(java.util.Collection collection)
Construct a new set from the specified set and linked to a subject. The subject is used to assure the set is not modifiable if the subject is set to read only. The type is optional, if specified the set will only contain elements of the specified type.

Parameters:
subject - the subject
type - the type
set - the set used to populate the created set
Method Detail

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set
Specified by:
iterator in class java.util.AbstractCollection

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection

addAll

public boolean addAll(java.util.Collection collection)
Add the items from the specified collection to the set.

Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set
Overrides:
addAll in class java.util.AbstractCollection
Parameters:
collection - the collection
Returns:
True if items from the specified collection were added to the set.

add

public boolean add(java.lang.Object obj)
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object obj)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection

canAdd

protected boolean canAdd(java.lang.Object object)
Return true if the specified argument can be added to the set.

The default implementation returns true.

Parameters:
object - the object
Returns:
true if the specified argument can be added to the set.

get

protected java.lang.Object get(int index)
Returns the element at the specified index, or null if the index is out of bounds. Used by the iterator.



Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.