cascading.tuple
Class Tuple

java.lang.Object
  extended by cascading.tuple.Tuple
All Implemented Interfaces:
Serializable, Comparable, Iterable
Direct Known Subclasses:
TuplePair

public class Tuple
extends Object
implements Comparable, Iterable, Serializable

A Tuple represents a set of values. Consider a Tuple the same as a data base record where every value is a column in that table. A Tuple stream would be a set of Tuple instances, which are passed consecutively through a Pipe assembly.

A Tuple is a collection of elements. These elements must be of type Comparable, so that Tuple instances can be compared. Tuple itself is Comparable and subsequently can hold elements of type Tuple.

Tuples are mutable for sake of efficiency. Since Tuples are mutable, it is not a good idea to hold an instance around with out first copying it via its copy constructor, a subsequent Pipe could change the Tuple in place. This is especially true for Aggregator operators.

Because a Tuple can hold any Comparable type, it is suitable for storing custom types. But all custom types must have a serialization support per the underlying framework.

For Hadoop, a Serialization implementation must be registered with Hadoop. For further performance improvements, see the SerializationToken Java annotation.

See Also:
Comparable, Serialization, SerializationToken, Serialized Form

Field Summary
protected  List<Comparable> elements
          Field elements
protected  boolean isUnmodifiable
          Field isUnmodifiable
 
Constructor Summary
  Tuple()
          Constructor Tuple creates a new Tuple instance.
  Tuple(Comparable... values)
          Constructor Tuple creates a new Tuple instance with all the given values.
protected Tuple(List<Comparable> elements)
           
  Tuple(String value)
          Constructor Tuple creates a new Tuple instance with a single String value.
  Tuple(Tuple tuple)
          Copy constructor.
 
Method Summary
 void add(Comparable value)
          Method add adds a new element value to this instance.
 void addAll(Comparable... values)
          Method addAll adds all given values to this instance.
 void addAll(Tuple tuple)
          Method addAll adds all the element values of the given Tuple instance to this instance.
 Tuple append(Tuple... tuples)
          Method append appends all the values of the given Tuple instances to a copy of this instance.
static Tuple asUnmodifiable(Tuple tuple)
           
 int compareTo(Object other)
          Method compareTo implements the Comparable.compareTo(Object) method.
 int compareTo(Tuple other)
          Method compareTo compares this Tuple to the given Tuple instance.
 boolean equals(Object object)
           
 String format(String format)
          Method format uses the Formatter class for formatting this tuples values into a new string.
 Tuple get(Fields declarator, Fields selector)
          Method get returns a new Tuple populated with only those values whose field names are specified in the given selector.
 Comparable get(int pos)
          Method get returns the element at the given position i.
 Tuple get(int[] pos)
          Method get will return a new Tuple instace populated with element values from the given array of positions.
 boolean getBoolean(int pos)
          Method getBoolean returns the element at the given position as a boolean.
 double getDouble(int pos)
          Method getDouble returns the element at the given position i as a double.
 float getFloat(int pos)
          Method getFloat returns the element at the given position i as a float.
 int getInteger(int pos)
          Method getInteger returns the element at the given position i as an int.
 long getLong(int pos)
          Method getLong returns the element at the given position i as an long.
 short getShort(int pos)
          Method getShort returns the element at the given position i as an short.
 String getString(int pos)
          Method getString returns the element at the given position i as a String.
 Class[] getTypes()
          Method getTypes returns an array of the element classes.
 int hashCode()
           
 boolean isEmpty()
          Method isEmpty returns true if this Tuple instance has no values.
 boolean isUnmodifiable()
          Method isUnmodifiable returns true if this Tuple instance is unmodifiable.
 Iterator iterator()
          Method iterator returns an Iterator over this Tuple instances values.
 Tuple leave(int[] pos)
          Method is the inverse of remove(int[]).
static Tuple parse(String string)
          Method parse will parse the print() String representation of a Tuple instance and return a new Tuple instance.
 String print()
          Method print returns a parsable String representation of this Tuple instance.
 void put(Fields declarator, Fields fields, Tuple tuple)
          Method put places the values of the given tuple into the positions specified by the fields argument.
 Tuple remove(Fields declarator, Fields selector)
          Method remove removes the values specified by the given selector.
 Tuple remove(int[] pos)
          Method remove removes the values specified by the given pos array and returns a new Tuple containing the removed values.
 void set(Fields declarator, Fields selector, Tuple tuple)
          Method set sets the values in the given selector positions to the values from the given Tuple.
 void set(int index, Comparable value)
          Method set sets the given value to the given index position in this instance.
 int size()
          Method size retuns the number of values in this Tuple instance.
static Tuple size(int size)
          Method size returns a new Tuple instance of the given size with nulls as its element values.
static Tuple size(int size, Comparable value)
          Method size returns a new Tuple instance of the given size with the given Comparable as its element values.
 String toString()
           
 String toString(String delim)
          Method toString writes this Tuple instance values out to a String delimited by the given String value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

isUnmodifiable

protected boolean isUnmodifiable
Field isUnmodifiable


elements

protected List<Comparable> elements
Field elements

Constructor Detail

Tuple

protected Tuple(List<Comparable> elements)

Tuple

public Tuple()
Constructor Tuple creates a new Tuple instance.


Tuple

public Tuple(String value)
Constructor Tuple creates a new Tuple instance with a single String value.

Parameters:
value - of type String

Tuple

public Tuple(Tuple tuple)
Copy constructor. Does not nest the given Tuple instance within this new instance. Use add(Comparable).

Parameters:
tuple - of type Tuple

Tuple

public Tuple(Comparable... values)
Constructor Tuple creates a new Tuple instance with all the given values.

Parameters:
values - of type Comparable...
Method Detail

asUnmodifiable

public static Tuple asUnmodifiable(Tuple tuple)

size

public static Tuple size(int size)
Method size returns a new Tuple instance of the given size with nulls as its element values.

Parameters:
size - of type int
Returns:
Tuple

size

public static Tuple size(int size,
                         Comparable value)
Method size returns a new Tuple instance of the given size with the given Comparable as its element values.

Parameters:
size - of type int
value - of type Comparable
Returns:
Tuple

parse

public static Tuple parse(String string)
Method parse will parse the print() String representation of a Tuple instance and return a new Tuple instance.

Parameters:
string - of type String
Returns:
Tuple

isUnmodifiable

public boolean isUnmodifiable()
Method isUnmodifiable returns true if this Tuple instance is unmodifiable.

Returns:
boolean

get

public Comparable get(int pos)
Method get returns the element at the given position i.

Parameters:
pos - of type int
Returns:
Comparable

getString

public String getString(int pos)
Method getString returns the element at the given position i as a String.

Parameters:
pos - of type int
Returns:
String

getFloat

public float getFloat(int pos)
Method getFloat returns the element at the given position i as a float. Zero if null.

Parameters:
pos - of type int
Returns:
float

getDouble

public double getDouble(int pos)
Method getDouble returns the element at the given position i as a double. Zero if null.

Parameters:
pos - of type int
Returns:
double

getInteger

public int getInteger(int pos)
Method getInteger returns the element at the given position i as an int. Zero if null.

Parameters:
pos - of type int
Returns:
int

getLong

public long getLong(int pos)
Method getLong returns the element at the given position i as an long. Zero if null.

Parameters:
pos - of type int
Returns:
long

getShort

public short getShort(int pos)
Method getShort returns the element at the given position i as an short. Zero if null.

Parameters:
pos - of type int
Returns:
long

getBoolean

public boolean getBoolean(int pos)
Method getBoolean returns the element at the given position as a boolean. If the value is (case ignored) the string 'true', a true value will be returned. false if null.

Parameters:
pos - of type int
Returns:
boolean

get

public Tuple get(int[] pos)
Method get will return a new Tuple instace populated with element values from the given array of positions.

Parameters:
pos - of type int[]
Returns:
Tuple

get

public Tuple get(Fields declarator,
                 Fields selector)
Method get returns a new Tuple populated with only those values whose field names are specified in the given selector. The declarator Fields instance declares the fields and positions in the current Tuple instance.

Parameters:
declarator - of type Fields
selector - of type Fields
Returns:
Tuple

leave

public Tuple leave(int[] pos)
Method is the inverse of remove(int[]).

Parameters:
pos - of type int[]
Returns:
Tuple

add

public void add(Comparable value)
Method add adds a new element value to this instance.

Parameters:
value - of type Comparable

addAll

public void addAll(Comparable... values)
Method addAll adds all given values to this instance.

Parameters:
values - of type Comparable...

addAll

public void addAll(Tuple tuple)
Method addAll adds all the element values of the given Tuple instance to this instance.

Parameters:
tuple - of type Tuple

set

public void set(int index,
                Comparable value)
Method set sets the given value to the given index position in this instance.

Parameters:
index - of type int
value - of type Comparable

put

public void put(Fields declarator,
                Fields fields,
                Tuple tuple)
Method put places the values of the given tuple into the positions specified by the fields argument. The declarator Fields value declares the fields in this Tuple instance.

Parameters:
declarator - of type Fields
fields - of type Fields
tuple - of type Tuple

remove

public Tuple remove(int[] pos)
Method remove removes the values specified by the given pos array and returns a new Tuple containing the removed values.

Parameters:
pos - of type int[]
Returns:
Tuple

remove

public Tuple remove(Fields declarator,
                    Fields selector)
Method remove removes the values specified by the given selector. The declarator declares the fields in this instance.

Parameters:
declarator - of type Fields
selector - of type Fields
Returns:
Tuple

set

public void set(Fields declarator,
                Fields selector,
                Tuple tuple)
Method set sets the values in the given selector positions to the values from the given Tuple.

Parameters:
declarator - of type Fields
selector - of type Fields
tuple - of type Tuple

iterator

public Iterator iterator()
Method iterator returns an Iterator over this Tuple instances values.

Specified by:
iterator in interface Iterable
Returns:
Iterator

isEmpty

public boolean isEmpty()
Method isEmpty returns true if this Tuple instance has no values.

Returns:
the empty (type boolean) of this Tuple object.

size

public int size()
Method size retuns the number of values in this Tuple instance.

Returns:
int

getTypes

public Class[] getTypes()
Method getTypes returns an array of the element classes. Null if the element is null.

Returns:
the types (type Class[]) of this Tuple object.

append

public Tuple append(Tuple... tuples)
Method append appends all the values of the given Tuple instances to a copy of this instance.

Parameters:
tuples - of type Tuple
Returns:
Tuple

compareTo

public int compareTo(Tuple other)
Method compareTo compares this Tuple to the given Tuple instance.

Parameters:
other - of type Tuple
Returns:
int

compareTo

public int compareTo(Object other)
Method compareTo implements the Comparable.compareTo(Object) method.

Specified by:
compareTo in interface Comparable
Parameters:
other - of type Object
Returns:
int

equals

public boolean equals(Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(String delim)
Method toString writes this Tuple instance values out to a String delimited by the given String value.

Parameters:
delim - of type String
Returns:
String

format

public String format(String format)
Method format uses the Formatter class for formatting this tuples values into a new string.

Parameters:
format - of type String
Returns:
String

print

public String print()
Method print returns a parsable String representation of this Tuple instance.

Returns:
String


Copyright © 2007-2008 Concurrent, Inc. All Rights Reserved.