|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cascading.tuple.Tuple
public class Tuple
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 subsequentPipe
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.
Comparable
,
Serialization
,
SerializationToken
,
Serialized FormField 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 |
---|
protected boolean isUnmodifiable
protected List<Object> elements
Constructor Detail |
---|
protected Tuple(List<Object> elements)
public Tuple()
@ConstructorProperties(value="tuple") public Tuple(Tuple tuple)
add(Object)
.
tuple
- of type Tuple@ConstructorProperties(value="values") public Tuple(Object... values)
values
- of type Object...Method Detail |
---|
@Deprecated public static Tuple asUnmodifiable(Tuple tuple)
tuple
- of type Tuple
public static Tuple size(int size)
size
- of type int
public static Tuple size(int size, Comparable value)
size
- of type intvalue
- of type Comparable
@Deprecated public static Tuple parse(String string)
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.
string
- of type String
public static List<Object> elements(Tuple tuple)
tuple
- of type Tuple
public boolean isUnmodifiable()
public Comparable get(int pos)
Comparable
in order to maintain backwards compatibility. See
getObject(int)
for an alternative.
pos
- of type int
public Object getObject(int pos)
pos
- of type int
public String getString(int pos)
pos
- of type int
public float getFloat(int pos)
pos
- of type int
public double getDouble(int pos)
pos
- of type int
public int getInteger(int pos)
pos
- of type int
public long getLong(int pos)
pos
- of type int
public short getShort(int pos)
pos
- of type int
public boolean getBoolean(int pos)
true
value will be returned. false
if null.
pos
- of type int
public Tuple get(int[] pos)
pos
- of type int[]
public Tuple get(Fields declarator, Fields selector)
declarator
- of type Fieldsselector
- of type Fields
public Tuple leave(int[] pos)
remove(int[])
.
pos
- of type int[]
public void clear()
size()
will return zero (0
).
public void add(Comparable value)
value
- of type Comparablepublic void add(Object value)
value
- of type Objectpublic void addAll(Object... values)
values
- of type Object...public void addAll(Tuple tuple)
tuple
- of type Tuplepublic void set(int index, Object value)
index
- of type intvalue
- of type Objectpublic void put(Fields declarator, Fields fields, Tuple tuple)
declarator
- of type Fieldsfields
- of type Fieldstuple
- of type Tuplepublic Tuple remove(int[] pos)
pos
- of type int[]
public Tuple remove(Fields declarator, Fields selector)
declarator
- of type Fieldsselector
- of type Fields
public void set(Fields declarator, Fields selector, Tuple tuple)
declarator
- of type Fieldsselector
- of type Fieldstuple
- of type Tuplepublic Iterator iterator()
Iterator
over this Tuple instances values.
iterator
in interface Iterable
public boolean isEmpty()
public int size()
public Class[] getTypes()
public Tuple append(Tuple... tuples)
tuples
- of type Tuple
public int compareTo(Tuple other)
other
- of type Tuple
public int compareTo(Comparator[] comparators, Tuple other)
public int compareTo(Object other)
Comparable.compareTo(Object)
method.
compareTo
in interface Comparable
other
- of type Object
public boolean equals(Object object)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public String toString(String delim)
delim
- of type String
public String toString(String delim, boolean printNull)
delim
- of type StringprintNull
- of type boolean
public String format(String format)
Formatter
class for formatting this tuples values into a new string.
format
- of type String
public String print()
protected StringBuffer print(StringBuffer buffer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |