net.sourceforge.cilib.type.types.container
Class AbstractList<E extends Type>

java.lang.Object
  extended by net.sourceforge.cilib.type.types.container.AbstractList<E>
Type Parameters:
E - The type element.
All Implemented Interfaces:
Serializable, Iterable<E>, StructuredType<E>, Randomizable, Type, Cloneable
Direct Known Subclasses:
TypeList, Vector

public abstract class AbstractList<E extends Type>
extends Object
implements StructuredType<E>

The basic definition for all Type objects that are based on a list.

Author:
Gary Pampara
See Also:
Serialized Form

Constructor Summary
AbstractList()
           
 
Method Summary
abstract  boolean append(AbstractList<E> list)
          Add the provided AbstractList to the end of the current list.
static
<T extends Type>
AbstractList<T>
append(AbstractList<T> lhs, AbstractList<T> rhs)
          Create a new (cloned) Vector consisting of rhs that has been appended to lhs.
 void append(E value)
          Add the provided Type to the end of the current list.
abstract  boolean equals(Object o)
          Compare the specified object with this type for equality.
abstract  E get(int index)
          Get the Type at the given index.
abstract  AbstractList<E> getClone()
          Create a cloned copy of the current object and return it.
 String getRepresentation()
          Get the representation of this Vector object in the form expressed by the domain notation.
abstract  int hashCode()
          Returns the hash code value for this list.
abstract  void insert(int index, E value)
          Insert the provided Type at the specified index.
abstract  boolean prepend(AbstractList<E> list)
          Add the provided AbstractList to the start of the current list.
static AbstractList prepend(AbstractList lhs, AbstractList rhs)
          Create a new (cloned) Vector consisting of rhs that has been prepended to lhs.
 void prepend(E value)
          Prepend the provided Type to the from of this list.
abstract  void set(int index, E value)
          Set the Type at the index index.
abstract  AbstractList<E> subList(int fromIndex, int toIndex)
          Create a sub vector from the current Vector.
abstract  Object[] toArray()
          Create an Object [] from this Vector.
 String toString()
          
 String toString(char delimiter)
          Get the String representation, using the provided delimiter.
 String toString(char first, char last, char delimiter)
          Generate a String representation of this Vector using the provided first, last and delimiter characters.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.cilib.type.types.container.StructuredType
accept, add, addAll, clear, contains, isEmpty, iterator, remove, remove, removeAll, size
 
Methods inherited from interface net.sourceforge.cilib.type.types.Randomizable
randomize
 

Constructor Detail

AbstractList

public AbstractList()
Method Detail

getClone

public abstract AbstractList<E> getClone()
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface StructuredType<E extends Type>
Specified by:
getClone in interface Type
Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

equals

public abstract boolean equals(Object o)
Compare the specified object with this type for equality. Returns true if and only if the specified object is also an instance of the same type.

Specified by:
equals in interface Type
Overrides:
equals in class Object
Parameters:
o - The object to compare.
Returns:
true if equality exists, false otherwise.
See Also:
Object.equals(Object)

hashCode

public abstract int hashCode()
Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:
  int hashCode = 7;
  Iterator<E> i = list.iterator();
  while (i.hasNext()) {
      E obj = i.next();
      hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
  }
 
This ensures that type1.equals(type2) implies that type1.hashCode()==type2.hashCode() for any two types, type1 and type2, as required by the general contract of Object.hashCode().

Specified by:
hashCode in interface Type
Overrides:
hashCode in class Object
Returns:
the hash code value for this list
See Also:
Object.equals(Object), Type.equals(Object)

get

public abstract E get(int index)
Get the Type at the given index.

Parameters:
index - The index to inspect to return.
Returns:
The Type found at index.

set

public abstract void set(int index,
                         E value)
Set the Type at the index index.

Parameters:
index - The index to set.
value - The value to set.

insert

public abstract void insert(int index,
                            E value)
Insert the provided Type at the specified index.

Parameters:
index - The index where to insert the Type.
value - The value to set.

append

public void append(E value)
Add the provided Type to the end of the current list.

Parameters:
value - The Type to add.

append

public abstract boolean append(AbstractList<E> list)
Add the provided AbstractList to the end of the current list.

Parameters:
list - The object to add.
Returns:
true if the operation was successful, false otherwise.

prepend

public void prepend(E value)
Prepend the provided Type to the from of this list.

Parameters:
value - The Type to prepend.

prepend

public abstract boolean prepend(AbstractList<E> list)
Add the provided AbstractList to the start of the current list.

Parameters:
list - The object to add.
Returns:
true if the operation was successful, false otherwise.

toArray

public abstract Object[] toArray()
Create an Object [] from this Vector.

Returns:
an Object [] representing the Vector

getRepresentation

public String getRepresentation()
Get the representation of this Vector object in the form expressed by the domain notation. This method calls the getRepresentation method for each element in the Vector. This method is also a bit clever in the sense that it will try to detect elements with the same representation that follow on each other, i.e. to return a representation as
R(-1.0, 1.0)^3
instead of
R(-1.0, 1.0),R(-1.0, 1.0),R(-1.0, 1.0) NOTE: This method WILL give unexpected behaviour when an element is a Vector.

Returns:
A String representing the Type in domain notation.

subList

public abstract AbstractList<E> subList(int fromIndex,
                                        int toIndex)
Create a sub vector from the current Vector.

Parameters:
fromIndex - The index to start the sub-list from.
toIndex - The last index to end the sub-list at.
Returns:
The created sub-list instance.

append

public static <T extends Type> AbstractList<T> append(AbstractList<T> lhs,
                                                      AbstractList<T> rhs)
Create a new (cloned) Vector consisting of rhs that has been appended to lhs.

Type Parameters:
T - The type element.
Parameters:
lhs - The Vector that will form the front part of the new (cloned) Vector.
rhs - The Vector that will form the back part of the new (cloned) Vector.
Returns:
A new Vector consisting of the concatenation of lhs and rhs.

prepend

public static AbstractList prepend(AbstractList lhs,
                                   AbstractList rhs)
Create a new (cloned) Vector consisting of rhs that has been prepended to lhs.

Parameters:
lhs - The Vector that will form the back part of the new (cloned) Vector.
rhs - The Vector that will form the front part of the new (cloned) Vector.
Returns:
A new Vector consisting of the concatenation of rhs and lhs.

toString

public String toString(char first,
                       char last,
                       char delimiter)
Generate a String representation of this Vector using the provided first, last and delimiter characters.

Example Input: Assume first = '[', last = ']', delimiter = ',' and elements of the Vector = {1,2,3,4,5}
Example Output: [1,2,3,4,5]

In the case where first and last characters are not desired, call the function as follows:
toString((char)0, (char)0, ','); The delimiter character may be any character including a tab '\t' or a newline '\n'.

Parameters:
first - The character that indicates the start of the Vector String
last - The character that indicates the end of the Vector String
delimiter - The character used to delimit the elements of the Vector
Returns:
a String representing this Vector

toString

public String toString()

Overrides:
toString in class Object

toString

public String toString(char delimiter)
Get the String representation, using the provided delimiter. Also see

Parameters:
delimiter - The delimiter to use.
Returns:
The String representation, using the provided delimiter.
See Also:
Object.toString()


Copyright © 2009 CIRG. All Rights Reserved.