|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcascading.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 |
static Tuple |
NULL
A constant empty Tuple instance. |
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. |
void |
addBoolean(boolean value)
Method addBoolean adds a new element value to this instance. |
void |
addDouble(double value)
Method addDouble adds a new element value to this instance. |
void |
addFloat(float value)
Method addFloat adds a new element value to this instance. |
void |
addInteger(int value)
Method addInteger adds a new element value to this instance. |
void |
addLong(long value)
Method addLong adds a new element value to this instance. |
void |
addShort(short value)
Method addShort adds a new element value to this instance. |
void |
addString(String value)
Method addString adds a new element value to this instance. |
Tuple |
append(Tuple... tuples)
Method append appends all the values of the given Tuple instances to a copy of this instance. |
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)
Deprecated. |
Tuple |
get(int[] pos)
Method get will return a new Tuple instance 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. |
int[] |
getPos(Fields declarator,
Fields selector)
|
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()
|
protected void |
internalSet(int index,
Object value)
|
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<Object> |
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. |
StringBuffer |
printTo(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. |
void |
setAll(Tuple... tuples)
Method setAll sets each element value of the given Tuple instances into the corresponding position of this instance. |
void |
setAll(Tuple tuple)
Method setAll sets each element value of the given Tuple instance into the corresponding position of this instance. |
void |
setBoolean(int index,
boolean value)
Method setBoolean sets the given value to the given index position in this instance. |
void |
setDouble(int index,
double value)
Method setDouble sets the given value to the given index position in this instance. |
void |
setFloat(int index,
float value)
Method setFloat sets the given value to the given index position in this instance. |
void |
setInteger(int index,
int value)
Method setInteger sets the given value to the given index position in this instance. |
void |
setLong(int index,
long value)
Method setLong sets the given value to the given index position in this instance. |
void |
setShort(int index,
short value)
Method setShort sets the given value to the given index position in this instance. |
void |
setString(int index,
String value)
Method setString 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 |
---|
public static final Tuple NULL
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 |
---|
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()
@Deprecated public Comparable get(int pos)
Comparable
in order to maintain backwards compatibility. See
getObject(int)
for an alternative.
This method is deprecated, use getObject(int)
instead.
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 int[] getPos(Fields declarator, Fields selector)
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 addBoolean(boolean value)
value
- of type booleanpublic void addShort(short value)
value
- of type shortpublic void addInteger(int value)
value
- of type intpublic void addLong(long value)
value
- of type longpublic void addFloat(float value)
value
- of type floatpublic void addDouble(double value)
value
- of type doublepublic void addString(String value)
value
- of type Stringpublic void addAll(Object... values)
values
- of type Object...public void addAll(Tuple tuple)
tuple
- of type Tuplepublic void setAll(Tuple tuple)
tuple
- of type Tuplepublic void setAll(Tuple... tuples)
tuples
- of type Tuple[]public void set(int index, Object value)
index
- of type intvalue
- of type Objectpublic void setBoolean(int index, boolean value)
index
- of type intvalue
- of type booleanpublic void setShort(int index, short value)
index
- of type intvalue
- of type shortpublic void setInteger(int index, int value)
index
- of type intvalue
- of type intpublic void setLong(int index, long value)
index
- of type intvalue
- of type longpublic void setFloat(int index, float value)
index
- of type intvalue
- of type floatpublic void setDouble(int index, double value)
index
- of type intvalue
- of type doublepublic void setString(int index, String value)
index
- of type intvalue
- of type Stringprotected final void internalSet(int index, Object value)
public 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<Object> iterator()
Iterator
over this Tuple instances values.
iterator
in interface Iterable<Object>
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<Object>
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()
public StringBuffer printTo(StringBuffer buffer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |