+ refactored util package into support collections and atomic
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.atomic;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.atomic;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.Collection;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisCommands;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
|
||||
/**
|
||||
* Default {@link RedisMap} implementation.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DefaultRedisMap<K, V> implements RedisMap<K, V> {
|
||||
|
||||
private class DefaultRedisMapEntry implements Map.Entry<String, String> {
|
||||
|
||||
private String key, value;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultRedisMapEntry</code> instance.
|
||||
*
|
||||
* @param entry
|
||||
*/
|
||||
public DefaultRedisMapEntry(org.springframework.data.keyvalue.redis.connection.RedisHashCommands.Entry entry) {
|
||||
this.key = entry.getField();
|
||||
this.value = entry.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setValue(String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
protected final String redisKey;
|
||||
protected final RedisOperations<String, ?> operations;
|
||||
private final MapOperations<String, K, V> mapOps;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultRedisMap</code> instance.
|
||||
*
|
||||
* @param key
|
||||
* @param operations
|
||||
*/
|
||||
public DefaultRedisMap(String key, RedisOperations<K, V> operations) {
|
||||
this.redisKey = key;
|
||||
this.operations = operations;
|
||||
this.maps = operations.forMap(key);
|
||||
}
|
||||
|
||||
public DefaultRedisList(String key, RedisOperations<String, E> operations) {
|
||||
super(key, operations);
|
||||
listOps = operations.listOps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer increment(String key, int delta) {
|
||||
return commands.hIncrBy(redisKey, key, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putIfAbsent(String key, String value) {
|
||||
return commands.hSetNX(redisKey, key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return redisKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisCommands getOperations() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return commands.hExists(redisKey, key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<java.util.Map.Entry<String, String>> entrySet() {
|
||||
return createEntrySet(commands.hGetAll(redisKey));
|
||||
}
|
||||
|
||||
private Set<java.util.Map.Entry<String, String>> createEntrySet(Set<org.springframework.data.keyvalue.redis.connection.RedisHashCommands.Entry> entries) {
|
||||
Set<java.util.Map.Entry<String, String>> result = new LinkedHashSet<java.util.Map.Entry<String, String>>(
|
||||
entries.size());
|
||||
|
||||
for (org.springframework.data.keyvalue.redis.connection.RedisHashCommands.Entry entry : entries) {
|
||||
result.add(new DefaultRedisMapEntry(entry));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Object key) {
|
||||
return commands.hGet(redisKey, key.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return commands.hKeys(redisKey);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String put(String key, String value) {
|
||||
String previous = commands.hGet(redisKey, key);
|
||||
if (commands.hSet(redisKey, key, value)) {
|
||||
return null;
|
||||
}
|
||||
return previous;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends String> m) {
|
||||
String[] keys = m.keySet().toArray(new String[m.size()]);
|
||||
String[] values = m.values().toArray(new String[m.size()]);
|
||||
|
||||
commands.hMSet(redisKey, keys, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String remove(Object key) {
|
||||
String previous = commands.hGet(redisKey, key.toString());
|
||||
if (commands.hDel(redisKey, key.toString())) {
|
||||
return previous;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return commands.hLen(redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> values() {
|
||||
return commands.hVals(redisKey);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
@@ -40,6 +40,8 @@ import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisCallback;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisStore;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
@@ -27,6 +27,8 @@ import java.util.NoSuchElementException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisList;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisList;
|
||||
|
||||
/**
|
||||
* Integration test for RedisList
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -43,6 +43,9 @@ import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory
|
||||
import org.springframework.data.keyvalue.redis.core.RedisCallback;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisMap;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisMap;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisStore;
|
||||
|
||||
/**
|
||||
* Integration test for Redis Map.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -29,6 +29,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisSet;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisSet;
|
||||
|
||||
/**
|
||||
* Integration test for Redis set.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
@@ -27,6 +27,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisZSet;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisZSet;
|
||||
|
||||
/**
|
||||
* Integration test for Redis ZSet.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
/**
|
||||
* Simple object factory.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -13,9 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisList;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisStore;
|
||||
|
||||
/**
|
||||
* Parameterized instance of Redis tests.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -23,6 +23,8 @@ import org.springframework.data.keyvalue.redis.Person;
|
||||
import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisMap;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisMap;
|
||||
|
||||
/**
|
||||
* Integration test for RedisMap.
|
||||
@@ -13,9 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisSet;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisStore;
|
||||
|
||||
/**
|
||||
* Parameterized instance of Redis tests.
|
||||
@@ -13,9 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.RedisTemplate;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.AbstractRedisCollection;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisZSet;
|
||||
import org.springframework.data.keyvalue.redis.support.collections.RedisStore;
|
||||
|
||||
/**
|
||||
* Parameterized instance of Redis sorted set tests.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.util;
|
||||
package org.springframework.data.keyvalue.redis.support.collections;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
Reference in New Issue
Block a user