DATAREDIS-444 - Polishing.

Add author name. Update license header. Reformat code. Add JavaDoc to hash operations.

Original pull request: #184.
This commit is contained in:
Mark Paluch
2016-03-29 10:30:55 +02:00
parent 5f9d005cb3
commit bef4fbe831
5 changed files with 204 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -25,38 +25,120 @@ import java.util.Set;
* *
* @author Costin Leau * @author Costin Leau
* @author Christoph Strobl * @author Christoph Strobl
* @author Ninad Divadkar
*/ */
public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> { public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> {
/**
* @return
*/
RedisOperations<H, ?> getOperations(); RedisOperations<H, ?> getOperations();
/**
* Determine if given hash {@code key} exists.
*
* @param key must not be {@literal null}.
* @return
*/
Boolean hasKey(Object key); 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); 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); 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); 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); 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); Boolean putIfAbsent(HK key, HV value);
/**
* Get values for given {@code keys} from the hash.
*
* @param keys must not be {@literal null}.
* @return
*/
List<HV> multiGet(Collection<HK> keys); List<HV> multiGet(Collection<HK> keys);
/**
* Set multiple hash fields to multiple values using data provided in {@code m}.
*
* @param m must not be {@literal null}.
*/
void putAll(Map<? extends HK, ? extends HV> m); void putAll(Map<? extends HK, ? extends HV> m);
/**
* Get key set (fields) of the hash.
*
* @return
*/
Set<HK> keys(); Set<HK> keys();
/**
* Get entry set (values) of hash.
*
* @return
*/
List<HV> values(); List<HV> values();
/**
* Get size of the hash.
*
* @return
*/
Long size(); Long size();
/**
* Delete given hash {@code keys}.
*
* @param keys must not be {@literal null}.
* @return
*/
Long delete(Object... keys); Long delete(Object... keys);
/**
* Get entire hash.
*
* @return
*/
Map<HK, HV> entries(); Map<HK, HV> entries();
/** /**
* Use a {@link Cursor} to iterate over entries in the hash.
*
* @param options * @param options
* @return * @return
* @since 1.4 * @since 1.4

View File

@@ -1,5 +1,5 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import org.springframework.data.redis.connection.DataType;
* *
* @author Costin Leau * @author Costin Leau
* @author Christoph Strobl * @author Christoph Strobl
* @author Ninad Divadkar
*/ */
class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H> implements class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H> implements
BoundHashOperations<H, HK, HV> { BoundHashOperations<H, HK, HV> {

View File

@@ -1,5 +1,5 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.springframework.data.redis.connection.RedisConnection;
* *
* @author Costin Leau * @author Costin Leau
* @author Christoph Strobl * @author Christoph Strobl
* @author Ninad Divadkar
*/ */
class DefaultHashOperations<K, HK, HV> extends AbstractOperations<K, Object> implements HashOperations<K, HK, HV> { class DefaultHashOperations<K, HK, HV> extends AbstractOperations<K, Object> implements HashOperations<K, HK, HV> {

View File

@@ -1,5 +1,5 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -25,40 +25,135 @@ import java.util.Set;
* *
* @author Costin Leau * @author Costin Leau
* @author Christoph Strobl * @author Christoph Strobl
* @author Ninad Divadkar
*/ */
public interface HashOperations<H, HK, HV> { public interface HashOperations<H, HK, HV> {
/**
* 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); 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); 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); 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<HV> multiGet(H key, Collection<HK> hashKeys); List<HV> multiGet(H key, Collection<HK> 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); 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); 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<HK> keys(H key); Set<HK> keys(H key);
/**
* Get size of hash at {@code key}.
*
* @param key must not be {@literal null}.
* @return
*/
Long size(H key); 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<? extends HK, ? extends HV> m); void putAll(H key, Map<? extends HK, ? extends HV> 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); 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); 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<HV> values(H key); List<HV> values(H key);
/**
* Get entire hash stored at {@code key}.
*
* @param key must not be {@literal null}.
* @return
*/
Map<HK, HV> entries(H key); Map<HK, HV> entries(H key);
/**
* @return
*/
RedisOperations<H, ?> getOperations(); RedisOperations<H, ?> getOperations();
/** /**
* Use a {@link Cursor} to iterate over entries in hash at {@code key}.
*
* @since 1.4 * @since 1.4
* @param key * @param key must not be {@literal null}.
* @param options * @param options
* @return * @return
*/ */

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Jennifer Hickey
* @author Christoph Strobl * @author Christoph Strobl
* @author Ninad Divadkar
* @param <K> Key type * @param <K> Key type
* @param <HK> Hash key type * @param <HK> Hash key type
* @param <HV> Hash value type * @param <HV> Hash value type
@@ -136,7 +137,7 @@ public class DefaultHashOperationsTests<K, HK, HV> {
hashOps.put(key, key2, val2); hashOps.put(key, key2, val2);
Long numDeleted = hashOps.delete(key, key1, key2); Long numDeleted = hashOps.delete(key, key1, key2);
assertTrue(hashOps.keys(key).isEmpty()); assertTrue(hashOps.keys(key).isEmpty());
assertEquals(2L, numDeleted.longValue()); assertEquals(2L, numDeleted.longValue());
} }
/** /**