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:
@@ -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<H, HK, HV> extends BoundKeyOperations<H> {
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
RedisOperations<H, ?> 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<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);
|
||||
|
||||
/**
|
||||
* Get key set (fields) of the hash.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Set<HK> keys();
|
||||
|
||||
/**
|
||||
* Get entry set (values) of hash.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<HV> 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<HK, HV> entries();
|
||||
|
||||
/**
|
||||
* Use a {@link Cursor} to iterate over entries in the hash.
|
||||
*
|
||||
* @param options
|
||||
* @return
|
||||
* @since 1.4
|
||||
|
||||
@@ -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<H, HK, HV> extends DefaultBoundKeyOperations<H> implements
|
||||
BoundHashOperations<H, HK, HV> {
|
||||
@@ -36,7 +37,7 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H>
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundHashOperations</code> instance.
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param operations
|
||||
*/
|
||||
|
||||
@@ -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<K, HK, HV> extends AbstractOperations<K, Object> implements HashOperations<K, HK, HV> {
|
||||
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
/**
|
||||
* 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<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);
|
||||
|
||||
/**
|
||||
* 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<HK> 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<? 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);
|
||||
|
||||
/**
|
||||
* 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<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);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
RedisOperations<H, ?> 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
|
||||
*/
|
||||
|
||||
@@ -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 <K> Key type
|
||||
* @param <HK> Hash key type
|
||||
* @param <HV> Hash value type
|
||||
@@ -136,7 +137,7 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user