From bef4fbe8317205d7e2eb6f8442aef25d128cac7f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 29 Mar 2016 10:30:55 +0200 Subject: [PATCH] DATAREDIS-444 - Polishing. Add author name. Update license header. Reformat code. Add JavaDoc to hash operations. Original pull request: #184. --- .../data/redis/core/BoundHashOperations.java | 92 ++++++++++++++- .../core/DefaultBoundHashOperations.java | 13 ++- .../redis/core/DefaultHashOperations.java | 11 +- .../data/redis/core/HashOperations.java | 107 +++++++++++++++++- .../core/DefaultHashOperationsTests.java | 5 +- 5 files changed, 204 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java b/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java index d61d81682..81b5f1e65 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java @@ -1,12 +1,12 @@ /* - * Copyright 2011-2014 the original author or authors. - * + * Copyright 2011-2016 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. @@ -22,41 +22,123 @@ import java.util.Set; /** * Hash operations bound to a certain key. - * + * * @author Costin Leau * @author Christoph Strobl + * @author Ninad Divadkar */ public interface BoundHashOperations extends BoundKeyOperations { + /** + * @return + */ RedisOperations getOperations(); + /** + * Determine if given hash {@code key} exists. + * + * @param key must not be {@literal null}. + * @return + */ Boolean hasKey(Object key); + /** + * Increment {@code value} of a hash {@code key} by the given {@code delta}. + * + * @param key must not be {@literal null}. + * @param delta + * @return + */ Long increment(HK key, long delta); + /** + * Increment {@code value} of a hash {@code key} by the given {@code delta}. + * + * @param key must not be {@literal null}. + * @param delta + * @return + */ Double increment(HK key, double delta); + /** + * Get value for given {@code key} from the hash. + * + * @param key must not be {@literal null}. + * @return + */ HV get(Object key); + /** + * Set the {@code value} of a hash {@code key}. + * + * @param key must not be {@literal null}. + * @param value + */ void put(HK key, HV value); + /** + * Set the {@code value} of a hash {@code key} only if {@code key} does not exist. + * + * @param key must not be {@literal null}. + * @param value + * @return + */ Boolean putIfAbsent(HK key, HV value); + /** + * Get values for given {@code keys} from the hash. + * + * @param keys must not be {@literal null}. + * @return + */ List multiGet(Collection keys); + /** + * Set multiple hash fields to multiple values using data provided in {@code m}. + * + * @param m must not be {@literal null}. + */ void putAll(Map m); + /** + * Get key set (fields) of the hash. + * + * @return + */ Set keys(); + /** + * Get entry set (values) of hash. + * + * @return + */ List values(); + /** + * Get size of the hash. + * + * @return + */ Long size(); + /** + * Delete given hash {@code keys}. + * + * @param keys must not be {@literal null}. + * @return + */ Long delete(Object... keys); + /** + * Get entire hash. + * + * @return + */ Map entries(); /** + * Use a {@link Cursor} to iterate over entries in the hash. + * * @param options * @return * @since 1.4 diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java index 51ab3eaca..9cb9a14e6 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java @@ -1,12 +1,12 @@ /* - * Copyright 2011-2014 the original author or authors. - * + * Copyright 2011-2016 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. @@ -25,9 +25,10 @@ import org.springframework.data.redis.connection.DataType; /** * Default implementation for {@link HashOperations}. - * + * * @author Costin Leau * @author Christoph Strobl + * @author Ninad Divadkar */ class DefaultBoundHashOperations extends DefaultBoundKeyOperations implements BoundHashOperations { @@ -36,7 +37,7 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations /** * Constructs a new DefaultBoundHashOperations instance. - * + * * @param key * @param operations */ diff --git a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java index 94c5e9676..a8e2ba69b 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java @@ -1,12 +1,12 @@ /* - * Copyright 2011-2014 the original author or authors. - * + * Copyright 2011-2016 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. @@ -29,9 +29,10 @@ import org.springframework.data.redis.connection.RedisConnection; /** * Default implementation of {@link HashOperations}. - * + * * @author Costin Leau * @author Christoph Strobl + * @author Ninad Divadkar */ class DefaultHashOperations extends AbstractOperations implements HashOperations { diff --git a/src/main/java/org/springframework/data/redis/core/HashOperations.java b/src/main/java/org/springframework/data/redis/core/HashOperations.java index 875713756..7c3e09598 100644 --- a/src/main/java/org/springframework/data/redis/core/HashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/HashOperations.java @@ -1,12 +1,12 @@ /* - * Copyright 2011-2014 the original author or authors. - * + * Copyright 2011-2016 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. @@ -22,43 +22,138 @@ import java.util.Set; /** * Redis map specific operations working on a hash. - * + * * @author Costin Leau * @author Christoph Strobl + * @author Ninad Divadkar */ public interface HashOperations { + /** + * Delete given hash {@code hashKeys}. + * + * @param key must not be {@literal null}. + * @param hashKeys must not be {@literal null}. + * @return + */ Long delete(H key, Object... hashKeys); + /** + * Determine if given hash {@code hashKey} exists. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @return + */ Boolean hasKey(H key, Object hashKey); + /** + * Get value for given {@code hashKey} from hash at {@code key}. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @return + */ HV get(H key, Object hashKey); + /** + * Get values for given {@code hashKeys} from hash at {@code key}. + * + * @param key must not be {@literal null}. + * @param hashKeys must not be {@literal null}. + * @return + */ List multiGet(H key, Collection hashKeys); + /** + * Increment {@code value} of a hash {@code hashKey} by the given {@code delta}. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @param delta + * @return + */ Long increment(H key, HK hashKey, long delta); + /** + * Increment {@code value} of a hash {@code hashKey} by the given {@code delta}. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @param delta + * @return + */ Double increment(H key, HK hashKey, double delta); + /** + * Get key set (fields) of hash at {@code key}. + * + * @param key must not be {@literal null}. + * @return + */ Set keys(H key); + /** + * Get size of hash at {@code key}. + * + * @param key must not be {@literal null}. + * @return + */ Long size(H key); + /** + * Set multiple hash fields to multiple values using data provided in {@code m}. + * + * @param key must not be {@literal null}. + * @param m must not be {@literal null}. + */ void putAll(H key, Map m); + /** + * Set the {@code value} of a hash {@code hashKey}. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @param value + */ void put(H key, HK hashKey, HV value); + /** + * Set the {@code value} of a hash {@code hashKey} only if {@code hashKey} does not exist. + * + * @param key must not be {@literal null}. + * @param hashKey must not be {@literal null}. + * @param value + * @return + */ Boolean putIfAbsent(H key, HK hashKey, HV value); + /** + * Get entry set (values) of hash at {@code key}. + * + * @param key must not be {@literal null}. + * @return + */ List values(H key); + /** + * Get entire hash stored at {@code key}. + * + * @param key must not be {@literal null}. + * @return + */ Map entries(H key); + /** + * @return + */ RedisOperations getOperations(); /** + * Use a {@link Cursor} to iterate over entries in hash at {@code key}. + * * @since 1.4 - * @param key + * @param key must not be {@literal null}. * @param options * @return */ diff --git a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java index a2299be3b..96c449856 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 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. @@ -44,6 +44,7 @@ import org.springframework.test.annotation.IfProfileValue; * * @author Jennifer Hickey * @author Christoph Strobl + * @author Ninad Divadkar * @param Key type * @param Hash key type * @param Hash value type @@ -136,7 +137,7 @@ public class DefaultHashOperationsTests { hashOps.put(key, key2, val2); Long numDeleted = hashOps.delete(key, key1, key2); assertTrue(hashOps.keys(key).isEmpty()); - assertEquals(2L, numDeleted.longValue()); + assertEquals(2L, numDeleted.longValue()); } /**