net.ponder2.objects
Class P2Array

java.lang.Object
  extended by net.ponder2.objects.P2Object
      extended by net.ponder2.objects.P2Array
All Implemented Interfaces:
java.io.Serializable, P2Serializable, ManagedObject, Ponder2Message
Direct Known Subclasses:
CsvHash

public class P2Array
extends P2Object
implements ManagedObject

Holds a collection of Ponder2 objects. An array may be returned from sending a message to an object or or may be created in PonderTalk with the

 #( obj1 obj2 obj3)
 
syntax.

Version:
$Id:$
Author:
Kevin Twidle
See Also:
Serialized Form

Constructor Summary
P2Array()
          creates an empty P2Array
P2Array(int... values)
          creates a P2Array initialised with int values
P2Array(P2Object... values)
          creates a P2Array initialised with values
P2Array(java.lang.String... values)
          creates a P2Array initialised with string values
 
Method Summary
 void add(P2Object aP2Object)
          adds a aP2Object to the receiver.
 void addAll(P2Array anArray)
          adds all objects in anArray to the receiver.
 P2Object[] asArray()
          Returns itself as an array of Ponder2 objects
 P2Hash asHash()
          Returns a Hash comprising of the array contents taken as key, value pairs
 P2Array asP2Array()
          Returns itself as a Ponder2 Array
 P2Object at(int anIndex)
          returns the object at anIndex
 P2Object atput(int anIndex, P2Object aP2Object)
          inserts aP2Object at anIndex posiion in the array.
 java.util.Vector<P2Object> getValues()
          Returns all the values in the array as a Vector
 boolean has(int anIndex)
          returns true if the array an element at anIndex.
 boolean hasObject(P2Object aP2Object)
          returns true if the array contains aP2Object
 P2Array operation_collect(P2Object source, P2Block aBlock)
          for each entry in the array executes aBlock with the entry given as an argument to the block.
 void operation_do(P2Object source, P2Block aBlock)
          for each object in the array executes aBlock with the object given as an argument to the block.
protected  void operation_removeAll()
          Removes all objects stored in the receiver.
 P2Object readXml(com.twicom.qdparser.TaggedElement xml, java.util.Map<java.lang.Integer,P2Serializable> read)
           
protected  P2Object remove(int anIndex)
          Answer the value associated with the given index and remove it from the receiver.
protected  boolean removeObject(P2Object anObject)
          Removes anObject from the receiver.
 int size()
          returns the number of elements in the receiver
 java.lang.String toString()
           
 com.twicom.qdparser.TaggedElement writeXml(java.util.Set<P2Object> written)
           
 
Methods inherited from class net.ponder2.objects.P2Object
asBlock, asBoolean, asClass, asDouble, asFloat, asInteger, asLong, asNumber, asString, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, fromXml, getManagedObject, getOID, getSMC, operation, operation, setSMC
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

P2Array

public P2Array()
creates an empty P2Array


P2Array

public P2Array(P2Object... values)
creates a P2Array initialised with values

Parameters:
values - the values to use to initialise the array

P2Array

public P2Array(java.lang.String... values)
creates a P2Array initialised with string values

Parameters:
values - the values to use to initialise the array

P2Array

public P2Array(int... values)
creates a P2Array initialised with int values

Parameters:
values - the values to use to initialise the array
Method Detail

asArray

public P2Object[] asArray()
                   throws Ponder2ArgumentException
Description copied from class: P2Object
Returns itself as an array of Ponder2 objects

Overrides:
asArray in class P2Object
Returns:
the array value
Throws:
Ponder2ArgumentException

asP2Array

public P2Array asP2Array()
                  throws Ponder2ArgumentException
Description copied from class: P2Object
Returns itself as a Ponder2 Array

Overrides:
asP2Array in class P2Object
Returns:
the array value
Throws:
Ponder2ArgumentException

asHash

public P2Hash asHash()
              throws Ponder2ArgumentException,
                     Ponder2OperationException
Returns a Hash comprising of the array contents taken as key, value pairs

Overrides:
asHash in class P2Object
Returns:
the hash value
Throws:
Ponder2ArgumentException
Ponder2OperationException
See Also:
P2Object.asHash()

operation_do

public void operation_do(P2Object source,
                         P2Block aBlock)
                  throws Ponder2Exception
for each object in the array executes aBlock with the object given as an argument to the block. Answers the receiver

Parameters:
source - the originator of the command
aBlock - the block to be executed
Throws:
Ponder2Exception

operation_collect

public P2Array operation_collect(P2Object source,
                                 P2Block aBlock)
                          throws Ponder2Exception
for each entry in the array executes aBlock with the entry given as an argument to the block. Answers an array of answers built from each execution of the block.

Parameters:
source - the originator of the command
aBlock - the block to be executed
Returns:
an array with the results of the block executions
Throws:
Ponder2Exception

add

public void add(P2Object aP2Object)
adds a aP2Object to the receiver. Answers the receiver

Parameters:
aP2Object - the object to be added to the array

addAll

public void addAll(P2Array anArray)
            throws Ponder2ArgumentException
adds all objects in anArray to the receiver. Answers the receiver

Parameters:
anArray - the array to be added to this object
Throws:
Ponder2ArgumentException

at

public P2Object at(int anIndex)
returns the object at anIndex

Parameters:
anIndex - the index of the required object
Returns:
the object located by anIndex

atput

public P2Object atput(int anIndex,
                      P2Object aP2Object)
inserts aP2Object at anIndex posiion in the array. Returns the object added.

Parameters:
anIndex - the index of the object to be added
aP2Object - the object to be added
Returns:
the object that was added

size

public int size()
returns the number of elements in the receiver

Returns:
the number of elements held

has

public boolean has(int anIndex)
returns true if the array an element at anIndex. This is really here to compliment the other collections and the remove: operations.

Parameters:
anIndex - the object to be checked
Returns:
true if the object is in the array

hasObject

public boolean hasObject(P2Object aP2Object)
returns true if the array contains aP2Object

Parameters:
aP2Object - the object to be checked
Returns:
true if the object is in the array

remove

protected P2Object remove(int anIndex)
Answer the value associated with the given index and remove it from the receiver.


removeObject

protected boolean removeObject(P2Object anObject)
                        throws Ponder2Exception
Removes anObject from the receiver. All copies of anObject will be removed. Answers true if one or more were removed.

Parameters:
anObject - the object to be removed
Returns:
true if the an object was removed
Throws:
Ponder2Exception

operation_removeAll

protected void operation_removeAll()
Removes all objects stored in the receiver. Answers self.


writeXml

public com.twicom.qdparser.TaggedElement writeXml(java.util.Set<P2Object> written)
                                           throws Ponder2OperationException
Specified by:
writeXml in interface P2Serializable
Overrides:
writeXml in class P2Object
Throws:
Ponder2OperationException

readXml

public P2Object readXml(com.twicom.qdparser.TaggedElement xml,
                        java.util.Map<java.lang.Integer,P2Serializable> read)
                 throws Ponder2OperationException,
                        Ponder2ArgumentException
Specified by:
readXml in interface P2Serializable
Specified by:
readXml in class P2Object
Throws:
Ponder2OperationException
Ponder2ArgumentException

getValues

public java.util.Vector<P2Object> getValues()
Returns all the values in the array as a Vector

Returns:
the values

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2008 Imperial College. All Rights Reserved.