Skip to content

Commit 2a022ae

Browse files
author
Nathan Marz
committed
javadoc for tuple
1 parent c2a5bf1 commit 2a022ae

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

src/jvm/backtype/storm/tuple/Tuple.java

+72-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
/**
9+
* The tuple is the main data structure in Storm. A tuple is a named list of values,
10+
* where each value can be any type. Tuples are dynamically typed -- the types of the fields
11+
* do not need to be declared. Tuples have helper methods like getInteger and getString
12+
* to get field values without having to cast the result.
13+
*
14+
* Storm needs to know how to serialize all the values in a tuple. By default, Storm
15+
* knows how to serialize the primitive types, strings, and byte arrays. If you want to
16+
* use another type, you'll need to implement and register a serializer for that type.
17+
* See {@link http://github.com/nathanmarz/storm/wiki/Serialization} for more info.
18+
*/
819
public class Tuple {
920
private List<Object> values;
1021
private int taskId;
@@ -48,46 +59,88 @@ public Tuple copyWithNewId(long id) {
4859
return new Tuple(this.context, this.values, this.taskId, this.streamId, MessageId.makeId(newIds));
4960
}
5061

62+
/**
63+
* Returns the number of fields in this tuple.
64+
*/
5165
public int size() {
5266
return values.size();
5367
}
54-
68+
69+
/**
70+
* Gets the field at position i in the tuple. Returns object since tuples are dynamically typed.
71+
*/
5572
public Object getValue(int i) {
5673
return values.get(i);
5774
}
5875

76+
/**
77+
* Returns the String at position i in the tuple. If that field is not a String,
78+
* you will get a runtime error.
79+
*/
5980
public String getString(int i) {
6081
return (String) values.get(i);
6182
}
6283

84+
/**
85+
* Returns the Integer at position i in the tuple. If that field is not an Integer,
86+
* you will get a runtime error.
87+
*/
6388
public Integer getInteger(int i) {
6489
return (Integer) values.get(i);
6590
}
6691

92+
/**
93+
* Returns the Long at position i in the tuple. If that field is not a Long,
94+
* you will get a runtime error.
95+
*/
6796
public Long getLong(int i) {
6897
return (Long) values.get(i);
6998
}
7099

100+
/**
101+
* Returns the Boolean at position i in the tuple. If that field is not a Boolean,
102+
* you will get a runtime error.
103+
*/
71104
public Boolean getBoolean(int i) {
72105
return (Boolean) values.get(i);
73106
}
74107

108+
/**
109+
* Returns the Short at position i in the tuple. If that field is not a Short,
110+
* you will get a runtime error.
111+
*/
75112
public Short getShort(int i) {
76113
return (Short) values.get(i);
77114
}
78115

116+
/**
117+
* Returns the Byte at position i in the tuple. If that field is not a Byte,
118+
* you will get a runtime error.
119+
*/
79120
public Byte getByte(int i) {
80121
return (Byte) values.get(i);
81122
}
82123

124+
/**
125+
* Returns the Double at position i in the tuple. If that field is not a Double,
126+
* you will get a runtime error.
127+
*/
83128
public Double getDouble(int i) {
84129
return (Double) values.get(i);
85130
}
86131

132+
/**
133+
* Returns the Float at position i in the tuple. If that field is not a Float,
134+
* you will get a runtime error.
135+
*/
87136
public Float getFloat(int i) {
88137
return (Float) values.get(i);
89138
}
90139

140+
/**
141+
* Returns the byte array at position i in the tuple. If that field is not a byte array,
142+
* you will get a runtime error.
143+
*/
91144
public byte[] getBinary(int i) {
92145
return (byte[]) values.get(i);
93146
}
@@ -97,26 +150,44 @@ public List<Object> getTuple() {
97150
return values;
98151
}
99152

153+
/**
154+
* Gets all the values in this tuple.
155+
*/
100156
public List<Object> getValues() {
101157
return values;
102158
}
103159

160+
/**
161+
* Gets the names of the fields in this tuple.
162+
*/
104163
public Fields getFields() {
105164
return context.getComponentOutputFields(getSourceComponent(), getSourceStreamId());
106165
}
107166

167+
/**
168+
* Returns a subset of the tuple based on the fields selector.
169+
*/
108170
public List<Object> select(Fields selector) {
109171
return getFields().select(selector, values);
110172
}
111173

174+
/**
175+
* Gets the id of the component that created this tuple.
176+
*/
112177
public int getSourceComponent() {
113178
return context.getComponentId(taskId);
114179
}
115180

181+
/**
182+
* Gets the id of the task that created this tuple.
183+
*/
116184
public int getSourceTask() {
117185
return taskId;
118186
}
119187

188+
/**
189+
* Gets the id of the stream that this tuple was emitted to.
190+
*/
120191
public int getSourceStreamId() {
121192
return streamId;
122193
}

0 commit comments

Comments
 (0)