Skip to content

Commit bef4fbe

Browse files
committed
DATAREDIS-444 - Polishing.
Add author name. Update license header. Reformat code. Add JavaDoc to hash operations. Original pull request: spring-projects#184.
1 parent 5f9d005 commit bef4fbe

File tree

5 files changed

+204
-24
lines changed

5 files changed

+204
-24
lines changed

src/main/java/org/springframework/data/redis/core/BoundHashOperations.java

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
3-
*
2+
* Copyright 2011-2016 the original author or authors.
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,41 +22,123 @@
2222

2323
/**
2424
* Hash operations bound to a certain key.
25-
*
25+
*
2626
* @author Costin Leau
2727
* @author Christoph Strobl
28+
* @author Ninad Divadkar
2829
*/
2930
public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> {
3031

32+
/**
33+
* @return
34+
*/
3135
RedisOperations<H, ?> getOperations();
3236

37+
/**
38+
* Determine if given hash {@code key} exists.
39+
*
40+
* @param key must not be {@literal null}.
41+
* @return
42+
*/
3343
Boolean hasKey(Object key);
3444

45+
/**
46+
* Increment {@code value} of a hash {@code key} by the given {@code delta}.
47+
*
48+
* @param key must not be {@literal null}.
49+
* @param delta
50+
* @return
51+
*/
3552
Long increment(HK key, long delta);
3653

54+
/**
55+
* Increment {@code value} of a hash {@code key} by the given {@code delta}.
56+
*
57+
* @param key must not be {@literal null}.
58+
* @param delta
59+
* @return
60+
*/
3761
Double increment(HK key, double delta);
3862

63+
/**
64+
* Get value for given {@code key} from the hash.
65+
*
66+
* @param key must not be {@literal null}.
67+
* @return
68+
*/
3969
HV get(Object key);
4070

71+
/**
72+
* Set the {@code value} of a hash {@code key}.
73+
*
74+
* @param key must not be {@literal null}.
75+
* @param value
76+
*/
4177
void put(HK key, HV value);
4278

79+
/**
80+
* Set the {@code value} of a hash {@code key} only if {@code key} does not exist.
81+
*
82+
* @param key must not be {@literal null}.
83+
* @param value
84+
* @return
85+
*/
4386
Boolean putIfAbsent(HK key, HV value);
4487

88+
/**
89+
* Get values for given {@code keys} from the hash.
90+
*
91+
* @param keys must not be {@literal null}.
92+
* @return
93+
*/
4594
List<HV> multiGet(Collection<HK> keys);
4695

96+
/**
97+
* Set multiple hash fields to multiple values using data provided in {@code m}.
98+
*
99+
* @param m must not be {@literal null}.
100+
*/
47101
void putAll(Map<? extends HK, ? extends HV> m);
48102

103+
/**
104+
* Get key set (fields) of the hash.
105+
*
106+
* @return
107+
*/
49108
Set<HK> keys();
50109

110+
/**
111+
* Get entry set (values) of hash.
112+
*
113+
* @return
114+
*/
51115
List<HV> values();
52116

117+
/**
118+
* Get size of the hash.
119+
*
120+
* @return
121+
*/
53122
Long size();
54123

124+
/**
125+
* Delete given hash {@code keys}.
126+
*
127+
* @param keys must not be {@literal null}.
128+
* @return
129+
*/
55130
Long delete(Object... keys);
56131

132+
/**
133+
* Get entire hash.
134+
*
135+
* @return
136+
*/
57137
Map<HK, HV> entries();
58138

59139
/**
140+
* Use a {@link Cursor} to iterate over entries in the hash.
141+
*
60142
* @param options
61143
* @return
62144
* @since 1.4

src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
3-
*
2+
* Copyright 2011-2016 the original author or authors.
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,9 +25,10 @@
2525

2626
/**
2727
* Default implementation for {@link HashOperations}.
28-
*
28+
*
2929
* @author Costin Leau
3030
* @author Christoph Strobl
31+
* @author Ninad Divadkar
3132
*/
3233
class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H> implements
3334
BoundHashOperations<H, HK, HV> {
@@ -36,7 +37,7 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H>
3637

3738
/**
3839
* Constructs a new <code>DefaultBoundHashOperations</code> instance.
39-
*
40+
*
4041
* @param key
4142
* @param operations
4243
*/

src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
3-
*
2+
* Copyright 2011-2016 the original author or authors.
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,9 +29,10 @@
2929

3030
/**
3131
* Default implementation of {@link HashOperations}.
32-
*
32+
*
3333
* @author Costin Leau
3434
* @author Christoph Strobl
35+
* @author Ninad Divadkar
3536
*/
3637
class DefaultHashOperations<K, HK, HV> extends AbstractOperations<K, Object> implements HashOperations<K, HK, HV> {
3738

src/main/java/org/springframework/data/redis/core/HashOperations.java

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
3-
*
2+
* Copyright 2011-2016 the original author or authors.
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,43 +22,138 @@
2222

2323
/**
2424
* Redis map specific operations working on a hash.
25-
*
25+
*
2626
* @author Costin Leau
2727
* @author Christoph Strobl
28+
* @author Ninad Divadkar
2829
*/
2930
public interface HashOperations<H, HK, HV> {
3031

32+
/**
33+
* Delete given hash {@code hashKeys}.
34+
*
35+
* @param key must not be {@literal null}.
36+
* @param hashKeys must not be {@literal null}.
37+
* @return
38+
*/
3139
Long delete(H key, Object... hashKeys);
3240

41+
/**
42+
* Determine if given hash {@code hashKey} exists.
43+
*
44+
* @param key must not be {@literal null}.
45+
* @param hashKey must not be {@literal null}.
46+
* @return
47+
*/
3348
Boolean hasKey(H key, Object hashKey);
3449

50+
/**
51+
* Get value for given {@code hashKey} from hash at {@code key}.
52+
*
53+
* @param key must not be {@literal null}.
54+
* @param hashKey must not be {@literal null}.
55+
* @return
56+
*/
3557
HV get(H key, Object hashKey);
3658

59+
/**
60+
* Get values for given {@code hashKeys} from hash at {@code key}.
61+
*
62+
* @param key must not be {@literal null}.
63+
* @param hashKeys must not be {@literal null}.
64+
* @return
65+
*/
3766
List<HV> multiGet(H key, Collection<HK> hashKeys);
3867

68+
/**
69+
* Increment {@code value} of a hash {@code hashKey} by the given {@code delta}.
70+
*
71+
* @param key must not be {@literal null}.
72+
* @param hashKey must not be {@literal null}.
73+
* @param delta
74+
* @return
75+
*/
3976
Long increment(H key, HK hashKey, long delta);
4077

78+
/**
79+
* Increment {@code value} of a hash {@code hashKey} by the given {@code delta}.
80+
*
81+
* @param key must not be {@literal null}.
82+
* @param hashKey must not be {@literal null}.
83+
* @param delta
84+
* @return
85+
*/
4186
Double increment(H key, HK hashKey, double delta);
4287

88+
/**
89+
* Get key set (fields) of hash at {@code key}.
90+
*
91+
* @param key must not be {@literal null}.
92+
* @return
93+
*/
4394
Set<HK> keys(H key);
4495

96+
/**
97+
* Get size of hash at {@code key}.
98+
*
99+
* @param key must not be {@literal null}.
100+
* @return
101+
*/
45102
Long size(H key);
46103

104+
/**
105+
* Set multiple hash fields to multiple values using data provided in {@code m}.
106+
*
107+
* @param key must not be {@literal null}.
108+
* @param m must not be {@literal null}.
109+
*/
47110
void putAll(H key, Map<? extends HK, ? extends HV> m);
48111

112+
/**
113+
* Set the {@code value} of a hash {@code hashKey}.
114+
*
115+
* @param key must not be {@literal null}.
116+
* @param hashKey must not be {@literal null}.
117+
* @param value
118+
*/
49119
void put(H key, HK hashKey, HV value);
50120

121+
/**
122+
* Set the {@code value} of a hash {@code hashKey} only if {@code hashKey} does not exist.
123+
*
124+
* @param key must not be {@literal null}.
125+
* @param hashKey must not be {@literal null}.
126+
* @param value
127+
* @return
128+
*/
51129
Boolean putIfAbsent(H key, HK hashKey, HV value);
52130

131+
/**
132+
* Get entry set (values) of hash at {@code key}.
133+
*
134+
* @param key must not be {@literal null}.
135+
* @return
136+
*/
53137
List<HV> values(H key);
54138

139+
/**
140+
* Get entire hash stored at {@code key}.
141+
*
142+
* @param key must not be {@literal null}.
143+
* @return
144+
*/
55145
Map<HK, HV> entries(H key);
56146

147+
/**
148+
* @return
149+
*/
57150
RedisOperations<H, ?> getOperations();
58151

59152
/**
153+
* Use a {@link Cursor} to iterate over entries in hash at {@code key}.
154+
*
60155
* @since 1.4
61-
* @param key
156+
* @param key must not be {@literal null}.
62157
* @param options
63158
* @return
64159
*/

src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@
4444
*
4545
* @author Jennifer Hickey
4646
* @author Christoph Strobl
47+
* @author Ninad Divadkar
4748
* @param <K> Key type
4849
* @param <HK> Hash key type
4950
* @param <HV> Hash value type
@@ -136,7 +137,7 @@ public void testDelete() {
136137
hashOps.put(key, key2, val2);
137138
Long numDeleted = hashOps.delete(key, key1, key2);
138139
assertTrue(hashOps.keys(key).isEmpty());
139-
assertEquals(2L, numDeleted.longValue());
140+
assertEquals(2L, numDeleted.longValue());
140141
}
141142

142143
/**

0 commit comments

Comments
 (0)