@@ -83,56 +83,6 @@ else if ( integralType == BigDecimal.class ) {
83
83
}
84
84
}
85
85
86
- public static long extractLong (IntegralDataTypeHolder holder ) {
87
- if ( holder .getClass () == BasicHolder .class ) {
88
- ( (BasicHolder ) holder ).checkInitialized ();
89
- return ( (BasicHolder ) holder ).value ;
90
- }
91
- else if ( holder .getClass () == BigIntegerHolder .class ) {
92
- ( (BigIntegerHolder ) holder ).checkInitialized ();
93
- return ( (BigIntegerHolder ) holder ).value .longValue ();
94
- }
95
- else if ( holder .getClass () == BigDecimalHolder .class ) {
96
- ( (BigDecimalHolder ) holder ).checkInitialized ();
97
- return ( (BigDecimalHolder ) holder ).value .longValue ();
98
- }
99
- throw new IdentifierGenerationException ( "Unknown IntegralDataTypeHolder impl [" + holder + "]" );
100
- }
101
-
102
- public static BigInteger extractBigInteger (IntegralDataTypeHolder holder ) {
103
- if ( holder .getClass () == BasicHolder .class ) {
104
- ( (BasicHolder ) holder ).checkInitialized ();
105
- return BigInteger .valueOf ( ( (BasicHolder ) holder ).value );
106
- }
107
- else if ( holder .getClass () == BigIntegerHolder .class ) {
108
- ( (BigIntegerHolder ) holder ).checkInitialized ();
109
- return ( (BigIntegerHolder ) holder ).value ;
110
- }
111
- else if ( holder .getClass () == BigDecimalHolder .class ) {
112
- ( (BigDecimalHolder ) holder ).checkInitialized ();
113
- // scale should already be set...
114
- return ( (BigDecimalHolder ) holder ).value .toBigInteger ();
115
- }
116
- throw new IdentifierGenerationException ( "Unknown IntegralDataTypeHolder impl [" + holder + "]" );
117
- }
118
-
119
- public static BigDecimal extractBigDecimal (IntegralDataTypeHolder holder ) {
120
- if ( holder .getClass () == BasicHolder .class ) {
121
- ( (BasicHolder ) holder ).checkInitialized ();
122
- return BigDecimal .valueOf ( ( (BasicHolder ) holder ).value );
123
- }
124
- else if ( holder .getClass () == BigIntegerHolder .class ) {
125
- ( (BigIntegerHolder ) holder ).checkInitialized ();
126
- return new BigDecimal ( ( (BigIntegerHolder ) holder ).value );
127
- }
128
- else if ( holder .getClass () == BigDecimalHolder .class ) {
129
- ( (BigDecimalHolder ) holder ).checkInitialized ();
130
- // scale should already be set...
131
- return ( (BigDecimalHolder ) holder ).value ;
132
- }
133
- throw new IdentifierGenerationException ( "Unknown IntegralDataTypeHolder impl [" + holder + "]" );
134
- }
135
-
136
86
public static Object getForeignId (
137
87
String entityName , String propertyName , SharedSessionContractImplementor sessionImplementor , Object object ) {
138
88
final EntityPersister entityDescriptor =
@@ -261,7 +211,7 @@ public IntegralDataTypeHolder subtract(long subtrahend) {
261
211
}
262
212
263
213
public IntegralDataTypeHolder multiplyBy (IntegralDataTypeHolder factor ) {
264
- return multiplyBy ( extractLong ( factor ) );
214
+ return multiplyBy ( factor . toLong ( ) );
265
215
}
266
216
267
217
public IntegralDataTypeHolder multiplyBy (long factor ) {
@@ -271,7 +221,7 @@ public IntegralDataTypeHolder multiplyBy(long factor) {
271
221
}
272
222
273
223
public boolean eq (IntegralDataTypeHolder other ) {
274
- return eq ( extractLong ( other ) );
224
+ return eq ( other . toLong ( ) );
275
225
}
276
226
277
227
public boolean eq (long value ) {
@@ -280,7 +230,7 @@ public boolean eq(long value) {
280
230
}
281
231
282
232
public boolean lt (IntegralDataTypeHolder other ) {
283
- return lt ( extractLong ( other ) );
233
+ return lt ( other . toLong ( ) );
284
234
}
285
235
286
236
public boolean lt (long value ) {
@@ -289,7 +239,7 @@ public boolean lt(long value) {
289
239
}
290
240
291
241
public boolean gt (IntegralDataTypeHolder other ) {
292
- return gt ( extractLong ( other ) );
242
+ return gt ( other . toLong ( ) );
293
243
}
294
244
295
245
public boolean gt (long value ) {
@@ -329,6 +279,24 @@ public Number makeValueThenAdd(long addend) {
329
279
return result ;
330
280
}
331
281
282
+ @ Override
283
+ public long toLong () {
284
+ checkInitialized ();
285
+ return value ;
286
+ }
287
+
288
+ @ Override
289
+ public BigDecimal toBigDecimal () {
290
+ checkInitialized ();
291
+ return BigDecimal .valueOf ( value );
292
+ }
293
+
294
+ @ Override
295
+ public BigInteger toBigInteger () {
296
+ checkInitialized ();
297
+ return BigInteger .valueOf ( value );
298
+ }
299
+
332
300
@ Override
333
301
public String toString () {
334
302
return "BasicHolder[" + exactType .getName () + "[" + value + "]]" ;
@@ -339,12 +307,9 @@ public boolean equals(Object o) {
339
307
if ( this == o ) {
340
308
return true ;
341
309
}
342
- if ( o == null || getClass () != o . getClass ( ) ) {
310
+ if ( !( o instanceof BasicHolder that ) ) {
343
311
return false ;
344
312
}
345
-
346
- BasicHolder that = (BasicHolder ) o ;
347
-
348
313
return value == that .value ;
349
314
}
350
315
@@ -407,7 +372,7 @@ public IntegralDataTypeHolder subtract(long subtrahend) {
407
372
408
373
public IntegralDataTypeHolder multiplyBy (IntegralDataTypeHolder factor ) {
409
374
checkInitialized ();
410
- value = value .multiply ( extractBigInteger ( factor ) );
375
+ value = value .multiply ( factor . toBigInteger ( ) );
411
376
return this ;
412
377
}
413
378
@@ -419,7 +384,7 @@ public IntegralDataTypeHolder multiplyBy(long factor) {
419
384
420
385
public boolean eq (IntegralDataTypeHolder other ) {
421
386
checkInitialized ();
422
- return value .compareTo ( extractBigInteger ( other ) ) == 0 ;
387
+ return value .compareTo ( other . toBigInteger ( ) ) == 0 ;
423
388
}
424
389
425
390
public boolean eq (long value ) {
@@ -429,7 +394,7 @@ public boolean eq(long value) {
429
394
430
395
public boolean lt (IntegralDataTypeHolder other ) {
431
396
checkInitialized ();
432
- return value .compareTo ( extractBigInteger ( other ) ) < 0 ;
397
+ return value .compareTo ( other . toBigInteger ( ) ) < 0 ;
433
398
}
434
399
435
400
public boolean lt (long value ) {
@@ -439,7 +404,7 @@ public boolean lt(long value) {
439
404
440
405
public boolean gt (IntegralDataTypeHolder other ) {
441
406
checkInitialized ();
442
- return value .compareTo ( extractBigInteger ( other ) ) > 0 ;
407
+ return value .compareTo ( other . toBigInteger ( ) ) > 0 ;
443
408
}
444
409
445
410
public boolean gt (long value ) {
@@ -470,6 +435,24 @@ public Number makeValueThenAdd(long addend) {
470
435
return result ;
471
436
}
472
437
438
+ @ Override
439
+ public long toLong () {
440
+ checkInitialized ();
441
+ return value .longValue ();
442
+ }
443
+
444
+ @ Override
445
+ public BigInteger toBigInteger () {
446
+ checkInitialized ();
447
+ return value ;
448
+ }
449
+
450
+ @ Override
451
+ public BigDecimal toBigDecimal () {
452
+ checkInitialized ();
453
+ return new BigDecimal ( value );
454
+ }
455
+
473
456
@ Override
474
457
public String toString () {
475
458
return "BigIntegerHolder[" + value + "]" ;
@@ -480,12 +463,9 @@ public boolean equals(Object o) {
480
463
if ( this == o ) {
481
464
return true ;
482
465
}
483
- if ( o == null || getClass () != o . getClass ( ) ) {
466
+ if ( !( o instanceof BigIntegerHolder that ) ) {
484
467
return false ;
485
468
}
486
-
487
- BigIntegerHolder that = (BigIntegerHolder ) o ;
488
-
489
469
return Objects .equals ( value , that .value );
490
470
}
491
471
@@ -548,7 +528,7 @@ public IntegralDataTypeHolder subtract(long subtrahend) {
548
528
549
529
public IntegralDataTypeHolder multiplyBy (IntegralDataTypeHolder factor ) {
550
530
checkInitialized ();
551
- value = value .multiply ( extractBigDecimal ( factor ) );
531
+ value = value .multiply ( factor . toBigDecimal ( ) );
552
532
return this ;
553
533
}
554
534
@@ -560,7 +540,7 @@ public IntegralDataTypeHolder multiplyBy(long factor) {
560
540
561
541
public boolean eq (IntegralDataTypeHolder other ) {
562
542
checkInitialized ();
563
- return value .compareTo ( extractBigDecimal ( other ) ) == 0 ;
543
+ return value .compareTo ( other . toBigDecimal ( ) ) == 0 ;
564
544
}
565
545
566
546
public boolean eq (long value ) {
@@ -570,7 +550,7 @@ public boolean eq(long value) {
570
550
571
551
public boolean lt (IntegralDataTypeHolder other ) {
572
552
checkInitialized ();
573
- return value .compareTo ( extractBigDecimal ( other ) ) < 0 ;
553
+ return value .compareTo ( other . toBigDecimal ( ) ) < 0 ;
574
554
}
575
555
576
556
public boolean lt (long value ) {
@@ -580,7 +560,7 @@ public boolean lt(long value) {
580
560
581
561
public boolean gt (IntegralDataTypeHolder other ) {
582
562
checkInitialized ();
583
- return value .compareTo ( extractBigDecimal ( other ) ) > 0 ;
563
+ return value .compareTo ( other . toBigDecimal ( ) ) > 0 ;
584
564
}
585
565
586
566
public boolean gt (long value ) {
@@ -611,6 +591,24 @@ public Number makeValueThenAdd(long addend) {
611
591
return result ;
612
592
}
613
593
594
+ @ Override
595
+ public long toLong () {
596
+ checkInitialized ();
597
+ return value .longValue ();
598
+ }
599
+
600
+ @ Override
601
+ public BigInteger toBigInteger () {
602
+ checkInitialized ();
603
+ return value .toBigInteger ();
604
+ }
605
+
606
+ @ Override
607
+ public BigDecimal toBigDecimal () {
608
+ checkInitialized ();
609
+ return value ;
610
+ }
611
+
614
612
@ Override
615
613
public String toString () {
616
614
return "BigDecimalHolder[" + value + "]" ;
@@ -621,12 +619,9 @@ public boolean equals(Object o) {
621
619
if ( this == o ) {
622
620
return true ;
623
621
}
624
- if ( o == null || getClass () != o . getClass ( ) ) {
622
+ if ( !( o instanceof BigDecimalHolder that ) ) {
625
623
return false ;
626
624
}
627
-
628
- BigDecimalHolder that = (BigDecimalHolder ) o ;
629
-
630
625
return Objects .equals ( this .value , that .value );
631
626
}
632
627
0 commit comments