Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RLexSortedSet object introduced. #135
- Loading branch information
Nikita
committed
Sep 14, 2015
1 parent
3ab7e1a
commit 1bfc3a7
Showing
18 changed files
with
277 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,142 @@ | |||
/** | |||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit | |||
* | |||
* 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. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.redisson; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.List; | |||
|
|||
import org.redisson.client.codec.StringCodec; | |||
import org.redisson.client.protocol.RedisCommands; | |||
import org.redisson.core.RLexSortedSet; | |||
|
|||
import io.netty.util.concurrent.Future; | |||
|
|||
public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implements RLexSortedSet { | |||
|
|||
public RedissonLexSortedSet(CommandExecutor commandExecutor, String name) { | |||
super(StringCodec.INSTANCE, commandExecutor, name); | |||
} | |||
|
|||
@Override | |||
public Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { | |||
return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive)); | |||
} | |||
|
|||
@Override | |||
public Collection<String> lexRangeHead(String toElement, boolean toInclusive) { | |||
return get(lexRangeHeadAsync(toElement, toInclusive)); | |||
} | |||
|
|||
@Override | |||
public Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive) { | |||
String toValue = value(toElement, toInclusive); | |||
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue); | |||
} | |||
|
|||
@Override | |||
public Collection<String> lexRangeTail(String fromElement, boolean fromInclusive) { | |||
return get(lexRangeTailAsync(fromElement, fromInclusive)); | |||
} | |||
|
|||
@Override | |||
public Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive) { | |||
String fromValue = value(fromElement, fromInclusive); | |||
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+"); | |||
} | |||
|
|||
|
|||
@Override | |||
public Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { | |||
String fromValue = value(fromElement, fromInclusive); | |||
String toValue = value(toElement, toInclusive); | |||
|
|||
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue); | |||
} | |||
|
|||
@Override | |||
public Integer lexCountTail(String fromElement, boolean fromInclusive) { | |||
return get(lexCountTailAsync(fromElement, fromInclusive)); | |||
} | |||
|
|||
@Override | |||
public Future<Integer> lexCountTailAsync(String fromElement, boolean fromInclusive) { | |||
String fromValue = value(fromElement, fromInclusive); | |||
|
|||
return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), fromValue, "+"); | |||
} | |||
|
|||
@Override | |||
public Integer lexCountHead(String toElement, boolean toInclusive) { | |||
return get(lexCountHeadAsync(toElement, toInclusive)); | |||
} | |||
|
|||
@Override | |||
public Future<Integer> lexCountHeadAsync(String toElement, boolean toInclusive) { | |||
String toValue = value(toElement, toInclusive); | |||
|
|||
return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), "-", toValue); | |||
} | |||
|
|||
@Override | |||
public Integer lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { | |||
return get(lexCountAsync(fromElement, fromInclusive, toElement, toInclusive)); | |||
} | |||
|
|||
@Override | |||
public Future<Integer> lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) { | |||
String fromValue = value(fromElement, fromInclusive); | |||
String toValue = value(toElement, toInclusive); | |||
|
|||
return commandExecutor.readAsync(getName(), RedisCommands.ZLEXCOUNT, getName(), fromValue, toValue); | |||
} | |||
|
|||
private String value(String fromElement, boolean fromInclusive) { | |||
String fromValue = fromElement.toString(); | |||
if (fromInclusive) { | |||
fromValue = "[" + fromValue; | |||
} else { | |||
fromValue = "(" + fromValue; | |||
} | |||
return fromValue; | |||
} | |||
|
|||
@Override | |||
public Future<Boolean> addAsync(String e) { | |||
return addAsync(0, e); | |||
} | |||
|
|||
@Override | |||
public Future<Boolean> addAllAsync(Collection<? extends String> c) { | |||
List<Object> params = new ArrayList<Object>(2*c.size()); | |||
for (Object param : c) { | |||
params.add(0); | |||
params.add(param); | |||
} | |||
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZADD, getName(), params.toArray()); | |||
} | |||
|
|||
@Override | |||
public boolean add(String e) { | |||
return get(addAsync(e)); | |||
} | |||
|
|||
@Override | |||
public boolean addAll(Collection<? extends String> c) { | |||
return get(addAllAsync(c)); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.