org.pf.osf
Class ObjectContainer

java.lang.Object
  extended by org.pf.osf.ObjectContainer
Direct Known Subclasses:
ObjectSearchResult

public class ObjectContainer
extends java.lang.Object

A generic container of objects that keeps it objects in the order they were added. It also provides methods to search for object by match rules.

Version:
1.2
Author:
M.Duchrow

Constructor Summary
ObjectContainer()
          Initialize the new instance with default values.
ObjectContainer(int initialCapacity)
          Initialize the new instance with an initial size.
 
Method Summary
 void add(AttributeReadAccess object)
          Adds the given object to the container
 java.lang.Object[] asArray(java.lang.Class elementType)
          Returns the elements of this container in an array of the specified type
 java.util.List asList()
          Returns all contained objects as List.
 void clear()
          Removes all objects from the container
 boolean contains(AttributeReadAccess object)
          Returns true if the given object is already in this container.
 boolean containsEqualObject(AttributeReadAccess object)
          Returns true if the container contains an object equal to the given object.
 ObjectContainer copy()
          Returns a copy of this object container.
 ObjectSearchResult find(IObjectFilter filter)
          Returns all objects in this container that match the given filter.
 ObjectSearchResult find(MatchRule rule)
          Returns all objects in this container that match the given rule.
 void find(ObjectSearchResult result, IObjectFilter filter)
          Adds all objects in this container that match the given filter to the given result object container.
 void find(ObjectSearchResult result, MatchRule rule)
          Adds all objects in this container that match the given rule to the given result object container.
 void find(ObjectSearchResult result, java.lang.String rule, boolean ignoreCase)
          Adds all objects in this container that match the given rule to the given result object container.
 ObjectSearchResult find(java.lang.String rule)
          Returns all object in this container that match the given rule.
 AttributeReadAccess findFirst(IObjectFilter filter)
          Returns the first object in this container that matches the given filter.
 AttributeReadAccess findFirst(MatchRule rule)
          Returns the first object in this container that matches the given rule.
 AttributeReadAccess findFirst(java.lang.String rule)
          Returns the first object in this container that matches the given rule or null if no matching element can be found.
 AttributeReadAccess findFirstIgnoreCase(java.lang.String rule)
          Returns the first object in this container that matches the given rule or null if no matching element can be found.
 ObjectSearchResult findIgnoreCase(java.lang.String rule)
          Returns all objects in this container that match the given rule.
 AttributeReadAccess get(int index)
          Returns the object at the given index position.
 boolean isEmpty()
          Returns true if the container currently contains nothing.
 boolean remove(AttributeReadAccess object)
          Removes the given object from the container.
 boolean removeEqual(AttributeReadAccess object)
          Removes the given object from the container.
 AttributeReadAccess set(int index, AttributeReadAccess object)
          Puts the given object at the specified index and returns the object previously located at that index.
 int size()
          Returns the number of contained objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectContainer

public ObjectContainer()
Initialize the new instance with default values.


ObjectContainer

public ObjectContainer(int initialCapacity)
Initialize the new instance with an initial size.

Parameters:
initialCapacity - Initial size reserved for elements
Method Detail

add

public void add(AttributeReadAccess object)
Adds the given object to the container


get

public AttributeReadAccess get(int index)
Returns the object at the given index position.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is outside the elements range

set

public AttributeReadAccess set(int index,
                               AttributeReadAccess object)
Puts the given object at the specified index and returns the object previously located at that index.

Parameters:
index - The index of the element to be replaced
object - The object to put into the container
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is outside the current range

clear

public void clear()
Removes all objects from the container


copy

public ObjectContainer copy()
Returns a copy of this object container. The copy contains all (identical) objects that this container.


remove

public boolean remove(AttributeReadAccess object)
Removes the given object from the container. Returns true if the object was in the container, otherwise false. The object is looked up by identity (==) rather than equality (equals()).

Parameters:
object - The object to remove
See Also:
removeEqual(AttributeReadAccess)

removeEqual

public boolean removeEqual(AttributeReadAccess object)
Removes the given object from the container. Returns true if the object was in the container, otherwise false. The object is looked up by equality (equals()) rather than identity (==).

Parameters:
object - The object to remove
See Also:
remove(AttributeReadAccess)

size

public int size()
Returns the number of contained objects.


isEmpty

public boolean isEmpty()
Returns true if the container currently contains nothing.


containsEqualObject

public boolean containsEqualObject(AttributeReadAccess object)
Returns true if the container contains an object equal to the given object.


contains

public boolean contains(AttributeReadAccess object)
Returns true if the given object is already in this container. Comparison is done by identity rather than equality!

Parameters:
object - The object to looked for

findFirst

public AttributeReadAccess findFirst(java.lang.String rule)
                              throws MatchRuleParseException
Returns the first object in this container that matches the given rule or null if no matching element can be found. The rule must comply to the MatchRule syntax of org.pf.text.DefaultMatchRuleParser.

Parameters:
rule - A rule based on the attributes the contained objects must match
Throws:
MatchRuleParseException - For any error when parsing the given rule
See Also:
DefaultMatchRuleParser

findFirstIgnoreCase

public AttributeReadAccess findFirstIgnoreCase(java.lang.String rule)
                                        throws MatchRuleParseException
Returns the first object in this container that matches the given rule or null if no matching element can be found. For all attribute and values the charachter case is ignored. The rule must comply to the MatchRule syntax of org.pf.text.DefaultMatchRuleParser.

Parameters:
rule - A rule based on the attributes the contained objects must match
Throws:
MatchRuleParseException - For any error when parsing the given rule
See Also:
DefaultMatchRuleParser

find

public ObjectSearchResult find(java.lang.String rule)
                        throws MatchRuleParseException
Returns all object in this container that match the given rule. The rule must comply to the MatchRule syntax of org.pf.text.DefaultMatchRuleParser.

Parameters:
rule - A rule based on the attributes the contained objects must match
Throws:
MatchRuleParseException - For any error when parsing the given rule
See Also:
DefaultMatchRuleParser

findIgnoreCase

public ObjectSearchResult findIgnoreCase(java.lang.String rule)
                                  throws MatchRuleParseException
Returns all objects in this container that match the given rule. For all attribute and values the charachter case is ignored. The rule must comply to the MatchRule syntax of org.pf.text.DefaultMatchRuleParser.

Parameters:
rule - A rule based on the attributes the contained objects must match
Throws:
MatchRuleParseException - For any error when parsing the given rule
See Also:
DefaultMatchRuleParser

find

public ObjectSearchResult find(MatchRule rule)
Returns all objects in this container that match the given rule.

Parameters:
rule - A rule based on the attributes the contained objects must match

find

public ObjectSearchResult find(IObjectFilter filter)
Returns all objects in this container that match the given filter.

Parameters:
filter - A filter the contained objects must match

find

public void find(ObjectSearchResult result,
                 MatchRule rule)
Adds all objects in this container that match the given rule to the given result object container.

Parameters:
result - The container all found objects must be added to
rule - A rule based on the attributes the contained objects must match

find

public void find(ObjectSearchResult result,
                 IObjectFilter filter)
Adds all objects in this container that match the given filter to the given result object container.

Parameters:
result - The container all found objects must be added to
filter - A filter the contained objects must match

find

public void find(ObjectSearchResult result,
                 java.lang.String rule,
                 boolean ignoreCase)
          throws MatchRuleParseException
Adds all objects in this container that match the given rule to the given result object container.

Parameters:
result - The container all found objects must be added to
rule - A rule based on the attributes the contained objects must match
ignoreCase - defines whether or not the search should be case-insensitive
Throws:
MatchRuleParseException - For any error when parsing the given rule
See Also:
DefaultMatchRuleParser

findFirst

public AttributeReadAccess findFirst(MatchRule rule)
Returns the first object in this container that matches the given rule.

Parameters:
rule - A rule based on the attributes the contained objects must match

findFirst

public AttributeReadAccess findFirst(IObjectFilter filter)
Returns the first object in this container that matches the given filter.

Parameters:
filter - A filter the contained objects must match

asList

public java.util.List asList()
Returns all contained objects as List. The returned list is not backed by this object container.


asArray

public java.lang.Object[] asArray(java.lang.Class elementType)
Returns the elements of this container in an array of the specified type

Parameters:
elementType - The type each element must comply to