+ update APIs to improve the generified usage
This commit is contained in:
@@ -67,34 +67,34 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> diff(Collection<RedisSet<? extends E>> sets) {
|
||||
public Set<E> diff(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.diff(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> diffAndStore(String destKey, Collection<RedisSet<? extends E>> sets) {
|
||||
public RedisSet<E> diffAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.diffAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().forSet(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> intersect(Collection<RedisSet<? extends E>> sets) {
|
||||
public Set<E> intersect(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.intersect(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> intersectAndStore(String destKey, Collection<RedisSet<? extends E>> sets) {
|
||||
public RedisSet<E> intersectAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.intersectAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().forSet(destKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> union(Collection<RedisSet<? extends E>> sets) {
|
||||
public Set<E> union(Collection<? extends RedisSet<?>> sets) {
|
||||
return boundSetOps.union(CollectionUtils.extractKeys(sets));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisSet<E> unionAndStore(String destKey, Collection<RedisSet<? extends E>> sets) {
|
||||
public RedisSet<E> unionAndStore(String destKey, Collection<? extends RedisSet<?>> sets) {
|
||||
boundSetOps.unionAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
return new DefaultRedisSet<E>(boundSetOps.getOperations().forSet(destKey));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> intersectAndStore(String destKey, Collection<RedisZSet<? extends E>> sets) {
|
||||
public RedisZSet<E> intersectAndStore(String destKey, Collection<? extends RedisZSet<?>> sets) {
|
||||
boundZSetOps.intersectAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().forZSet(destKey), getDefaultScore());
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> unionAndStore(String destKey, Collection<RedisZSet<? extends E>> sets) {
|
||||
public RedisZSet<E> unionAndStore(String destKey, Collection<? extends RedisZSet<?>> sets) {
|
||||
boundZSetOps.unionAndStore(destKey, CollectionUtils.extractKeys(sets));
|
||||
return new DefaultRedisZSet<E>(boundZSetOps.getOperations().forZSet(destKey), getDefaultScore());
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ import java.util.Set;
|
||||
*/
|
||||
public interface RedisSet<E> extends RedisStore<String>, Set<E> {
|
||||
|
||||
Set<E> intersect(Collection<RedisSet<? extends E>> sets);
|
||||
Set<E> intersect(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
Set<E> union(Collection<RedisSet<? extends E>> sets);
|
||||
Set<E> union(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
Set<E> diff(Collection<RedisSet<? extends E>> sets);
|
||||
Set<E> diff(Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
RedisSet<E> intersectAndStore(String destKey, Collection<RedisSet<? extends E>> sets);
|
||||
RedisSet<E> intersectAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
RedisSet<E> unionAndStore(String destKey, Collection<RedisSet<? extends E>> sets);
|
||||
RedisSet<E> unionAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
|
||||
RedisSet<E> diffAndStore(String destKey, Collection<RedisSet<? extends E>> sets);
|
||||
RedisSet<E> diffAndStore(String destKey, Collection<? extends RedisSet<?>> sets);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ import java.util.SortedSet;
|
||||
*/
|
||||
public interface RedisZSet<E> extends RedisStore<String>, Set<E> {
|
||||
|
||||
RedisZSet<E> intersectAndStore(String destKey, Collection<RedisZSet<? extends E>> sets);
|
||||
RedisZSet<E> intersectAndStore(String destKey, Collection<? extends RedisZSet<?>> sets);
|
||||
|
||||
RedisZSet<E> unionAndStore(String destKey, Collection<RedisZSet<? extends E>> sets);
|
||||
RedisZSet<E> unionAndStore(String destKey, Collection<? extends RedisZSet<?>> sets);
|
||||
|
||||
Set<E> range(long start, long end);
|
||||
|
||||
|
||||
@@ -29,8 +29,6 @@ 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.
|
||||
@@ -80,7 +78,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
diffSet1.add(t2);
|
||||
diffSet2.add(t3);
|
||||
|
||||
Set<T> diff = set.diff(diffSet1, diffSet2);
|
||||
Set<T> diff = set.diff(Arrays.asList(diffSet1, diffSet2));
|
||||
assertEquals(1, diff.size());
|
||||
assertThat(diff, hasItem(t1));
|
||||
}
|
||||
@@ -104,7 +102,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
diffSet2.add(t4);
|
||||
|
||||
String resultName = "test:set:diff:result:1";
|
||||
RedisSet<T> diff = set.diffAndStore(resultName, diffSet1, diffSet2);
|
||||
RedisSet<T> diff = set.diffAndStore(resultName, Arrays.asList(diffSet1, diffSet2));
|
||||
|
||||
assertEquals(1, diff.size());
|
||||
assertThat(diff, hasItem(t1));
|
||||
@@ -130,7 +128,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
intSet2.add(t2);
|
||||
intSet2.add(t3);
|
||||
|
||||
Set<T> inter = set.intersect(intSet1, intSet2);
|
||||
Set<T> inter = set.intersect(Arrays.asList(intSet1, intSet2));
|
||||
assertEquals(1, inter.size());
|
||||
assertThat(inter, hasItem(t2));
|
||||
}
|
||||
@@ -155,7 +153,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
intSet2.add(t3);
|
||||
|
||||
String resultName = "test:set:intersect:result:1";
|
||||
RedisSet<T> inter = set.intersectAndStore(resultName, intSet1, intSet2);
|
||||
RedisSet<T> inter = set.intersectAndStore(resultName, Arrays.asList(intSet1, intSet2));
|
||||
assertEquals(1, inter.size());
|
||||
assertThat(inter, hasItem(t2));
|
||||
assertEquals(resultName, inter.getKey());
|
||||
@@ -178,7 +176,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
unionSet1.add(t4);
|
||||
unionSet2.add(t3);
|
||||
|
||||
Set<T> union = set.union(unionSet1, unionSet2);
|
||||
Set<T> union = set.union(Arrays.asList(unionSet1, unionSet2));
|
||||
assertEquals(4, union.size());
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
}
|
||||
@@ -201,7 +199,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
|
||||
unionSet2.add(t3);
|
||||
|
||||
String resultName = "test:set:union:result:1";
|
||||
RedisSet<T> union = set.unionAndStore(resultName, unionSet1, unionSet2);
|
||||
RedisSet<T> union = set.unionAndStore(resultName, Arrays.asList(unionSet1, unionSet2));
|
||||
assertEquals(4, union.size());
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
assertEquals(resultName, union.getKey());
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.junit.matchers.JUnitMatchers.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
@@ -27,8 +28,6 @@ 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.
|
||||
@@ -208,7 +207,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
interSet2.add(t3, 3);
|
||||
|
||||
String resultName = "test:zset:inter:result:1";
|
||||
RedisZSet<T> inter = zSet.intersectAndStore(resultName, interSet1, interSet2);
|
||||
RedisZSet<T> inter = zSet.intersectAndStore(resultName, Arrays.asList(interSet1, interSet2));
|
||||
|
||||
assertEquals(1, inter.size());
|
||||
assertThat(inter, hasItem(t2));
|
||||
@@ -328,7 +327,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
|
||||
unionSet2.add(t3, 6);
|
||||
|
||||
String resultName = "test:zset:union:result:1";
|
||||
RedisZSet<T> union = zSet.unionAndStore(resultName, unionSet1, unionSet2);
|
||||
RedisZSet<T> union = zSet.unionAndStore(resultName, Arrays.asList(unionSet1, unionSet2));
|
||||
assertEquals(4, union.size());
|
||||
assertThat(union, hasItems(t1, t2, t3, t4));
|
||||
assertEquals(resultName, union.getKey());
|
||||
|
||||
Reference in New Issue
Block a user