@@ -224,23 +224,23 @@ protected int getHash(Object o) {
224
224
@ Override
225
225
public V get (Object key ) {
226
226
Reference <K , V > reference = getReference (key , Restructure .WHEN_NECESSARY );
227
- Entry <K , V > entry = (reference == null ? null : reference .get ());
227
+ Entry <K , V > entry = (reference != null ? reference .get () : null );
228
228
return (entry != null ? entry .getValue () : null );
229
229
}
230
230
231
231
@ Override
232
232
public boolean containsKey (Object key ) {
233
233
Reference <K , V > reference = getReference (key , Restructure .WHEN_NECESSARY );
234
- Entry <K , V > entry = (reference == null ? null : reference .get ());
234
+ Entry <K , V > entry = (reference != null ? reference .get () : null );
235
235
return (entry != null && ObjectUtils .nullSafeEquals (entry .getKey (), key ));
236
236
}
237
237
238
238
/**
239
- * Returns a {@link Reference} to the {@link Entry} for the specified {@code key} or
240
- * {@code null} if not found.
239
+ * Return a {@link Reference} to the {@link Entry} for the specified {@code key},
240
+ * or {@code null} if not found.
241
241
* @param key the key (can be {@code null})
242
242
* @param restructure types of restructure allowed during this call
243
- * @return the reference or {@code null}
243
+ * @return the reference, or {@code null} if not found
244
244
*/
245
245
protected final Reference <K , V > getReference (Object key , Restructure restructure ) {
246
246
int hash = getHash (key );
@@ -400,14 +400,10 @@ protected static int calculateShift(int minimumValue, int maximumValue) {
400
400
*/
401
401
public static enum ReferenceType {
402
402
403
- /**
404
- * Use {@link SoftReference}s.
405
- */
403
+ /** Use {@link SoftReference}s */
406
404
SOFT ,
407
405
408
- /**
409
- * Use {@link WeakReference}s.
410
- */
406
+ /** Use {@link WeakReference}s */
411
407
WEAK
412
408
}
413
409
@@ -462,8 +458,8 @@ public Reference<K, V> getReference(Object key, int hash, Restructure restructur
462
458
}
463
459
464
460
/**
465
- * Apply an update operation to this segment. The segment will be locked
466
- * during update.
461
+ * Apply an update operation to this segment.
462
+ * The segment will be locked during the update.
467
463
* @param hash the hash of the key
468
464
* @param key the key
469
465
* @param task the update operation
@@ -474,20 +470,20 @@ public <T> T doTask(final int hash, final Object key, final Task<T> task) {
474
470
if (task .hasOption (TaskOption .RESTRUCTURE_BEFORE )) {
475
471
restructureIfNecessary (resize );
476
472
}
477
- if (task .hasOption (TaskOption .SKIP_IF_EMPTY ) && ( this .count == 0 ) ) {
473
+ if (task .hasOption (TaskOption .SKIP_IF_EMPTY ) && this .count == 0 ) {
478
474
return task .execute (null , null , null );
479
475
}
480
476
lock ();
481
477
try {
482
478
final int index = getIndex (hash , this .references );
483
479
final Reference <K , V > head = this .references [index ];
484
480
Reference <K , V > reference = findInChain (head , key , hash );
485
- Entry <K , V > entry = (reference == null ? null : reference .get ());
481
+ Entry <K , V > entry = (reference != null ? reference .get () : null );
486
482
Entries entries = new Entries () {
487
483
@ Override
488
484
public void add (V value ) {
489
485
@ SuppressWarnings ("unchecked" )
490
- Entry <K , V > newEntry = new Entry <K , V >((K )key , value );
486
+ Entry <K , V > newEntry = new Entry <K , V >((K ) key , value );
491
487
Reference <K , V > newReference = Segment .this .referenceManager .createReference (newEntry , hash , head );
492
488
Segment .this .references [index ] = newReference ;
493
489
Segment .this .count ++;
@@ -514,7 +510,8 @@ public void clear() {
514
510
try {
515
511
setReferences (createReferenceArray (this .initialSize ));
516
512
this .count = 0 ;
517
- } finally {
513
+ }
514
+ finally {
518
515
unlock ();
519
516
}
520
517
}
@@ -545,16 +542,16 @@ protected final void restructureIfNecessary(boolean allowResize) {
545
542
546
543
// Recalculate taking into account count inside lock and items that
547
544
// will be purged
548
- needsResize = (( countAfterRestructure > 0 ) && ( countAfterRestructure >= this .resizeThreshold ) );
545
+ needsResize = (countAfterRestructure > 0 && countAfterRestructure >= this .resizeThreshold );
549
546
boolean resizing = false ;
550
547
int restructureSize = this .references .length ;
551
- if (allowResize && needsResize && ( restructureSize < MAXIMUM_SEGMENT_SIZE ) ) {
548
+ if (allowResize && needsResize && restructureSize < MAXIMUM_SEGMENT_SIZE ) {
552
549
restructureSize <<= 1 ;
553
550
resizing = true ;
554
551
}
555
552
556
553
// Either create a new table or reuse the existing one
557
- Reference <K , V >[] restructured = (resizing ? createReferenceArray (restructureSize ) : this .references );
554
+ Reference <K , V >[] restructured = (resizing ? createReferenceArray (restructureSize ) : this .references );
558
555
559
556
// Restructure
560
557
for (int i = 0 ; i < this .references .length ; i ++) {
@@ -578,7 +575,8 @@ protected final void restructureIfNecessary(boolean allowResize) {
578
575
setReferences (restructured );
579
576
}
580
577
this .count = Math .max (countAfterRestructure , 0 );
581
- } finally {
578
+ }
579
+ finally {
582
580
unlock ();
583
581
}
584
582
}
@@ -606,7 +604,7 @@ private Reference<K, V>[] createReferenceArray(int size) {
606
604
}
607
605
608
606
private int getIndex (int hash , Reference <K , V >[] references ) {
609
- return hash & (references .length - 1 );
607
+ return ( hash & (references .length - 1 ) );
610
608
}
611
609
612
610
/**
@@ -700,27 +698,26 @@ public V setValue(V value) {
700
698
701
699
@ Override
702
700
public String toString () {
703
- return this .key + "=" + this .value ;
701
+ return ( this .key + "=" + this .value ) ;
704
702
}
705
703
706
704
@ Override
707
705
@ SuppressWarnings ("rawtypes" )
708
- public final boolean equals (Object o ) {
709
- if (o == this ) {
706
+ public final boolean equals (Object other ) {
707
+ if (this == other ) {
710
708
return true ;
711
709
}
712
- if (o != null && o instanceof Map .Entry ) {
713
- Map .Entry other = (Map .Entry ) o ;
714
- return ObjectUtils .nullSafeEquals (getKey (), other .getKey ())
715
- && ObjectUtils .nullSafeEquals (getValue (), other .getValue ());
710
+ if (!(other instanceof Map .Entry )) {
711
+ return false ;
716
712
}
717
- return false ;
713
+ Map .Entry otherEntry = (Map .Entry ) other ;
714
+ return (ObjectUtils .nullSafeEquals (getKey (), otherEntry .getKey ()) &&
715
+ ObjectUtils .nullSafeEquals (getValue (), otherEntry .getValue ()));
718
716
}
719
717
720
718
@ Override
721
719
public final int hashCode () {
722
- return ObjectUtils .nullSafeHashCode (this .key )
723
- ^ ObjectUtils .nullSafeHashCode (this .value );
720
+ return (ObjectUtils .nullSafeHashCode (this .key ) ^ ObjectUtils .nullSafeHashCode (this .value ));
724
721
}
725
722
}
726
723
@@ -802,7 +799,7 @@ public boolean contains(Object o) {
802
799
if (o != null && o instanceof Map .Entry <?, ?>) {
803
800
Map .Entry <?, ?> entry = (java .util .Map .Entry <?, ?>) o ;
804
801
Reference <K , V > reference = ConcurrentReferenceHashMap .this .getReference (entry .getKey (), Restructure .NEVER );
805
- Entry <K , V > other = (reference == null ? null : reference .get ());
802
+ Entry <K , V > other = (reference != null ? reference .get () : null );
806
803
if (other != null ) {
807
804
return ObjectUtils .nullSafeEquals (entry .getValue (), other .getValue ());
808
805
}
@@ -855,7 +852,7 @@ public EntryIterator() {
855
852
@ Override
856
853
public boolean hasNext () {
857
854
getNextIfNecessary ();
858
- return this .next != null ;
855
+ return ( this .next != null ) ;
859
856
}
860
857
861
858
@ Override
@@ -987,7 +984,6 @@ public void release() {
987
984
enqueue ();
988
985
clear ();
989
986
}
990
-
991
987
}
992
988
993
989
@@ -1021,7 +1017,6 @@ public void release() {
1021
1017
enqueue ();
1022
1018
clear ();
1023
1019
}
1024
-
1025
1020
}
1026
1021
1027
1022
}
0 commit comments