blob: ee38beb919c26d255030179d26f1f6f6b9eeeef3 [file] [log] [blame]
Andreas Wundsam27303462013-07-16 12:52:35 -07001//:: # Copyright 2013, Big Switch Networks, Inc.
2//:: #
3//:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4//:: # the following special exception:
5//:: #
6//:: # LOXI Exception
7//:: #
8//:: # As a special exception to the terms of the EPL, you may distribute libraries
9//:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10//:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11//:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12//:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13//:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14//:: #
15//:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16//:: #
17//:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18//:: # a copy of the EPL at:
19//:: #
20//:: # http::: #www.eclipse.org/legal/epl-v10.html
21//:: #
22//:: # Unless required by applicable law or agreed to in writing, software
23//:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24//:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25//:: # EPL for the specific language governing permissions and limitations
26//:: # under the EPL.
27//::
28//:: from loxi_ir import *
Andreas Wundsambc679f72013-08-01 22:13:09 -070029//:: import os
Andreas Wundsam27303462013-07-16 12:52:35 -070030//:: import itertools
31//:: import of_g
32//:: include('_copyright.java')
33
34//:: include('_autogen.java')
35
36package ${msg.package};
37
38//:: include("_imports.java", msg=msg)
39
Andreas Wundsam99e931d2013-08-22 07:53:53 -070040class ${impl_class} implements ${msg.interface.inherited_declaration()} {
Andreas Wundsam70aa5492013-10-23 15:26:53 -070041//:: if genopts.instrument:
42 private static final Logger logger = LoggerFactory.getLogger(${impl_class}.class);
43//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070044 // version: ${version}
Yotam Harchol791e4882013-09-05 16:32:56 -070045 final static byte WIRE_VERSION = ${version.int_version};
Andreas Wundsam27303462013-07-16 12:52:35 -070046//:: if msg.is_fixed_length:
Yotam Harchol791e4882013-09-05 16:32:56 -070047 final static int LENGTH = ${msg.length};
Andreas Wundsam27303462013-07-16 12:52:35 -070048//:: else:
Yotam Harchol791e4882013-09-05 16:32:56 -070049 final static int MINIMUM_LENGTH = ${msg.min_length};
Andreas Wundsam27303462013-07-16 12:52:35 -070050//:: #endif
51
52//:: for prop in msg.data_members:
Andreas Wundsamf89f7822013-09-23 14:49:24 -070053 //:: if prop.default_value:
54 private final static ${prop.java_type.public_type} ${prop.default_name} = ${prop.default_value};
55 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070056//:: #end
57
58 // OF message fields
59//:: for prop in msg.data_members:
60 private final ${prop.java_type.public_type} ${prop.name};
61//:: #endfor
Andreas Wundsame962d372013-10-02 18:15:58 -070062//
63//:: if all(prop.default_value for prop in msg.data_members):
64 // Immutable default instance
65 final static ${impl_class} DEFAULT = new ${impl_class}(
66 ${", ".join(prop.default_name for prop in msg.data_members)}
67 );
68//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070069
Andreas Wundsam99e931d2013-08-22 07:53:53 -070070 //:: if msg.data_members:
71 // package private constructor - used by readers, builders, and factory
Andreas Wundsam27303462013-07-16 12:52:35 -070072 ${impl_class}(${
73 ", ".join("%s %s" %(prop.java_type.public_type, prop.name) for prop in msg.data_members) }) {
74//:: for prop in msg.data_members:
75 this.${prop.name} = ${prop.name};
76//:: #endfor
77 }
Andreas Wundsam99e931d2013-08-22 07:53:53 -070078 //:: else:
79 final static ${impl_class} INSTANCE = new ${impl_class}();
80 // private empty constructor - use shared instance!
81 private ${impl_class}() {
82 }
83 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070084
85 // Accessors for OF message fields
Yotam Harcholf25e8142013-09-09 14:30:13 -070086 //:: include("_field_accessors.java", msg=msg, generate_setters=False, builder=False, has_parent=False)
Andreas Wundsam27303462013-07-16 12:52:35 -070087
Andreas Wundsambc679f72013-08-01 22:13:09 -070088 //:: if os.path.exists("%s/custom/%s.java" % (template_dir, msg.name)):
89 //:: include("custom/%s.java" % msg.name, msg=msg)
90 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070091
Andreas Wundsam99e931d2013-08-22 07:53:53 -070092 //:: if msg.data_members:
Andreas Wundsam5204de22013-07-30 11:34:45 -070093 public ${msg.interface.name}.Builder createBuilder() {
94 return new BuilderWithParent(this);
Andreas Wundsam27303462013-07-16 12:52:35 -070095 }
96
Andreas Wundsam5204de22013-07-30 11:34:45 -070097 static class BuilderWithParent implements ${msg.interface.name}.Builder {
Andreas Wundsam27303462013-07-16 12:52:35 -070098 final ${impl_class} parentMessage;
99
100 // OF message fields
101//:: for prop in msg.data_members:
102 private boolean ${prop.name}Set;
103 private ${prop.java_type.public_type} ${prop.name};
104//:: #endfor
105
Andreas Wundsam5204de22013-07-30 11:34:45 -0700106 BuilderWithParent(${impl_class} parentMessage) {
Andreas Wundsam27303462013-07-16 12:52:35 -0700107 this.parentMessage = parentMessage;
108 }
109
Yotam Harcholf25e8142013-09-09 14:30:13 -0700110//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=True)
Andreas Wundsam27303462013-07-16 12:52:35 -0700111
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700112
Andreas Wundsam27303462013-07-16 12:52:35 -0700113 @Override
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700114 public ${msg.interface.name} build() {
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700115 //:: for prop in msg.data_members:
116 ${prop.java_type.public_type} ${prop.name} = this.${prop.name}Set ? this.${prop.name} : parentMessage.${prop.name};
117 //:: if not prop.is_nullable and not prop.java_type.is_primitive:
118 if(${prop.name} == null)
119 throw new NullPointerException("Property ${prop.name} must not be null");
120 //:: #endif
121 //:: #endfor
122
123 //
124 //:: if os.path.exists("%s/custom/%s.Builder_normalize_stanza.java" % (template_dir, msg.name)):
125 //:: include("custom/%s.Builder_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
126 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700127 return new ${impl_class}(
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700128 //:: for i, prop in enumerate(msg.data_members):
129 //:: comma = "," if i < len(msg.data_members)-1 else ""
130 ${prop.name}${comma}
131 //:: #endfor
132 );
Andreas Wundsam27303462013-07-16 12:52:35 -0700133 }
Andreas Wundsambc679f72013-08-01 22:13:09 -0700134 //:: if os.path.exists("%s/custom/%s.Builder.java" % (template_dir, msg.name)):
Yotam Harchol98af7752013-08-22 14:59:38 -0700135 //:: include("custom/%s.Builder.java" % msg.name, msg=msg, has_parent=True)
Andreas Wundsambc679f72013-08-01 22:13:09 -0700136 //:: #endif
137
Andreas Wundsam27303462013-07-16 12:52:35 -0700138 }
139
Andreas Wundsam5204de22013-07-30 11:34:45 -0700140 static class Builder implements ${msg.interface.name}.Builder {
Andreas Wundsam27303462013-07-16 12:52:35 -0700141 // OF message fields
142//:: for prop in msg.data_members:
143 private boolean ${prop.name}Set;
144 private ${prop.java_type.public_type} ${prop.name};
145//:: #endfor
146
Yotam Harcholf25e8142013-09-09 14:30:13 -0700147//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=False)
Andreas Wundsam27303462013-07-16 12:52:35 -0700148//
149 @Override
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700150 public ${msg.interface.name} build() {
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700151 //:: for prop in msg.data_members:
152 //:: if prop.default_value:
153 ${prop.java_type.public_type} ${prop.name} = this.${prop.name}Set ? this.${prop.name} : ${prop.default_name};
154 //:: else:
155 if(!this.${prop.name}Set)
156 throw new IllegalStateException("Property ${prop.name} doesn't have default value -- must be set");
157 //:: #endif
158 //:: if not prop.is_nullable and not prop.java_type.is_primitive:
159 if(${prop.name} == null)
160 throw new NullPointerException("Property ${prop.name} must not be null");
161 //:: #endif
162 //:: #endfor
163
164 //:: if os.path.exists("%s/custom/%s.Builder_normalize_stanza.java" % (template_dir, msg.name)):
165 //:: include("custom/%s.Builder_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
166 //:: #endif
167
Andreas Wundsam27303462013-07-16 12:52:35 -0700168 return new ${impl_class}(
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700169 //:: for i, prop in enumerate(msg.data_members):
170 //:: comma = "," if i < len(msg.data_members)-1 else ""
171 ${prop.name}${comma}
172 //:: #endfor
Andreas Wundsam27303462013-07-16 12:52:35 -0700173 );
174 }
Andreas Wundsambc679f72013-08-01 22:13:09 -0700175 //:: if os.path.exists("%s/custom/%s.Builder.java" % (template_dir, msg.name)):
Yotam Harchol98af7752013-08-22 14:59:38 -0700176 //:: include("custom/%s.Builder.java" % msg.name, msg=msg, has_parent=False)
Andreas Wundsambc679f72013-08-01 22:13:09 -0700177 //:: #endif
178
Andreas Wundsam27303462013-07-16 12:52:35 -0700179 }
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700180 //:: else:
181 // no data members - do not support builder
182 public ${msg.interface.name}.Builder createBuilder() {
183 throw new UnsupportedOperationException("${impl_class} has no mutable properties -- builder unneeded");
184 }
185 //:: #endif
186
Andreas Wundsam27303462013-07-16 12:52:35 -0700187
188 final static Reader READER = new Reader();
189 static class Reader implements OFMessageReader<${msg.interface.name}> {
190 @Override
191 public ${msg.interface.name} readFrom(ChannelBuffer bb) throws OFParseError {
Yotam Harchola86e4252013-09-06 15:36:28 -0700192//:: for prop in msg.members:
193//:: if not prop.is_virtual and (prop.is_length_value or prop.is_field_length_value):
Andreas Wundsam001b1822013-08-02 22:25:55 -0700194 int start = bb.readerIndex();
Yotam Harchola86e4252013-09-06 15:36:28 -0700195//:: break
196//:: #endif
197//:: #endfor
Andreas Wundsam27303462013-07-16 12:52:35 -0700198//:: fields_with_length_member = {}
199//:: for prop in msg.members:
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700200//:: if prop.is_virtual:
201//:: continue
202//:: elif prop.is_data:
Andreas Wundsam001b1822013-08-02 22:25:55 -0700203 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True,
Andreas Wundsam27303462013-07-16 12:52:35 -0700204 length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
205//:: elif prop.is_pad:
206 // pad: ${prop.length} bytes
207 bb.skipBytes(${prop.length});
Andreas Wundsam27303462013-07-16 12:52:35 -0700208//:: elif prop.is_length_value:
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700209 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
210 //:: if prop.is_fixed_value:
211 if(${prop.name} != ${prop.value})
212 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
213 //:: else:
Andreas Wundsam27303462013-07-16 12:52:35 -0700214 if(${prop.name} < MINIMUM_LENGTH)
215 throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700216 //:: #endif
Yotam Harchol0178c202013-09-05 16:25:50 -0700217 if(bb.readableBytes() + (bb.readerIndex() - start) < ${prop.name}) {
218 // Buffer does not have all data yet
219 bb.readerIndex(start);
220 return null;
221 }
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700222 //:: if genopts.instrument:
223 if(OFInstrumentationOptions.TRACE_READS)
224 if(logger.isTraceEnabled())
225 logger.trace("readFrom - length={}", ${prop.name});
226 //:: #endif
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700227//:: elif prop.is_fixed_value:
228 // fixed value property ${prop.name} == ${prop.value}
229 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
230 if(${prop.name} != ${prop.priv_value})
231 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
232//:: elif prop.is_field_length_value:
233//:: fields_with_length_member[prop.member.field_name] = prop.name
234 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
235//:: else:
236 // fixme: todo ${prop.name}
Yotam Harchol0178c202013-09-05 16:25:50 -0700237//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700238//:: #endfor
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700239 //:: if msg.align:
Andreas Wundsam87bdcf42013-10-23 15:19:01 -0700240 //:: if msg.length_includes_align:
241 // align message to ${msg.align} bytes (length contains aligned value)
242 bb.skipBytes(length - (bb.readerIndex() - start));
243 //:: else:
244 // align message to ${msg.align} bytes (length does not contain alignment)
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700245 bb.skipBytes(((length + ${msg.align-1})/${msg.align} * ${msg.align} ) - length );
246 //:: #endif
Andreas Wundsam87bdcf42013-10-23 15:19:01 -0700247 //:: #endif
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700248
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700249 //:: if msg.data_members:
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700250 //:: if os.path.exists("%s/custom/%s.Reader_normalize_stanza.java" % (template_dir, msg.name)):
251 //:: include("custom/%s.Reader_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
252 //:: #endif
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700253 ${impl_class} ${msg.variable_name} = new ${impl_class}(
Andreas Wundsam27303462013-07-16 12:52:35 -0700254 ${",\n ".join(
255 [ prop.name for prop in msg.data_members])}
256 );
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700257 //:: if genopts.instrument:
258 if(OFInstrumentationOptions.TRACE_READS)
259 if(logger.isTraceEnabled())
260 logger.trace("readFrom - read={}", ${msg.variable_name});
261 //:: #endif
262 return ${msg.variable_name};
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700263 //:: else:
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700264 //:: if genopts.instrument:
265 if(OFInstrumentationOptions.TRACE_READS)
266 if(logger.isTraceEnabled())
267 logger.trace("readFrom - returning shared instance={}", INSTANCE);
268 //:: #endif
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700269 return INSTANCE;
270 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700271 }
272 }
273
Andreas Wundsam22ba3af2013-10-04 16:00:30 -0700274 public void putTo(PrimitiveSink sink) {
275 FUNNEL.funnel(this, sink);
276 }
277
278 final static ${impl_class}Funnel FUNNEL = new ${impl_class}Funnel();
279 static class ${impl_class}Funnel implements Funnel<${impl_class}> {
280 private static final long serialVersionUID = 1L;
281 @Override
282 public void funnel(${impl_class} message, PrimitiveSink sink) {
283//:: for prop in msg.members:
284//:: if prop.is_virtual:
285//:: continue
286//:: elif prop.is_data:
287 ${prop.java_type.funnel_op(version, "message." + prop.name, pub_type=True)};
288//:: elif prop.is_pad:
289 // skip pad (${prop.length} bytes)
290//:: elif prop.is_fixed_value:
291 // fixed value property ${prop.name} = ${prop.value}
292 ${prop.java_type.funnel_op(version, prop.priv_value, pub_type=False)};
293//:: else:
294 // FIXME: skip funnel of ${prop.name}
295//:: #endif
296//:: #endfor
297 }
298 }
299
300
Yotam Harchol5c9d6f42013-08-01 11:09:20 -0700301 public void writeTo(ChannelBuffer bb) {
302 WRITER.write(bb, this);
Andreas Wundsam27303462013-07-16 12:52:35 -0700303 }
304
305 final static Writer WRITER = new Writer();
306 static class Writer implements OFMessageWriter<${impl_class}> {
307 @Override
Andreas Wundsama94273b2013-08-01 22:11:33 -0700308 public void write(ChannelBuffer bb, ${impl_class} message) {
Yotam Harchola86e4252013-09-06 15:36:28 -0700309//:: if not msg.is_fixed_length:
Andreas Wundsam482f6d92013-07-24 16:10:21 -0700310 int startIndex = bb.writerIndex();
Yotam Harchola86e4252013-09-06 15:36:28 -0700311//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700312//:: fields_with_length_member = {}
313//:: for prop in msg.members:
314//:: if prop.c_name in fields_with_length_member:
315 int ${prop.name}StartIndex = bb.writerIndex();
316//:: #endif
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700317//:: if prop.is_virtual:
318//:: continue
319//:: elif prop.is_data:
Andreas Wundsam001b1822013-08-02 22:25:55 -0700320 ${prop.java_type.write_op(version, "message." + prop.name, pub_type=True)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700321//:: elif prop.is_pad:
322 // pad: ${prop.length} bytes
323 bb.writeZero(${prop.length});
324//:: elif prop.is_fixed_value:
325 // fixed value property ${prop.name} = ${prop.value}
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700326 ${prop.java_type.write_op(version, prop.priv_value, pub_type=False)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700327//:: elif prop.is_length_value:
328 // ${prop.name} is length of variable message, will be updated at the end
Andreas Wundsam001b1822013-08-02 22:25:55 -0700329//:: if not msg.is_fixed_length:
330 int lengthIndex = bb.writerIndex();
331//:: #end
Andreas Wundsam27303462013-07-16 12:52:35 -0700332 ${prop.java_type.write_op(version, 0)};
Andreas Wundsam001b1822013-08-02 22:25:55 -0700333
Andreas Wundsam27303462013-07-16 12:52:35 -0700334//:: elif prop.is_field_length_value:
335//:: fields_with_length_member[prop.member.field_name] = prop.name
336 // ${prop.name} is length indicator for ${prop.member.field_name}, will be
337 // udpated when ${prop.member.field_name} has been written
338 int ${prop.name}Index = bb.writerIndex();
Andreas Wundsam001b1822013-08-02 22:25:55 -0700339 ${prop.java_type.write_op(version, 0, pub_type=False)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700340//:: else:
341 // FIXME: todo write ${prop.name}
342//:: #endif
343//:: if prop.c_name in fields_with_length_member:
344//:: length_member_name = fields_with_length_member[prop.c_name]
345 // update field length member ${length_member_name}
346 int ${prop.name}Length = bb.writerIndex() - ${prop.name}StartIndex;
347 bb.setShort(${length_member_name}Index, ${prop.name}Length);
348//:: #endif
349//:: #endfor
350
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700351//:: if not msg.is_fixed_length:
Andreas Wundsam27303462013-07-16 12:52:35 -0700352 // update length field
353 int length = bb.writerIndex() - startIndex;
Andreas Wundsam5da68512013-10-22 22:18:00 -0700354 //:: if msg.align:
355 int alignedLength = ((length + ${msg.align-1})/${msg.align} * ${msg.align});
356 //:: #endif
357 bb.setShort(lengthIndex, ${"alignedLength" if msg.length_includes_align else "length"});
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700358 //:: if msg.align:
359 // align message to ${msg.align} bytes
Andreas Wundsam5da68512013-10-22 22:18:00 -0700360 bb.writeZero(alignedLength - length);
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700361 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700362//:: #end
363
364 }
365 }
366
Andreas Wundsameeefb552013-07-30 11:04:35 -0700367 @Override
Andreas Wundsamd7d5bb32013-07-30 12:26:31 -0700368 public String toString() {
369 StringBuilder b = new StringBuilder("${msg.name}(");
370 //:: for i, prop in enumerate(msg.data_members):
371 //:: if i > 0:
372 b.append(", ");
373 //:: #endif
374 b.append("${prop.name}=").append(${ "Arrays.toString(%s)" % prop.name if prop.java_type.is_array else prop.name });
375 //:: #endfor
376 b.append(")");
377 return b.toString();
378 }
379
380
381 @Override
Andreas Wundsameeefb552013-07-30 11:04:35 -0700382 public boolean equals(Object obj) {
383 if (this == obj)
384 return true;
385 if (obj == null)
386 return false;
387 if (getClass() != obj.getClass())
388 return false;
Yotam Harchola86e4252013-09-06 15:36:28 -0700389 //:: if len(msg.data_members) > 0:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700390 ${msg.name} other = (${msg.name}) obj;
Yotam Harchola86e4252013-09-06 15:36:28 -0700391 //:: #endif
Andreas Wundsameeefb552013-07-30 11:04:35 -0700392
393 //:: for prop in msg.data_members:
394 //:: if prop.java_type.is_primitive:
395 if( ${prop.name} != other.${prop.name})
396 return false;
397 //:: elif prop.java_type.is_array:
398 if (!Arrays.equals(${prop.name}, other.${prop.name}))
399 return false;
Andreas Wundsamd7d5bb32013-07-30 12:26:31 -0700400 //:: else:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700401 if (${prop.name} == null) {
402 if (other.${prop.name} != null)
403 return false;
404 } else if (!${prop.name}.equals(other.${prop.name}))
405 return false;
406 //:: #endif
407 //:: #endfor
408 return true;
409 }
410
411 @Override
412 public int hashCode() {
Yotam Harchola86e4252013-09-06 15:36:28 -0700413 //:: if len(msg.data_members) > 0:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700414 final int prime = 31;
Yotam Harchola86e4252013-09-06 15:36:28 -0700415 //:: #endif
Andreas Wundsameeefb552013-07-30 11:04:35 -0700416 int result = 1;
417
418 //:: for prop in msg.data_members:
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700419 //:: if prop.java_type.pub_type == 'long':
420 result = prime * (int) (${prop.name} ^ (${prop.name} >>> 32));
Rob Vaterlausfeee3712013-09-30 11:24:19 -0700421 //:: elif prop.java_type.pub_type == 'boolean':
422 result = prime * result + (${prop.name} ? 1231 : 1237);
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700423 //:: elif prop.java_type.is_primitive:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700424 result = prime * result + ${prop.name};
425 //:: elif prop.java_type.is_array:
426 result = prime * result + Arrays.hashCode(${prop.name});
427 //:: else:
428 result = prime * result + ((${prop.name} == null) ? 0 : ${prop.name}.hashCode());
429 //:: #endif
430 //:: #endfor
431 return result;
432 }
433
Andreas Wundsam27303462013-07-16 12:52:35 -0700434
435}