cascading.tuple
Class Tuple

java.lang.Object
  extended by cascading.tuple.Tuple
All Implemented Interfaces:
Serializable, Comparable, Iterable
Direct Known Subclasses:
IndexTuple, 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<Object> elements
          Field elements
protected  boolean isUnmodifiable
          Field isUnmodifiable
 
Constructor Summary
  Tuple()
          Constructor Tuple creates a new Tuple instance.
protected Tuple(List<Object> elements)
           
  Tuple(Object... values)
          Constructor Tuple creates a new Tuple instance with all the given values.
  Tuple(Tuple tuple)
          Copy constructor.
 
Method Summary
 void add(Comparable value)
          Method add adds a new element value to this instance.
 void add(Object value)
          Method add adds a new element value to this instance.
 void addAll(Object... 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)
          Deprecated.  
 void clear()
          Method clear empties this Tuple instance.
 int compareTo(Comparator[] comparators, Tuple other)
           
 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.
static List<Object> elements(Tuple tuple)
          Returns a reference to the private elements of the given Tuple.
 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.
 Object getObject(int pos)
          Method get returns the element at the given position i.
 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)
          Deprecated.  
 String print()
          Method print returns a parsable String representation of this Tuple instance.
protected  StringBuffer print(StringBuffer buffer)
           
 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, Object value)
          Method set sets the given value to the given index position in this instance.
 int size()
          Method size returns 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.
 String toString(String delim, boolean printNull)
          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<Object> elements
Field elements

Constructor Detail

Tuple

protected Tuple(List<Object> elements)

Tuple

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


Tuple

@ConstructorProperties(value="tuple")
public Tuple(Tuple tuple)
Copy constructor. Does not nest the given Tuple instance within this new instance. Use add(Object).

Parameters:
tuple - of type Tuple

Tuple

@ConstructorProperties(value="values")
public Tuple(Object... values)
Constructor Tuple creates a new Tuple instance with all the given values.

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

asUnmodifiable

@Deprecated
public static Tuple asUnmodifiable(Tuple tuple)
Deprecated. 

Method asUnmodifiable marks the given Tuple instance as unmodifiable.

Parameters:
tuple - of type Tuple
Returns:
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

@Deprecated
public static Tuple parse(String string)
Deprecated. 

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

This method has been deprecated as it doesn't properly handle nulls, and any types other than primitive types.

Parameters:
string - of type String
Returns:
Tuple

elements

public static List<Object> elements(Tuple tuple)
Returns a reference to the private elements of the given Tuple.

This method is for internal use and is subject to change scope in a future release.

Parameters:
tuple - of type Tuple
Returns:
List

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.

This method assumes the element implements Comparable in order to maintain backwards compatibility. See getObject(int) for an alternative.

Parameters:
pos - of type int
Returns:
Comparable

getObject

public Object getObject(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

clear

public void clear()
Method clear empties this Tuple instance. A subsequent call to size() will return zero (0).


add

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

Parameters:
value - of type Comparable

add

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

Parameters:
value - of type Object

addAll

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

Parameters:
values - of type Object...

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,
                Object value)
Method set sets the given value to the given index position in this instance.

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

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 returns 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(Comparator[] comparators,
                     Tuple other)

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

toString

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

Parameters:
delim - of type String
printNull - of type boolean
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

print

protected StringBuffer print(StringBuffer buffer)


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