Class jada.tuple.Tuple
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jada.tuple.Tuple

java.lang.Object
   |
   +----jada.tuple.Tuple

public class Tuple
extends Object
implements TupleItem
Base tuple class.
A tuple is a ordered set of items. Each item of a Jada tuple can be either an Integer, a String, a class that implements TupleItem (and we say it is "actual") or a Class (and we say it is "formal")
A Jada tuple can have as much as 10 items and 10 constructors are provided in order to ease the creation of a new tuple.
Tuples are used for the tuple space operations in an associative way using a matching operation. This operation is performed by the matches method. Two tuples are matching if they have the same no. of items and the i-th field of the first tuple matches the i-th field of the second one for each i.
Two items are matching if:
  • they are Integers and they represent the same value
  • they are String and they have the same contents
  • they implement TupleItem and the matchItem method returns true
  • they are Class and they represent the same class
  • one is a Class and the other is an instance of that class
    so the tuple
    Tuple ta = new Tuple(new Integer(3), "three")
    will match the tuple
    Tuple tb = new Tuple(new Integer(3), new String().getClass())
    Note that Tuple implements TupleItem so you can use a tuple as an item of another tuple.
    A tuple can be converted to a string using toString()
    A tuple string format is a list of items between brackets separated by commas. Items can be actual or formal. If an item is formal it starts with a ? followed the name of the class it represents ("i" and "s" are used as short formats for Integer and String respectively). If it's actual the toString() method is used to represent its value.
    Note: if you don't follow the rules for writing a TupleItem some method of this class (notably buildItem) may generate a class-related exception which is caught and is printed to the System.err stream.

    Constructor Index

     o Tuple()
    Constructor: builds an empty tuple.
     o Tuple(Tuple)
    Constructor: build a tuple copying the given one.
     o Tuple(int)
    Constructor: builds the tuple calling init(int).
     o Tuple(byte[])
    Constructor: builds the tuple from a byte array calling buildItem.
     o Tuple(Object)
    Constructor: buils a tuple with the item item This is first of a set of 10 constructors that differ on the items number.
     o Tuple(Object, Object)
     o Tuple(Object, Object, Object)
     o Tuple(Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object, Object, Object, Object, Object)
     o Tuple(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)

    Method Index

     o I()
    Short form for IntegerClass.
     o IntegerClass()
    Returns the Class for an Integer object.
     o S()
    Short form for StringClass.
     o StringClass()
    Returns the Class for a String object.
     o buildItem(byte[])
    From the TupleItem interface: build this tuple from a tuple array
     o buildItem(byte[], int)
    Builds this tuple from a tuple array starting at position from
     o cloneItem(Object)
    From the TupleItem interface: clone a tuple given a "source" one
     o dumpItem()
    From the TupleItem interface: dumps this tuple to an array of bytes
     o formal()
    Returns the Class for a tuple, useful when we want a tuple as a formal field for another tuple.
     o getIndex()
    Returns the index of this tuple if it is a result for a multiple in or read operation.
     o getItem(int)
    Returns the Object at the given position.
     o getSize()
    Returns the size (in bytes) of this object as used in the dumpItem method (Note: this method really calls dumpItem to calculate the size if it has not already been called and this may be time-consuming).
     o initFromString(String)
    Allocates basic data and sets the tuple reading its regular string representation.
     o matchesItem(Object)
    Checks for the given tuple to match the current one.
     o read(InputStream)
    Read this tuple from the given InputStream.
     o setItem(int, Object)
    Sets an item of the tuple.
    Watch out: just String, Integer and TupleItem are valid object types.
     o toString()
    Override Object.toString().
     o write(OutputStream)
    Write this tuple to the given OutputStream.

    Constructors

     o Tuple
      public Tuple()
    
    Constructor: builds an empty tuple.
     o Tuple
      public Tuple(Tuple source)
    
    Constructor: build a tuple copying the given one.
     o Tuple
      public Tuple(int items)
    
    Constructor: builds the tuple calling init(int). The resulting tuple contains formal integer values.
    See Also:
    init
     o Tuple
      public Tuple(byte bytes[])
    
    Constructor: builds the tuple from a byte array calling buildItem.
    See Also:
    buildItem
     o Tuple
      public Tuple(Object item)
    
    Constructor: buils a tuple with the item item This is first of a set of 10 constructors that differ on the items number.
     o Tuple
      public Tuple(Object item1,
                   Object item2)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5,
                   Object item6)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5,
                   Object item6,
                   Object item7)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5,
                   Object item6,
                   Object item7,
                   Object item8)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5,
                   Object item6,
                   Object item7,
                   Object item8,
                   Object item9)
    
     o Tuple
      public Tuple(Object item1,
                   Object item2,
                   Object item3,
                   Object item4,
                   Object item5,
                   Object item6,
                   Object item7,
                   Object item8,
                   Object item9,
                   Object item10)
    

    Methods

     o getSize
      public int getSize()
    
    Returns the size (in bytes) of this object as used in the dumpItem method (Note: this method really calls dumpItem to calculate the size if it has not already been called and this may be time-consuming).
    See Also:
    dumpItem
     o getIndex
      public int getIndex()
    
    Returns the index of this tuple if it is a result for a multiple in or read operation.
     o IntegerClass
      public static Class IntegerClass()
    
    Returns the Class for an Integer object. Useful for a Integer formal tuple item.
    See Also:
    I
     o StringClass
      public static Class StringClass()
    
    Returns the Class for a String object. Useful for a String formal tuple item.
    See Also:
    S
     o I
      public static Class I()
    
    Short form for IntegerClass.
    See Also:
    IntegerClass
     o S
      public static Class S()
    
    Short form for StringClass.
    See Also:
    StringClass
     o formal
      public static Class formal()
    
    Returns the Class for a tuple, useful when we want a tuple as a formal field for another tuple.
     o initFromString
      protected void initFromString(String s)
    
    Allocates basic data and sets the tuple reading its regular string representation.
     o setItem
      public void setItem(int index,
                          Object value)
    
    Sets an item of the tuple.
    Watch out: just String, Integer and TupleItem are valid object types.
    See Also:
    getItem
     o getItem
      public Object getItem(int index)
    
    Returns the Object at the given position. Watch out: this is not a copy: its the object itself!
    See Also:
    setItem
     o matchesItem
      public boolean matchesItem(Object object)
    
    Checks for the given tuple to match the current one.
     o toString
      public String toString()
    
    Override Object.toString(). Uses the same representation initFromString uses to init a tuple
    Overrides:
    toString in class Object
    See Also:
    initFromString
     o write
      public void write(OutputStream os) throws IOException
    
    Write this tuple to the given OutputStream.
     o read
      public boolean read(InputStream is) throws IOException
    
    Read this tuple from the given InputStream. Return false if an "empty" tuple is read.
     o cloneItem
      public void cloneItem(Object object_source)
    
    From the TupleItem interface: clone a tuple given a "source" one
     o dumpItem
      public byte[] dumpItem()
    
    From the TupleItem interface: dumps this tuple to an array of bytes
     o buildItem
      public boolean buildItem(byte b[])
    
    From the TupleItem interface: build this tuple from a tuple array
     o buildItem
      public boolean buildItem(byte b[],
                               int from)
    
    Builds this tuple from a tuple array starting at position from

    All Packages  Class Hierarchy  This Package  Previous  Next  Index