5
5
import java .util .List ;
6
6
import java .util .Map ;
7
7
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
+ */
8
19
public class Tuple {
9
20
private List <Object > values ;
10
21
private int taskId ;
@@ -48,46 +59,88 @@ public Tuple copyWithNewId(long id) {
48
59
return new Tuple (this .context , this .values , this .taskId , this .streamId , MessageId .makeId (newIds ));
49
60
}
50
61
62
+ /**
63
+ * Returns the number of fields in this tuple.
64
+ */
51
65
public int size () {
52
66
return values .size ();
53
67
}
54
-
68
+
69
+ /**
70
+ * Gets the field at position i in the tuple. Returns object since tuples are dynamically typed.
71
+ */
55
72
public Object getValue (int i ) {
56
73
return values .get (i );
57
74
}
58
75
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
+ */
59
80
public String getString (int i ) {
60
81
return (String ) values .get (i );
61
82
}
62
83
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
+ */
63
88
public Integer getInteger (int i ) {
64
89
return (Integer ) values .get (i );
65
90
}
66
91
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
+ */
67
96
public Long getLong (int i ) {
68
97
return (Long ) values .get (i );
69
98
}
70
99
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
+ */
71
104
public Boolean getBoolean (int i ) {
72
105
return (Boolean ) values .get (i );
73
106
}
74
107
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
+ */
75
112
public Short getShort (int i ) {
76
113
return (Short ) values .get (i );
77
114
}
78
115
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
+ */
79
120
public Byte getByte (int i ) {
80
121
return (Byte ) values .get (i );
81
122
}
82
123
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
+ */
83
128
public Double getDouble (int i ) {
84
129
return (Double ) values .get (i );
85
130
}
86
131
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
+ */
87
136
public Float getFloat (int i ) {
88
137
return (Float ) values .get (i );
89
138
}
90
139
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
+ */
91
144
public byte [] getBinary (int i ) {
92
145
return (byte []) values .get (i );
93
146
}
@@ -97,26 +150,44 @@ public List<Object> getTuple() {
97
150
return values ;
98
151
}
99
152
153
+ /**
154
+ * Gets all the values in this tuple.
155
+ */
100
156
public List <Object > getValues () {
101
157
return values ;
102
158
}
103
159
160
+ /**
161
+ * Gets the names of the fields in this tuple.
162
+ */
104
163
public Fields getFields () {
105
164
return context .getComponentOutputFields (getSourceComponent (), getSourceStreamId ());
106
165
}
107
166
167
+ /**
168
+ * Returns a subset of the tuple based on the fields selector.
169
+ */
108
170
public List <Object > select (Fields selector ) {
109
171
return getFields ().select (selector , values );
110
172
}
111
173
174
+ /**
175
+ * Gets the id of the component that created this tuple.
176
+ */
112
177
public int getSourceComponent () {
113
178
return context .getComponentId (taskId );
114
179
}
115
180
181
+ /**
182
+ * Gets the id of the task that created this tuple.
183
+ */
116
184
public int getSourceTask () {
117
185
return taskId ;
118
186
}
119
187
188
+ /**
189
+ * Gets the id of the stream that this tuple was emitted to.
190
+ */
120
191
public int getSourceStreamId () {
121
192
return streamId ;
122
193
}
0 commit comments