DATAREDIS-407 - Polishing.

Updated license header, added missing Javadoc, fix indentation and organized imports.

Original Pull Request: #166
This commit is contained in:
Christoph Strobl
2016-02-09 12:11:35 +01:00
parent 4131f501a6
commit 97b88979e7
9 changed files with 159 additions and 64 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");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,8 @@ package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Set;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
/**
@@ -53,9 +54,26 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
Set<TypedTuple<V>> reverseRangeByScoreWithScores(double min, double max);
Set<V> rangeByLex(RedisZSetCommands.Range range);
/**
* Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @since 1.7
*/
Set<V> rangeByLex(Range range);
Set<V> rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit);
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return
* @since 1.7
*/
Set<V> rangeByLex(Range range, Limit limit);
void removeRange(long start, long end);

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");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@ import java.util.Collection;
import java.util.Set;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
/**
@@ -97,13 +98,21 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.reverseRangeWithScores(getKey(), start, end);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<V> rangeByLex(RedisZSetCommands.Range range) {
return ops.rangeByLex(getKey(), range);
public Set<V> rangeByLex(Range range) {
return rangeByLex(range, null);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<V> rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) {
public Set<V> rangeByLex(Range range, Limit limit) {
return ops.rangeByLex(getKey(), range, limit);
}

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");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@ import java.util.Set;
import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
/**
@@ -143,23 +144,21 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
return deserializeTupleValues(rawValues);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<V> rangeByLex(K key, final RedisZSetCommands.Range range) {
final byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
public Set<byte[]> doInRedis(RedisConnection connection) {
return connection.zRangeByLex(rawKey, range);
}
}, true);
return deserializeValues(rawValues);
public Set<V> rangeByLex(K key, final Range range) {
return rangeByLex(key, range, null);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<V> rangeByLex(K key, final RedisZSetCommands.Range range, final RedisZSetCommands.Limit limit) {
public Set<V> rangeByLex(K key, final Range range, final Limit limit) {
final byte[] rawKey = rawKey(key);

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");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,8 @@ package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Set;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
/**
* Redis ZSet/sorted set specific operations.
@@ -55,9 +56,28 @@ public interface ZSetOperations<K, V> {
Set<TypedTuple<V>> reverseRangeWithScores(K key, long start, long end);
Set<V> rangeByLex(K key, RedisZSetCommands.Range range);
/**
* Get all elements with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}.
* @param range must not be {@literal null}.
* @since 1.7
*/
Set<V> rangeByLex(K key, Range range);
Set<V> rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit);
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return
* @since 1.7
*/
Set<V> rangeByLex(K key, Range range, Limit limit);
Set<V> rangeByScore(K key, double min, double max);

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");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@ import java.util.Set;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.ConvertingCursor;
import org.springframework.data.redis.core.Cursor;
@@ -116,13 +117,21 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
return boundZSetOps.reverseRange(start, end);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<E> rangeByLex(RedisZSetCommands.Range range) {
public Set<E> rangeByLex(Range range) {
return boundZSetOps.rangeByLex(range);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<E> rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) {
public Set<E> rangeByLex(Range range, Limit limit) {
return boundZSetOps.rangeByLex(range, limit);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 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.
@@ -22,7 +22,9 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedSet;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
/**
@@ -33,6 +35,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
*
* @author Costin Leau
* @author Mark Paluch
* @auhtor Christoph Strobl
*/
public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
@@ -48,9 +51,29 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
Set<E> reverseRange(long start, long end);
Set<E> rangeByLex(RedisZSetCommands.Range range);
/**
* Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @return
* @see BoundZSetOperations#rangeByLex(Range)
* @since 1.7
*/
Set<E> rangeByLex(Range range);
Set<E> rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit);
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return
* @see BoundZSetOperations#rangeByLex(Range, Limit)
* @since 1.7
*/
Set<E> rangeByLex(Range range, Limit limit);
Set<E> rangeByScore(double min, double max);

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");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,9 @@ package org.springframework.data.redis.core;
import static org.hamcrest.core.AnyOf.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.Collection;
@@ -179,8 +179,10 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexUnbounded() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -203,8 +205,10 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexBounded() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -227,8 +231,10 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexUnboundedWithLimit() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -252,8 +258,10 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexBoundedWithLimit() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -263,8 +271,8 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1), RedisZSetCommands.Limit
.limit().count(1).offset(1));
assertEquals(1, tuples.size());
V tuple = tuples.iterator().next();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 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.
@@ -332,8 +332,10 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnbounded() {
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -355,8 +357,10 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBounded() {
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -378,8 +382,10 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexUnboundedWithLimit() {
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -388,8 +394,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(),
RedisZSetCommands.Limit.limit().count(1).offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();
@@ -402,8 +408,10 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@Test
public void testRangeByLexBoundedWithLimit() {
assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(
factory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
T t1 = getT();
T t2 = getT();
@@ -412,8 +420,8 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), RedisZSetCommands.Limit.limit().count(1)
.offset(1));
assertEquals(1, tuples.size());
T tuple = tuples.iterator().next();

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");
* you may not use this file except in compliance with the License.
@@ -233,7 +233,8 @@ public abstract class CollectionTestParams {
{ personFactory, jackson2JsonPersonTemplateJR },
{ rawFactory, rawTemplateJR },
// srp
{ stringFactory, stringTemplateSRP }, { personFactory, personTemplateSRP },
{ stringFactory, stringTemplateSRP },
{ personFactory, personTemplateSRP },
{ stringFactory, xstreamStringTemplateSRP },
{ personFactory, xstreamPersonTemplateSRP },
{ personFactory, jsonPersonTemplateSRP },