Hyperic HQ Plugin API v. 4.4.0.2

org.hyperic.util
Class StrongList

java.lang.Object
  extended by org.hyperic.util.StrongCollection
      extended by org.hyperic.util.StrongList
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, java.util.List
Direct Known Subclasses:
StringList

public class StrongList
extends StrongCollection
implements java.util.List

StrongList is a collection class, ArrayList that will only accept objects into the collection of a type specified when constructing the collection. StrongCollection's are subclassed to to create a type specific collection (e.g., FooCollection extends StrongCollection). In this example, FooCollection would only accept objects of type Foo. StrongCollection enforces the Collection checks at runtime. Subclassing the StrongCollection class and providing stub implementions of methods like add(Foo element) adds compile time checks. StrongList supports all of the methods of the java.util.List interface. StrongList also returns a ListIterator from the StrongList.listIterator() method call. The ListIterator.add() and ListIterator.remove() call also enforce that only objects allowed by the StrongList will be allowed into the collection.

See Also:
List

Nested Class Summary
protected  class StrongList.ListItr
           
 
Nested classes/interfaces inherited from class org.hyperic.util.StrongCollection
StrongCollection.Itr
 
Field Summary
 
Fields inherited from class org.hyperic.util.StrongCollection
CLASS_NOT_FOUND_MSG, m_aList
 
Constructor Summary
protected StrongList()
          Constructs a StrongCollection class.
  StrongList(java.lang.Class object)
          Constructs a StrongList class.
  StrongList(java.lang.Class collection, java.lang.Class object)
          Constructs a StrongList class.
  StrongList(java.lang.String object)
          Constructs a StrongList class.
protected StrongList(java.lang.String coll, java.lang.String obj)
          Constructs a StrongList class.
 
Method Summary
 void add(int index, java.lang.Object element)
          Inserts the specified element into specified position in the collection.
 boolean addAll(int index, java.util.Collection c)
          Inserts the elements of the specified collection to this collection.
protected  void checkCollection(java.util.Collection collection)
          Checks whether a Collection object is of the type specified when constructing the StrongBase class and throws a ClassCastException if it is not.
protected  void checkObject(java.lang.Object obj)
          Checks whether a object is of the type that the collection accepts and throws a ClassCastException if it is not.
 java.lang.Object get(int index)
          Retries the element at the specified index from the collection.
protected  java.lang.Class getCollectionClass()
          Returns the collection Class.
protected  java.lang.Class getObjectClass()
          Returns the object Class of the objects accepted by a Collection.
 int indexOf(java.lang.Object element)
          Searches for the first occurrence of the specified element in the collection.
protected  void init(java.lang.Class coll, java.lang.Class obj)
          Initializes a StrongBase class.
protected  void init(java.lang.String coll, java.lang.String obj)
          Initializes a StrongBase class.
protected  boolean isValidCollection(java.util.Collection collection)
          Returns whether a Collection object is of the type specified when constructing the StrongBase class.
protected  boolean isValidObject(java.lang.Object obj)
          Returns whether an object is of the type that the collection accepts.
 int lastIndexOf(java.lang.Object element)
          Searches for the last occurrence of the specified element in the collection.
 java.util.ListIterator listIterator()
          Returns a ListIterator of the elements in the collection.
 java.util.ListIterator listIterator(int index)
          Returns a ListIterator of the elements in the collection starting at the specified index.
 java.lang.Object remove(int index)
          Removes the specified element from the collection.
 java.lang.Object set(int index, java.lang.Object element)
          Replaces the element at the specified position in the collection.
 java.util.List subList(int fromIndex, int toIndex)
          Returns a view of a portion of the collection.
 
Methods inherited from class org.hyperic.util.StrongCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, reverse, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

StrongList

protected StrongList()
Constructs a StrongCollection class. This constructor is provided so that subclasses can use the init() method, which makes it easier to catch exceptions in their constructors. If this constructor is called the next method call must be to init().


StrongList

public StrongList(java.lang.Class collection,
                  java.lang.Class object)
Constructs a StrongList class.

Parameters:
collection - The java.lang.Class type of the subclassed collection.
object - The java.lang.Class type of the object this collection will accept.

StrongList

protected StrongList(java.lang.String coll,
                     java.lang.String obj)
              throws java.lang.ClassNotFoundException
Constructs a StrongList class. This constructor is used by subclasses that are strongly typed at compile time and runtime. Because this constructor is protected a subclass should provide the public constructor and subclass the methods in this class that accept types.

Parameters:
collection - The java.lang.String type that specifies the fully qualified class name of the subclassed collection.
object - The java.lang.String type that specifies the fully qualified class name of the class this collection will accept.
Throws:
java.lang.ClassNotFoundException

StrongList

public StrongList(java.lang.Class object)
Constructs a StrongList class. This constructor allows you to use a strongly typed list that is only type checked at runtime.

Parameters:
object - The java.lang.Class type of the object this collection will accept.

StrongList

public StrongList(java.lang.String object)
Constructs a StrongList class. This constructor allows you to use a strongly typed list that is only type checked at runtime.

Parameters:
object - The java.lang.Class type of the object this collection will accept.
Method Detail

add

public void add(int index,
                java.lang.Object element)
Inserts the specified element into specified position in the collection.

Specified by:
add in interface java.util.List
Parameters:
index - The zero-based index where the element should be inserted.
element - The object to add to the list.
Throws:
java.lang.ClassCastException - If the element is not of the type accepted by the collection.

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Inserts the elements of the specified collection to this collection.

Specified by:
addAll in interface java.util.List
Parameters:
c - The collection to insert into this collection.
Returns:
true if the objects was successfully added to the collection.
Throws:
java.lang.ClassCastException - If the specified collection is not the same type as this collection.

get

public java.lang.Object get(int index)
Retries the element at the specified index from the collection.

Specified by:
get in interface java.util.List
Parameters:
index - The zero-based index where the element should be retrieved from.
Returns:
The element at the specified index in the collection

indexOf

public int indexOf(java.lang.Object element)
Searches for the first occurrence of the specified element in the collection.

Specified by:
indexOf in interface java.util.List
Parameters:
element - The element to search for.
Returns:
The zero-based index of the specified element or -1 if the element cannot be found.
Throws:
java.lang.ClassCastException - If the element is not of the type accepted by the collection.

lastIndexOf

public int lastIndexOf(java.lang.Object element)
Searches for the last occurrence of the specified element in the collection.

Specified by:
lastIndexOf in interface java.util.List
Parameters:
element - The element to search for.
Returns:
The zero-based index of the specified element or -1 if the element cannot be found.
Throws:
java.lang.ClassCastException - If the element is not of the type accepted by the collection.

listIterator

public java.util.ListIterator listIterator()
Returns a ListIterator of the elements in the collection.

Specified by:
listIterator in interface java.util.List
Returns:
A java.util.ListIterator object.

listIterator

public java.util.ListIterator listIterator(int index)
Returns a ListIterator of the elements in the collection starting at the specified index.

Specified by:
listIterator in interface java.util.List
Returns:
A java.util.ListIterator object.

remove

public java.lang.Object remove(int index)
Removes the specified element from the collection.

Specified by:
remove in interface java.util.List
Parameters:
index - The zero-based index of the element to remove from the collection.
Returns:
The element previously at the specified position.

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Replaces the element at the specified position in the collection.

Specified by:
set in interface java.util.List
Parameters:
index - The zero-based index where the element should be replaced.
element - The object to store at the specified index in the collection.
Throws:
java.lang.ClassCastException - If the element is not of the type accepted by the collection.

subList

public java.util.List subList(int fromIndex,
                              int toIndex)
Returns a view of a portion of the collection. The SubList and collection are linked. Changes in one are reflected in the other.

Specified by:
subList in interface java.util.List
Parameters:
fromIndex - The zero-based index where the SubList should start from.
toIndex - The zero-based index where the SubList should go to.

init

protected void init(java.lang.Class coll,
                    java.lang.Class obj)
Initializes a StrongBase class.

Parameters:
c - The java.lang.Class object of the collection class that will use the StrongBase. The collection class must implement the java.util.Collection interface or a sublcass of this interface.
obj - The java.lang.Class object of the class that the collection will contain. The obj Class can be any type that can be implemented in the Java language.
See Also:
Collection

init

protected void init(java.lang.String coll,
                    java.lang.String obj)
             throws java.lang.ClassNotFoundException
Initializes a StrongBase class.

Parameters:
c - The java.lang.Class object of the collection class that will use the StrongBase. The collection class must implement the java.util.Collection interface or a sublcass of this interface.
obj - The java.lang.Class object of the class that the collection will contain. The obj Class can be any type that can be implemented in the Java language.
Throws:
java.lang.ClassNotFoundException
See Also:
Collection

checkCollection

protected void checkCollection(java.util.Collection collection)
Checks whether a Collection object is of the type specified when constructing the StrongBase class and throws a ClassCastException if it is not.

Parameters:
collection - The java.lang.Class object of the collection class that will use the StrongBase. This methods throws a ClassCastException if the paramater is not valid.
See Also:
ClassCastException, Collection

checkObject

protected void checkObject(java.lang.Object obj)
Checks whether a object is of the type that the collection accepts and throws a ClassCastException if it is not.

Parameters:
obj - The java.lang.Class object of the collection class that will use the StrongBase. This methods throws a ClassCastException if the paramater is not valid.
See Also:
ClassCastException

getCollectionClass

protected java.lang.Class getCollectionClass()
Returns the collection Class.

Returns:
The java.lang.Class object of the Collection class.
See Also:
Class

getObjectClass

protected java.lang.Class getObjectClass()
Returns the object Class of the objects accepted by a Collection.

Returns:
The java.lang.Class object of the objects allowed in the collection.
See Also:
Class

isValidCollection

protected boolean isValidCollection(java.util.Collection collection)
Returns whether a Collection object is of the type specified when constructing the StrongBase class.

Parameters:
collection - The java.lang.Class object of the collection class that will use the StrongBase. This methods throws a ClassCastException if the paramater is not valid.
Returns:
true if the collection class is valid. false otherwise.
See Also:
Collection

isValidObject

protected boolean isValidObject(java.lang.Object obj)
Returns whether an object is of the type that the collection accepts.

Parameters:
obj - The java.lang.Class object of the collection class that will use the StrongBase.
Returns:
true if the object is allowed in the collection. false otherwise.

Hyperic HQ Plugin API v. 4.4.0.2

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.