Polishing.
Add tests that assert initialization constraints, use early return to default value in case of null and align code format. Original Pull Request: #2637
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public enum DataType {
|
||||
|
||||
@@ -36,9 +37,9 @@ public enum DataType {
|
||||
private static final Map<String, DataType> codeLookup = new ConcurrentHashMap<>(7);
|
||||
|
||||
static {
|
||||
for (DataType type : EnumSet.allOf(DataType.class))
|
||||
for (DataType type : EnumSet.allOf(DataType.class)) {
|
||||
codeLookup.put(type.code, type);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private final String code;
|
||||
@@ -63,9 +64,11 @@ public enum DataType {
|
||||
* @return actual enum corresponding to the given code
|
||||
*/
|
||||
public static DataType fromCode(String code) {
|
||||
|
||||
DataType data = codeLookup.get(code);
|
||||
if (data == null)
|
||||
throw new IllegalArgumentException("unknown data type code");
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("unknown data type code %s".formatted(code));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class RedisCollectionFactoryBean implements SmartFactoryBean<RedisStore>,
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public enum CollectionType {
|
||||
LIST {
|
||||
@@ -95,6 +96,10 @@ public class RedisCollectionFactoryBean implements SmartFactoryBean<RedisStore>,
|
||||
*/
|
||||
static CollectionType findCollectionType(@Nullable DataType dataType, Supplier<CollectionType> ifNotFound) {
|
||||
|
||||
if (dataType == null) {
|
||||
return ifNotFound.get();
|
||||
}
|
||||
|
||||
for (CollectionType collectionType : values()) {
|
||||
if (collectionType.dataType() == dataType) {
|
||||
return collectionType;
|
||||
@@ -135,7 +140,7 @@ public class RedisCollectionFactoryBean implements SmartFactoryBean<RedisStore>,
|
||||
|
||||
if (keyType != null && DataType.NONE != keyType && this.type.dataType() != keyType) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Cannot create collection type '%s' for a key containing '%s'", this.type, keyType));
|
||||
"Cannot create collection type '%s' for a key containing '%s'".formatted(this.type, keyType));
|
||||
}
|
||||
|
||||
return createStore(this.type, key, template);
|
||||
|
||||
Reference in New Issue
Block a user