-
Notifications
You must be signed in to change notification settings - Fork 23
/
generated.html
617 lines (551 loc) · 57.5 KB
/
generated.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"-->
<link rel="stylesheet" href="/gfx/bootstrap.min.css">
<link rel="stylesheet" href="/gfx/main.css">
<link rel="stylesheet" href="/gfx/code.css">
<title>Generated code</title>
</head>
<body class="page">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-PMJSKV"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PMJSKV');</script>
<!-- End Google Tag Manager -->
<header>
<div class="container">
<a href="/">Immutables</a> ←
<h1>Generated code <iframe src="https://ghbtns.com/github-btn.html?user=immutables&repo=immutables&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
</h1>
</div>
</header>
<aside id="toc"></aside>
<section class="documentation">
<p>Here’s an illustration of the kind of code is generated by annotation processor.</p>
<p>Let’s start with minimal example. In the first example builder and copy methods are suppressed,
and there are no Guava or JSR-305 annotations libraries in the classpath.
<code class="language-plaintext highlighter-rouge">@Parameter</code> annotation is used to specify constructor parameters so that <a href="/immutable.html#constructor">constructor method</a> is generated.</p>
<h3 id="minimal-tuple">Minimal tuple</h3>
<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">org.immutables.value.Value</span><span class="o">;</span>
<span class="nd">@Value</span><span class="o">.</span><span class="na">Immutable</span><span class="o">(</span><span class="n">builder</span> <span class="o">=</span> <span class="kc">false</span><span class="o">,</span> <span class="n">copy</span> <span class="o">=</span> <span class="kc">false</span><span class="o">)</span>
<span class="kd">interface</span> <span class="nc">Tuple</span> <span class="o">{</span>
<span class="nd">@Value</span><span class="o">.</span><span class="na">Parameter</span> <span class="kt">int</span> <span class="nf">getIndex</span><span class="o">();</span>
<span class="nd">@Value</span><span class="o">.</span><span class="na">Parameter</span> <span class="nc">String</span> <span class="nf">getName</span><span class="o">();</span>
<span class="o">}</span>
</code></pre></div></div>
<p>The source code of the generated immutable implementation:</p>
<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">java.util.Objects</span><span class="o">;</span>
<span class="cm">/**
* Immutable implementation of {@link Tuple}.
* <p>
* Use the static factory method to create immutable instances:
* {@code ImmutableTuple.of()}.
*/</span>
<span class="nd">@SuppressWarnings</span><span class="o">(</span><span class="s">"all"</span><span class="o">)</span>
<span class="nd">@Immutable</span>
<span class="kd">final</span> <span class="kd">class</span> <span class="nc">ImmutableTuple</span> <span class="kd">implements</span> <span class="nc">Tuple</span> <span class="o">{</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">index</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="nc">String</span> <span class="n">name</span><span class="o">;</span>
<span class="kd">private</span> <span class="nf">ImmutableTuple</span><span class="o">(</span><span class="kt">int</span> <span class="n">index</span><span class="o">,</span> <span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">index</span> <span class="o">=</span> <span class="n">index</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="nc">Objects</span><span class="o">.</span><span class="na">requireNonNull</span><span class="o">(</span><span class="n">name</span><span class="o">,</span> <span class="s">"name"</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code index} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="nf">getIndex</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">index</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code name} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">String</span> <span class="nf">getName</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* This instance is equal to all instances of {@code ImmutableTuple} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">equals</span><span class="o">(</span><span class="nc">Object</span> <span class="n">another</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span> <span class="o">==</span> <span class="n">another</span><span class="o">)</span> <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">return</span> <span class="n">another</span> <span class="k">instanceof</span> <span class="nc">ImmutableTuple</span>
<span class="o">&&</span> <span class="n">equalTo</span><span class="o">((</span><span class="nc">ImmutableTuple</span><span class="o">)</span> <span class="n">another</span><span class="o">);</span>
<span class="o">}</span>
<span class="kd">private</span> <span class="kt">boolean</span> <span class="nf">equalTo</span><span class="o">(</span><span class="nc">ImmutableTuple</span> <span class="n">another</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">index</span> <span class="o">==</span> <span class="n">another</span><span class="o">.</span><span class="na">index</span>
<span class="o">&&</span> <span class="n">name</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">another</span><span class="o">.</span><span class="na">name</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Computes a hash code from attributes: {@code index}, {@code name}.
* @return hashCode value
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="nf">hashCode</span><span class="o">()</span> <span class="o">{</span>
<span class="kt">int</span> <span class="n">h</span> <span class="o">=</span> <span class="mi">31</span><span class="o">;</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="n">index</span><span class="o">;</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="n">name</span><span class="o">.</span><span class="na">hashCode</span><span class="o">();</span>
<span class="k">return</span> <span class="n">h</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Prints the immutable value {@code Tuple...} with all non-generated
* and non-auxiliary attribute values.
* @return A string representation of the value
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">String</span> <span class="nf">toString</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="s">"Tuple{"</span>
<span class="o">+</span> <span class="s">"index="</span> <span class="o">+</span> <span class="n">index</span>
<span class="o">+</span> <span class="s">", name="</span> <span class="o">+</span> <span class="n">name</span>
<span class="o">+</span> <span class="s">"}"</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Construct a new immutable {@code Tuple} instance.
* @param index The value for the {@code index} attribute
* @param name The value for the {@code name} attribute
* @return An immutable Tuple instance
*/</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="nc">ImmutableTuple</span> <span class="nf">of</span><span class="o">(</span><span class="kt">int</span> <span class="n">index</span><span class="o">,</span> <span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableTuple</span><span class="o">(</span><span class="n">index</span><span class="o">,</span> <span class="n">name</span><span class="o">);</span>
<span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>
<p>By default, extra code is generated. These extras can be disabled.
See the <a href="/style.html">Style guide</a> for examples of how this can be configured on package or using meta-annotations.</p>
<h3 id="typical-value-object">Typical value object</h3>
<p>Here’s a more typical example of a value object with a builder and copy methods. Google Guava is present in classpath.</p>
<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">com.google.common.base.Optional</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">java.util.List</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.immutables.value.Value</span><span class="o">;</span>
<span class="nd">@Value</span><span class="o">.</span><span class="na">Immutable</span>
<span class="kd">interface</span> <span class="nc">ValueObject</span> <span class="o">{</span>
<span class="kt">long</span> <span class="nf">id</span><span class="o">();</span>
<span class="nc">String</span> <span class="nf">name</span><span class="o">();</span>
<span class="nc">List</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="nf">numbers</span><span class="o">();</span>
<span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="nf">comment</span><span class="o">();</span>
<span class="kt">long</span><span class="o">[]</span> <span class="nf">data</span><span class="o">();</span>
<span class="o">}</span>
</code></pre></div></div>
<p>You will probably agree that the code below would have been painful to write by hand:</p>
<div class="language-java highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">com.google.common.base.MoreObjects</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.google.common.base.Optional</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.google.common.base.Preconditions</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.google.common.collect.ImmutableList</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.google.common.collect.Lists</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.google.common.primitives.Longs</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">java.util.Arrays</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">java.util.List</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">javax.annotation.Generated</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">javax.annotation.Nullable</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">javax.annotation.ParametersAreNonnullByDefault</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">javax.annotation.concurrent.Immutable</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">javax.annotation.concurrent.NotThreadSafe</span><span class="o">;</span>
<span class="cm">/**
* Immutable implementation of {@link ValueObject}.
* <p>
* Use the builder to create immutable instances:
* {@code ImmutableValueObject.builder()}.
*/</span>
<span class="nd">@SuppressWarnings</span><span class="o">(</span><span class="s">"all"</span><span class="o">)</span>
<span class="nd">@ParametersAreNonnullByDefault</span>
<span class="nd">@Generated</span><span class="o">({</span><span class="s">"Immutables.generator"</span><span class="o">,</span> <span class="s">"ValueObject"</span><span class="o">})</span>
<span class="nd">@Immutable</span>
<span class="kd">final</span> <span class="kd">class</span> <span class="nc">ImmutableValueObject</span> <span class="kd">implements</span> <span class="nc">ValueObject</span> <span class="o">{</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="kt">long</span> <span class="n">id</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="nc">String</span> <span class="n">name</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="nc">ImmutableList</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="n">numbers</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">comment</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">final</span> <span class="kt">long</span><span class="o">[]</span> <span class="n">data</span><span class="o">;</span>
<span class="kd">private</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span>
<span class="kt">long</span> <span class="n">id</span><span class="o">,</span>
<span class="nc">String</span> <span class="n">name</span><span class="o">,</span>
<span class="nc">ImmutableList</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="n">numbers</span><span class="o">,</span>
<span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">comment</span><span class="o">,</span>
<span class="kt">long</span><span class="o">[]</span> <span class="n">data</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">id</span> <span class="o">=</span> <span class="n">id</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">numbers</span> <span class="o">=</span> <span class="n">numbers</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">comment</span> <span class="o">=</span> <span class="n">comment</span><span class="o">;</span>
<span class="k">this</span><span class="o">.</span><span class="na">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code id} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">long</span> <span class="nf">id</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">id</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code name} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">String</span> <span class="nf">name</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">name</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code numbers} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">ImmutableList</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="nf">numbers</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">numbers</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return The value of the {@code comment} attribute
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="nf">comment</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">comment</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* @return A cloned {@code data} array
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">long</span><span class="o">[]</span> <span class="nf">data</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">data</span><span class="o">.</span><span class="na">clone</span><span class="o">();</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object by setting a value for the {@link ValueObject#id() id} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id
* @return A modified copy of the {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withId</span><span class="o">(</span><span class="kt">long</span> <span class="n">value</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span> <span class="o">==</span> <span class="n">value</span><span class="o">)</span> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="n">value</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">numbers</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">comment</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object by setting a value for the {@link ValueObject#name() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withName</span><span class="o">(</span><span class="nc">String</span> <span class="n">value</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">value</span><span class="o">))</span> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span>
<span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span>
<span class="nc">Preconditions</span><span class="o">.</span><span class="na">checkNotNull</span><span class="o">(</span><span class="n">value</span><span class="o">,</span> <span class="s">"name"</span><span class="o">),</span>
<span class="k">this</span><span class="o">.</span><span class="na">numbers</span><span class="o">,</span>
<span class="k">this</span><span class="o">.</span><span class="na">comment</span><span class="o">,</span>
<span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object with elements that replace the content of {@link ValueObject#numbers() numbers}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withNumbers</span><span class="o">(</span><span class="nc">Number</span><span class="o">...</span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="nc">ImmutableList</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="n">newValue</span> <span class="o">=</span> <span class="nc">ImmutableList</span><span class="o">.</span><span class="na">copyOf</span><span class="o">(</span><span class="n">elements</span><span class="o">);</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="n">newValue</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">comment</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object with elements that replace the content of {@link ValueObject#numbers() numbers}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of numbers elements to set
* @return A modified copy of {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withNumbers</span><span class="o">(</span><span class="nc">Iterable</span><span class="o"><?</span> <span class="kd">extends</span> <span class="nc">Number</span><span class="o">></span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">numbers</span> <span class="o">==</span> <span class="n">elements</span><span class="o">)</span> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="nc">ImmutableList</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="n">newValue</span> <span class="o">=</span> <span class="nc">ImmutableList</span><span class="o">.</span><span class="na">copyOf</span><span class="o">(</span><span class="n">elements</span><span class="o">);</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="n">newValue</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">comment</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object by setting a <i>present</i> value for the optional {@link ValueObject#comment() comment} attribute.
* @param value The value for comment
* @return A modified copy of {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withComment</span><span class="o">(</span><span class="nc">String</span> <span class="n">value</span><span class="o">)</span> <span class="o">{</span>
<span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">newValue</span> <span class="o">=</span> <span class="nc">Optional</span><span class="o">.</span><span class="na">of</span><span class="o">(</span><span class="n">value</span><span class="o">);</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">numbers</span><span class="o">,</span> <span class="n">newValue</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object by setting an optional value for the {@link ValueObject#comment() comment} attribute.
* A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
* @param optional A value for comment
* @return A modified copy of {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withComment</span><span class="o">(</span><span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">optional</span><span class="o">)</span> <span class="o">{</span>
<span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">value</span> <span class="o">=</span> <span class="nc">Preconditions</span><span class="o">.</span><span class="na">checkNotNull</span><span class="o">(</span><span class="n">optional</span><span class="o">,</span> <span class="s">"comment"</span><span class="o">);</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">comment</span> <span class="o">==</span> <span class="n">value</span><span class="o">)</span> <span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">numbers</span><span class="o">,</span> <span class="n">value</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Copy the current immutable object with elements that replace the content of {@link ValueObject#data() data}.
* The array is cloned before being saved as attribute values.
* @param elements The non-null elements for data
* @return A modified copy of {@code this} object
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">ImmutableValueObject</span> <span class="nf">withData</span><span class="o">(</span><span class="kt">long</span><span class="o">...</span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="kt">long</span><span class="o">[]</span> <span class="n">newValue</span> <span class="o">=</span> <span class="n">elements</span><span class="o">.</span><span class="na">clone</span><span class="o">();</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="k">this</span><span class="o">.</span><span class="na">id</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">name</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">numbers</span><span class="o">,</span> <span class="k">this</span><span class="o">.</span><span class="na">comment</span><span class="o">,</span> <span class="n">newValue</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* This instance is equal to all instances of {@code ImmutableValueObject} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">equals</span><span class="o">(</span><span class="nd">@Nullable</span> <span class="nc">Object</span> <span class="n">another</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="k">this</span> <span class="o">==</span> <span class="n">another</span><span class="o">)</span> <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
<span class="k">return</span> <span class="n">another</span> <span class="k">instanceof</span> <span class="nc">ImmutableValueObject</span>
<span class="o">&&</span> <span class="n">equalTo</span><span class="o">((</span><span class="nc">ImmutableValueObject</span><span class="o">)</span> <span class="n">another</span><span class="o">);</span>
<span class="o">}</span>
<span class="kd">private</span> <span class="kt">boolean</span> <span class="nf">equalTo</span><span class="o">(</span><span class="nc">ImmutableValueObject</span> <span class="n">another</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="n">id</span> <span class="o">==</span> <span class="n">another</span><span class="o">.</span><span class="na">id</span>
<span class="o">&&</span> <span class="n">name</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">another</span><span class="o">.</span><span class="na">name</span><span class="o">)</span>
<span class="o">&&</span> <span class="n">numbers</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">another</span><span class="o">.</span><span class="na">numbers</span><span class="o">)</span>
<span class="o">&&</span> <span class="n">comment</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">another</span><span class="o">.</span><span class="na">comment</span><span class="o">)</span>
<span class="o">&&</span> <span class="nc">Arrays</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">data</span><span class="o">,</span> <span class="n">another</span><span class="o">.</span><span class="na">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Computes a hash code from attributes: {@code id}, {@code name}, {@code numbers}, {@code comment}, {@code data}.
* @return hashCode value
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="kt">int</span> <span class="nf">hashCode</span><span class="o">()</span> <span class="o">{</span>
<span class="kt">int</span> <span class="n">h</span> <span class="o">=</span> <span class="mi">31</span><span class="o">;</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="nc">Longs</span><span class="o">.</span><span class="na">hashCode</span><span class="o">(</span><span class="n">id</span><span class="o">);</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="n">name</span><span class="o">.</span><span class="na">hashCode</span><span class="o">();</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="n">numbers</span><span class="o">.</span><span class="na">hashCode</span><span class="o">();</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="n">comment</span><span class="o">.</span><span class="na">hashCode</span><span class="o">();</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">h</span> <span class="o">*</span> <span class="mi">17</span> <span class="o">+</span> <span class="nc">Arrays</span><span class="o">.</span><span class="na">hashCode</span><span class="o">(</span><span class="n">data</span><span class="o">);</span>
<span class="k">return</span> <span class="n">h</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Prints the immutable value {@code ValueObject...} with all non-generated
* and non-auxiliary attribute values.
* @return A string representation of the value
*/</span>
<span class="nd">@Override</span>
<span class="kd">public</span> <span class="nc">String</span> <span class="nf">toString</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="nc">MoreObjects</span><span class="o">.</span><span class="na">toStringHelper</span><span class="o">(</span><span class="s">"ValueObject"</span><span class="o">)</span>
<span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"id"</span><span class="o">,</span> <span class="n">id</span><span class="o">)</span>
<span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"name"</span><span class="o">,</span> <span class="n">name</span><span class="o">)</span>
<span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"numbers"</span><span class="o">,</span> <span class="n">numbers</span><span class="o">)</span>
<span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"comment"</span><span class="o">,</span> <span class="n">comment</span><span class="o">)</span>
<span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"data"</span><span class="o">,</span> <span class="nc">Arrays</span><span class="o">.</span><span class="na">toString</span><span class="o">(</span><span class="n">data</span><span class="o">))</span>
<span class="o">.</span><span class="na">toString</span><span class="o">();</span>
<span class="o">}</span>
<span class="cm">/**
* Creates an immutable copy of a {@link ValueObject} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable ValueObject instance
*/</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="nc">ImmutableValueObject</span> <span class="nf">copyOf</span><span class="o">(</span><span class="nc">ValueObject</span> <span class="n">instance</span><span class="o">)</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="n">instance</span> <span class="k">instanceof</span> <span class="nc">ImmutableValueObject</span><span class="o">)</span> <span class="o">{</span>
<span class="k">return</span> <span class="o">(</span><span class="nc">ImmutableValueObject</span><span class="o">)</span> <span class="n">instance</span><span class="o">;</span>
<span class="o">}</span>
<span class="k">return</span> <span class="nc">ImmutableValueObject</span><span class="o">.</span><span class="na">builder</span><span class="o">()</span>
<span class="o">.</span><span class="na">from</span><span class="o">(</span><span class="n">instance</span><span class="o">)</span>
<span class="o">.</span><span class="na">build</span><span class="o">();</span>
<span class="o">}</span>
<span class="cm">/**
* Creates a builder for {@link ImmutableValueObject ImmutableValueObject}.
* @return A new ImmutableValueObject builder
*/</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="nc">ImmutableValueObject</span><span class="o">.</span><span class="na">Builder</span> <span class="nf">builder</span><span class="o">()</span> <span class="o">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nc">ImmutableValueObject</span><span class="o">.</span><span class="na">Builder</span><span class="o">();</span>
<span class="o">}</span>
<span class="cm">/**
* Builds instances of type {@link ImmutableValueObject ImmutableValueObject}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.</em>
*/</span>
<span class="nd">@NotThreadSafe</span>
<span class="kd">static</span> <span class="kd">final</span> <span class="kd">class</span> <span class="nc">Builder</span> <span class="o">{</span>
<span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">long</span> <span class="no">INIT_BIT_ID</span> <span class="o">=</span> <span class="mh">0x1</span><span class="no">L</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">long</span> <span class="no">INIT_BIT_NAME</span> <span class="o">=</span> <span class="mh">0x2</span><span class="no">L</span><span class="o">;</span>
<span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">long</span> <span class="no">INIT_BIT_DATA</span> <span class="o">=</span> <span class="mh">0x4</span><span class="no">L</span><span class="o">;</span>
<span class="kd">private</span> <span class="kt">long</span> <span class="n">initBits</span> <span class="o">=</span> <span class="mh">0x7</span><span class="o">;</span>
<span class="kd">private</span> <span class="kt">long</span> <span class="n">id</span><span class="o">;</span>
<span class="kd">private</span> <span class="nd">@Nullable</span> <span class="nc">String</span> <span class="n">name</span><span class="o">;</span>
<span class="kd">private</span> <span class="nc">ImmutableList</span><span class="o">.</span><span class="na">Builder</span><span class="o"><</span><span class="nc">Number</span><span class="o">></span> <span class="n">numbersBuilder</span> <span class="o">=</span> <span class="nc">ImmutableList</span><span class="o">.</span><span class="na">builder</span><span class="o">();</span>
<span class="kd">private</span> <span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">comment</span> <span class="o">=</span> <span class="nc">Optional</span><span class="o">.</span><span class="na">absent</span><span class="o">();</span>
<span class="kd">private</span> <span class="nd">@Nullable</span> <span class="kt">long</span><span class="o">[]</span> <span class="n">data</span><span class="o">;</span>
<span class="kd">private</span> <span class="nf">Builder</span><span class="o">()</span> <span class="o">{</span>
<span class="o">}</span>
<span class="cm">/**
* Fill a builder with attribute values from the provided {@code ValueObject} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">from</span><span class="o">(</span><span class="nc">ValueObject</span> <span class="n">instance</span><span class="o">)</span> <span class="o">{</span>
<span class="nc">Preconditions</span><span class="o">.</span><span class="na">checkNotNull</span><span class="o">(</span><span class="n">instance</span><span class="o">,</span> <span class="s">"instance"</span><span class="o">);</span>
<span class="n">id</span><span class="o">(</span><span class="n">instance</span><span class="o">.</span><span class="na">id</span><span class="o">());</span>
<span class="n">name</span><span class="o">(</span><span class="n">instance</span><span class="o">.</span><span class="na">name</span><span class="o">());</span>
<span class="n">addAllNumbers</span><span class="o">(</span><span class="n">instance</span><span class="o">.</span><span class="na">numbers</span><span class="o">());</span>
<span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">commentOptional</span> <span class="o">=</span> <span class="n">instance</span><span class="o">.</span><span class="na">comment</span><span class="o">();</span>
<span class="k">if</span> <span class="o">(</span><span class="n">commentOptional</span><span class="o">.</span><span class="na">isPresent</span><span class="o">())</span> <span class="o">{</span>
<span class="n">comment</span><span class="o">(</span><span class="n">commentOptional</span><span class="o">);</span>
<span class="o">}</span>
<span class="n">data</span><span class="o">(</span><span class="n">instance</span><span class="o">.</span><span class="na">data</span><span class="o">());</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Initializes the value for the {@link ValueObject#id() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">id</span><span class="o">(</span><span class="kt">long</span> <span class="n">id</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">id</span> <span class="o">=</span> <span class="n">id</span><span class="o">;</span>
<span class="n">initBits</span> <span class="o">&=</span> <span class="o">~</span><span class="no">INIT_BIT_ID</span><span class="o">;</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Initializes the value for the {@link ValueObject#name() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">name</span><span class="o">(</span><span class="nc">String</span> <span class="n">name</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">name</span> <span class="o">=</span> <span class="nc">Preconditions</span><span class="o">.</span><span class="na">checkNotNull</span><span class="o">(</span><span class="n">name</span><span class="o">,</span> <span class="s">"name"</span><span class="o">);</span>
<span class="n">initBits</span> <span class="o">&=</span> <span class="o">~</span><span class="no">INIT_BIT_NAME</span><span class="o">;</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Adds one element to {@link ValueObject#numbers() numbers} list.
* @param element A numbers element
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">addNumbers</span><span class="o">(</span><span class="nc">Number</span> <span class="n">element</span><span class="o">)</span> <span class="o">{</span>
<span class="n">numbersBuilder</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">element</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Adds elements to {@link ValueObject#numbers() numbers} list.
* @param elements An array of numbers elements
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">addNumbers</span><span class="o">(</span><span class="nc">Number</span><span class="o">...</span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="n">numbersBuilder</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">elements</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Sets or replaces all elements for {@link ValueObject#numbers() numbers} list.
* @param elements An iterable of numbers elements
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">numbers</span><span class="o">(</span><span class="nc">Iterable</span><span class="o"><?</span> <span class="kd">extends</span> <span class="nc">Number</span><span class="o">></span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="n">numbersBuilder</span> <span class="o">=</span> <span class="nc">ImmutableList</span><span class="o">.</span><span class="na">builder</span><span class="o">();</span>
<span class="k">return</span> <span class="nf">addAllNumbers</span><span class="o">(</span><span class="n">elements</span><span class="o">);</span>
<span class="o">}</span>
<span class="cm">/**
* Adds elements to {@link ValueObject#numbers() numbers} list.
* @param elements An iterable of numbers elements
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">addAllNumbers</span><span class="o">(</span><span class="nc">Iterable</span><span class="o"><?</span> <span class="kd">extends</span> <span class="nc">Number</span><span class="o">></span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="n">numbersBuilder</span><span class="o">.</span><span class="na">addAll</span><span class="o">(</span><span class="n">elements</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Initializes the optional value {@link ValueObject#comment() comment} to comment.
* @param comment The value for comment
* @return {@code this} builder for chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">comment</span><span class="o">(</span><span class="nc">String</span> <span class="n">comment</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">comment</span> <span class="o">=</span> <span class="nc">Optional</span><span class="o">.</span><span class="na">of</span><span class="o">(</span><span class="n">comment</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Initializes the optional value {@link ValueObject#comment() comment} to comment.
* @param comment The value for comment
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">comment</span><span class="o">(</span><span class="nc">Optional</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">comment</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">comment</span> <span class="o">=</span> <span class="nc">Preconditions</span><span class="o">.</span><span class="na">checkNotNull</span><span class="o">(</span><span class="n">comment</span><span class="o">,</span> <span class="s">"comment"</span><span class="o">);</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Initializes the value for the {@link ValueObject#data() data} attribute.
* @param elements The elements for data
* @return {@code this} builder for use in a chained invocation
*/</span>
<span class="kd">public</span> <span class="kd">final</span> <span class="nc">Builder</span> <span class="nf">data</span><span class="o">(</span><span class="kt">long</span><span class="o">...</span> <span class="n">elements</span><span class="o">)</span> <span class="o">{</span>
<span class="k">this</span><span class="o">.</span><span class="na">data</span> <span class="o">=</span> <span class="n">elements</span><span class="o">.</span><span class="na">clone</span><span class="o">();</span>
<span class="n">initBits</span> <span class="o">&=</span> <span class="o">~</span><span class="no">INIT_BIT_DATA</span><span class="o">;</span>
<span class="k">return</span> <span class="k">this</span><span class="o">;</span>
<span class="o">}</span>
<span class="cm">/**
* Builds a new {@link ImmutableValueObject ImmutableValueObject}.
* @return An immutable instance of ValueObject
* @throws java.lang.IllegalStateException if any required attributes are missing
*/</span>
<span class="kd">public</span> <span class="nc">ImmutableValueObject</span> <span class="nf">build</span><span class="o">()</span> <span class="kd">throws</span> <span class="nc">IllegalStateException</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">(</span><span class="n">initBits</span> <span class="o">!=</span> <span class="mi">0</span><span class="o">)</span> <span class="o">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nf">IllegalStateException</span><span class="o">(</span><span class="n">formatRequiredAttributesMessage</span><span class="o">());</span>
<span class="o">}</span>
<span class="k">return</span> <span class="k">new</span> <span class="nf">ImmutableValueObject</span><span class="o">(</span><span class="n">id</span><span class="o">,</span> <span class="n">name</span><span class="o">,</span> <span class="n">numbersBuilder</span><span class="o">.</span><span class="na">build</span><span class="o">(),</span> <span class="n">comment</span><span class="o">,</span> <span class="n">data</span><span class="o">);</span>
<span class="o">}</span>
<span class="kd">private</span> <span class="nc">String</span> <span class="nf">formatRequiredAttributesMessage</span><span class="o">()</span> <span class="o">{</span>
<span class="nc">List</span><span class="o"><</span><span class="nc">String</span><span class="o">></span> <span class="n">attributes</span> <span class="o">=</span> <span class="nc">Lists</span><span class="o">.</span><span class="na">newArrayList</span><span class="o">();</span>
<span class="k">if</span> <span class="o">((</span><span class="n">initBits</span> <span class="o">&</span> <span class="no">INIT_BIT_ID</span><span class="o">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="o">)</span> <span class="n">attributes</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"id"</span><span class="o">);</span>
<span class="k">if</span> <span class="o">((</span><span class="n">initBits</span> <span class="o">&</span> <span class="no">INIT_BIT_NAME</span><span class="o">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="o">)</span> <span class="n">attributes</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"name"</span><span class="o">);</span>
<span class="k">if</span> <span class="o">((</span><span class="n">initBits</span> <span class="o">&</span> <span class="no">INIT_BIT_DATA</span><span class="o">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="o">)</span> <span class="n">attributes</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">"data"</span><span class="o">);</span>
<span class="k">return</span> <span class="s">"Cannot build ValueObject, some of required attributes are not set "</span> <span class="o">+</span> <span class="n">attributes</span><span class="o">;</span>
<span class="o">}</span>
<span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>
</section>
<footer class="jumbotron">
<div class="container">
<h2 id="guides">Guides</h2>
<ul>
<li><a href="/getstarted.html">Get started!</a></li>
<li><a href="/intro.html">Inception</a></li>
<li><a href="/immutable.html">Immutable objects</a></li>
<li><a href="/factory.html">Factory builders</a></li>
<li><a href="/functional.html">Functions and Predicates (for Java 7)</a></li>
<li><a href="/style.html">Style customization</a></li>
<li><a href="/json.html">JSON serialization</a></li>
<li><a href="/criteria.html">Criteria</a></li>
<li><a href="/mongo.html">MongoDB repositories</a></li>
<li><a href="/dynamodb.html">DynamoDB integration</a></li>
<li><a href="/encoding.html">Encoding: Customizing attributes and builders (experimental)</a></li>
<li><a href="/apt.html">Using annotation processor in IDE</a></li>
</ul>
<h2 id="get-involved">Get involved</h2>
<ul>
<li>Clone source repository, contribute bug reports and fixes on <a href="https://github.com/immutables/immutables">GitHub immutables/immutables</a></li>
<li>Issue reports, questions and feedback is welcome on issue tracker <a href="https://github.com/immutables/immutables/issues">GitHub immutables/immutables/issues</a></li>
<li>News and announcements on twitter <a href="https://twitter.com/ImmutablesOrg">@ImmutablesOrg</a></li>
</ul>
<p><a href="/license.html">Apache License 2.0</a></p>
<!--<div><h2>Posts</h2>
<ul>
</ul>
</div>-->
</div>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script defer src="/gfx/jquery.toc.min.js"></script>
<script>
$(function() {
$('#toc').toc({
container: '.documentation',
selectors: 'h1,h2,h3,h4',
anchorName: function(i, heading, prefix) {
heading = $(heading).text();
if (heading.trim) heading = heading.trim();
return heading.toLowerCase().replace(/ /g, '-').replace(/[^a-z^\-]+/g, '');
},
})
})
</script>
</body>
</html>