Skip to content

Commit 961ba90

Browse files
Align newly added method names in RedisZSet to RedisSet.
And add some documentation to RedisSet along the way. #Original Pull Request: #2097
1 parent d019ada commit 961ba90

File tree

4 files changed

+113
-17
lines changed

4 files changed

+113
-17
lines changed

src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public DefaultRedisZSet(BoundZSetOperations<String, E> boundOps, double defaultS
110110
* @see org.springframework.data.redis.support.collections.RedisZSet#difference(org.springframework.data.redis.support.collections.RedisZSet)
111111
*/
112112
@Override
113-
public Set<E> difference(RedisZSet<?> set) {
113+
public Set<E> diff(RedisZSet<?> set) {
114114
return boundZSetOps.difference(set.getKey());
115115
}
116116

@@ -119,7 +119,7 @@ public Set<E> difference(RedisZSet<?> set) {
119119
* @see org.springframework.data.redis.support.collections.RedisZSet#difference(java.util.Collection)
120120
*/
121121
@Override
122-
public Set<E> difference(Collection<? extends RedisZSet<?>> sets) {
122+
public Set<E> diff(Collection<? extends RedisZSet<?>> sets) {
123123
return boundZSetOps.difference(CollectionUtils.extractKeys(sets));
124124
}
125125

@@ -128,7 +128,7 @@ public Set<E> difference(Collection<? extends RedisZSet<?>> sets) {
128128
* @see org.springframework.data.redis.support.collections.RedisZSet#differenceWithScores(org.springframework.data.redis.support.collections.RedisZSet)
129129
*/
130130
@Override
131-
public Set<TypedTuple<E>> differenceWithScores(RedisZSet<?> set) {
131+
public Set<TypedTuple<E>> diffWithScores(RedisZSet<?> set) {
132132
return boundZSetOps.differenceWithScores(set.getKey());
133133
}
134134

@@ -137,7 +137,7 @@ public Set<TypedTuple<E>> differenceWithScores(RedisZSet<?> set) {
137137
* @see org.springframework.data.redis.support.collections.RedisZSet#differenceWithScores(java.util.Collection)
138138
*/
139139
@Override
140-
public Set<TypedTuple<E>> differenceWithScores(Collection<? extends RedisZSet<?>> sets) {
140+
public Set<TypedTuple<E>> diffWithScores(Collection<? extends RedisZSet<?>> sets) {
141141
return boundZSetOps.differenceWithScores(CollectionUtils.extractKeys(sets));
142142
}
143143

@@ -146,7 +146,7 @@ public Set<TypedTuple<E>> differenceWithScores(Collection<? extends RedisZSet<?>
146146
* @see org.springframework.data.redis.support.collections.RedisZSet#differenceAndStore(org.springframework.data.redis.support.collections.RedisZSet, java.lang.String)
147147
*/
148148
@Override
149-
public RedisZSet<E> differenceAndStore(RedisZSet<?> set, String destKey) {
149+
public RedisZSet<E> diffAndStore(RedisZSet<?> set, String destKey) {
150150

151151
boundZSetOps.differenceAndStore(set.getKey(), destKey);
152152
return new DefaultRedisZSet<>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());
@@ -157,7 +157,7 @@ public RedisZSet<E> differenceAndStore(RedisZSet<?> set, String destKey) {
157157
* @see org.springframework.data.redis.support.collections.RedisZSet#differenceAndStore(java.util.Collection, java.lang.String)
158158
*/
159159
@Override
160-
public RedisZSet<E> differenceAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) {
160+
public RedisZSet<E> diffAndStore(Collection<? extends RedisZSet<?>> sets, String destKey) {
161161

162162
boundZSetOps.differenceAndStore(CollectionUtils.extractKeys(sets), destKey);
163163
return new DefaultRedisZSet<>(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore());

src/main/java/org/springframework/data/redis/support/collections/RedisSet.java

+96
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,124 @@
2727
*/
2828
public interface RedisSet<E> extends RedisCollection<E>, Set<E> {
2929

30+
/**
31+
* Intersect this set and another {@link RedisSet}.
32+
*
33+
* @param set must not be {@literal null}.
34+
* @return a {@link Set} containing the intersecting values.
35+
* @since 1.0
36+
*/
3037
Set<E> intersect(RedisSet<?> set);
3138

39+
/**
40+
* Intersect this set and other {@link RedisSet}s.
41+
*
42+
* @param sets must not be {@literal null}.
43+
* @return a {@link Set} containing the intersecting values.
44+
* @since 1.0
45+
*/
3246
Set<E> intersect(Collection<? extends RedisSet<?>> sets);
3347

48+
/**
49+
* Union this set and another {@link RedisSet}.
50+
*
51+
* @param set must not be {@literal null}.
52+
* @return a {@link Set} containing the combined values.
53+
* @since 2.6
54+
*/
3455
Set<E> union(RedisSet<?> set);
3556

57+
/**
58+
* Union this set and other {@link RedisSet}s.
59+
*
60+
* @param sets must not be {@literal null}.
61+
* @return a {@link Set} containing the combined values.
62+
* @since 1.0
63+
*/
3664
Set<E> union(Collection<? extends RedisSet<?>> sets);
3765

66+
/**
67+
* Diff this set and another {@link RedisSet}.
68+
*
69+
* @param set must not be {@literal null}.
70+
* @return a {@link Set} containing the values that differ.
71+
* @since 1.0
72+
*/
3873
Set<E> diff(RedisSet<?> set);
3974

75+
/**
76+
* Diff this set and other {@link RedisSet}s.
77+
*
78+
* @param sets must not be {@literal null}.
79+
* @return a {@link Set} containing the values that differ.
80+
* @since 1.0
81+
*/
4082
Set<E> diff(Collection<? extends RedisSet<?>> sets);
4183

84+
/**
85+
* Create a new {@link RedisSet} by intersecting this sorted set and {@link RedisSet} and store result in
86+
* destination {@code destKey}.
87+
*
88+
* @param set must not be {@literal null}.
89+
* @param destKey must not be {@literal null}.
90+
* @return a new {@link RedisSet} pointing at {@code destKey}
91+
* @since 1.0
92+
*/
4293
RedisSet<E> intersectAndStore(RedisSet<?> set, String destKey);
4394

95+
/**
96+
* Create a new {@link RedisSet} by intersecting this sorted set and the collection {@link RedisSet} and store
97+
* result in destination {@code destKey}.
98+
*
99+
* @param sets must not be {@literal null}.
100+
* @param destKey must not be {@literal null}.
101+
* @return a new {@link RedisSet} pointing at {@code destKey}.
102+
* @since 1.0
103+
*/
44104
RedisSet<E> intersectAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
45105

106+
/**
107+
* Create a new {@link RedisSet} by union this sorted set and {@link RedisSet} and store result in destination
108+
* {@code destKey}.
109+
*
110+
* @param set must not be {@literal null}.
111+
* @param destKey must not be {@literal null}.
112+
* @return a new {@link RedisSet} pointing at {@code destKey}.
113+
* @since 1.0
114+
*/
46115
RedisSet<E> unionAndStore(RedisSet<?> set, String destKey);
47116

117+
/**
118+
* Create a new {@link RedisSet} by union this sorted set and the collection {@link RedisSet} and store result in
119+
* destination {@code destKey}.
120+
*
121+
* @param sets must not be {@literal null}.
122+
* @param destKey must not be {@literal null}.
123+
* @return a new {@link RedisSet} pointing at {@code destKey}.
124+
* @since 1.0
125+
*/
48126
RedisSet<E> unionAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
49127

128+
/**
129+
* Create a new {@link RedisSet} by diffing this sorted set and {@link RedisSet} and store result in destination
130+
* {@code destKey}.
131+
*
132+
* @param set must not be {@literal null}.
133+
* @param destKey must not be {@literal null}.
134+
* @return a new {@link RedisSet} pointing at {@code destKey}.
135+
* @since 1.0
136+
*/
50137
RedisSet<E> diffAndStore(RedisSet<?> set, String destKey);
51138

139+
/**
140+
* Create a new {@link RedisSet} by diffing this sorted set and the collection {@link RedisSet} and store result in
141+
* destination {@code destKey}.
142+
*
143+
* @param sets must not be {@literal null}.
144+
* @param destKey must not be {@literal null}.
145+
* @return a new {@link RedisSet} pointing at {@code destKey}.
146+
* @since 1.0
147+
*/
52148
RedisSet<E> diffAndStore(Collection<? extends RedisSet<?>> sets, String destKey);
53149

54150
/**

src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
7373
* @return a {@link Set} containing the values that differ.
7474
* @since 2.6
7575
*/
76-
Set<E> difference(RedisZSet<?> set);
76+
Set<E> diff(RedisZSet<?> set);
7777

7878
/**
7979
* Diff this set and other {@link RedisZSet}s.
@@ -82,7 +82,7 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
8282
* @return a {@link Set} containing the values that differ.
8383
* @since 2.6
8484
*/
85-
Set<E> difference(Collection<? extends RedisZSet<?>> sets);
85+
Set<E> diff(Collection<? extends RedisZSet<?>> sets);
8686

8787
/**
8888
* Diff this set and another {@link RedisZSet}.
@@ -91,16 +91,16 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
9191
* @return a {@link Set} containing the values that differ with their scores.
9292
* @since 2.6
9393
*/
94-
Set<TypedTuple<E>> differenceWithScores(RedisZSet<?> set);
94+
Set<TypedTuple<E>> diffWithScores(RedisZSet<?> set);
9595

9696
/**
9797
* Diff this set and other {@link RedisZSet}s.
9898
*
99-
* @param set must not be {@literal null}.
99+
* @param sets must not be {@literal null}.
100100
* @return a {@link Set} containing the values that differ with their scores.
101101
* @since 2.6
102102
*/
103-
Set<TypedTuple<E>> differenceWithScores(Collection<? extends RedisZSet<?>> sets);
103+
Set<TypedTuple<E>> diffWithScores(Collection<? extends RedisZSet<?>> sets);
104104

105105
/**
106106
* Create a new {@link RedisZSet} by diffing this sorted set and {@link RedisZSet} and store result in destination
@@ -111,7 +111,7 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
111111
* @return a new {@link RedisZSet} pointing at {@code destKey}.
112112
* @since 2.6
113113
*/
114-
RedisZSet<E> differenceAndStore(RedisZSet<?> set, String destKey);
114+
RedisZSet<E> diffAndStore(RedisZSet<?> set, String destKey);
115115

116116
/**
117117
* Create a new {@link RedisZSet} by diffing this sorted set and the collection {@link RedisZSet} and store result in
@@ -122,7 +122,7 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
122122
* @return a new {@link RedisZSet} pointing at {@code destKey}.
123123
* @since 2.6
124124
*/
125-
RedisZSet<E> differenceAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
125+
RedisZSet<E> diffAndStore(Collection<? extends RedisZSet<?>> sets, String destKey);
126126

127127
/**
128128
* Intersect this set and another {@link RedisZSet}.
@@ -154,7 +154,7 @@ static <E> RedisZSet<E> create(String key, RedisOperations<String, E> operations
154154
/**
155155
* Intersect this set and other {@link RedisZSet}s.
156156
*
157-
* @param set must not be {@literal null}.
157+
* @param sets must not be {@literal null}.
158158
* @return a {@link Set} containing the intersecting values with their scores.
159159
* @since 2.6
160160
*/

src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTestIntegration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ void testDifference() {
633633
set2.add(t2, 2);
634634
set2.add(t3, 3);
635635

636-
assertThat(zSet.difference(Arrays.asList(set1, set2))).containsOnly(t1);
637-
assertThat(zSet.differenceWithScores(Arrays.asList(set1, set2))).containsOnly(new DefaultTypedTuple<>(t1, 1d));
636+
assertThat(zSet.diff(Arrays.asList(set1, set2))).containsOnly(t1);
637+
assertThat(zSet.diffWithScores(Arrays.asList(set1, set2))).containsOnly(new DefaultTypedTuple<>(t1, 1d));
638638
}
639639

640640
@ParameterizedRedisTest // GH-2041
@@ -658,7 +658,7 @@ void testDifferenceAndStore() {
658658
set2.add(t3, 3);
659659

660660
String resultName = "test:zset:inter:result:1";
661-
RedisZSet<T> diff = zSet.differenceAndStore(Arrays.asList(set1, set2), resultName);
661+
RedisZSet<T> diff = zSet.diffAndStore(Arrays.asList(set1, set2), resultName);
662662

663663
assertThat(diff).containsOnly(t1);
664664
}

0 commit comments

Comments
 (0)