DATAREDIS-872 - Polishing.
Create unit tests for RedisAtomic counter initialization. Refactor setIfAbsent(…) method to initializeIfAbsent() to not expose additional API methods. Original pull request: #367.
This commit is contained in:
@@ -91,7 +91,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
@@ -135,12 +135,16 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeIfAbsent() {
|
||||
operations.setIfAbsent(key, (double) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value.
|
||||
*
|
||||
@@ -165,16 +169,6 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO
|
||||
operations.set(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to the given value, only if {@code key} does not exist.
|
||||
*
|
||||
* @param newValue the new value.
|
||||
* @return true if successful. False return indicates that {@code key} already existed.
|
||||
*/
|
||||
public Boolean setIfAbsent(double newValue) {
|
||||
return operations.setIfAbsent(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to the given value and return the old value.
|
||||
*
|
||||
|
||||
@@ -114,7 +114,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
@@ -133,12 +133,16 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeIfAbsent() {
|
||||
operations.setIfAbsent(key, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value.
|
||||
*
|
||||
@@ -163,16 +167,6 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey
|
||||
operations.set(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to the given value, only if {@code key} does not exist.
|
||||
*
|
||||
* @param newValue the new value.
|
||||
* @return true if successful. False return indicates that {@code key} already existed.
|
||||
*/
|
||||
public Boolean setIfAbsent(int newValue) {
|
||||
return operations.setIfAbsent(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to the given value and return the old value.
|
||||
*
|
||||
|
||||
@@ -92,7 +92,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
@@ -140,12 +140,16 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe
|
||||
this.operations = generalOps.opsForValue();
|
||||
|
||||
if (initialValue == null) {
|
||||
setIfAbsent(0);
|
||||
initializeIfAbsent();
|
||||
} else {
|
||||
set(initialValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeIfAbsent() {
|
||||
operations.setIfAbsent(key, (long) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value.
|
||||
*
|
||||
@@ -170,16 +174,6 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe
|
||||
operations.set(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to the given value, only if {@code key} does not exist.
|
||||
*
|
||||
* @param newValue the new value.
|
||||
* @return true if successful. False return indicates that {@code key} already existed.
|
||||
*/
|
||||
public Boolean setIfAbsent(long newValue) {
|
||||
return operations.setIfAbsent(key, newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to the given value and return the old value.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user