use of org.redisson.api.condition.Condition in project redisson by redisson.
the class LiveObjectSearch method traverseOr.
private Set<Object> traverseOr(ORCondition condition, NamingScheme namingScheme, Class<?> entityClass) {
Set<Object> allIds = new HashSet<Object>();
List<String> eqNames = new ArrayList<String>();
Map<RScoredSortedSet<Object>, Number> ltNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> leNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> gtNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> geNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> eqNumericNames = new HashMap<>();
for (Condition cond : condition.getConditions()) {
if (cond instanceof EQCondition) {
EQCondition eqc = (EQCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, eqc.getName());
if (eqc.getValue() instanceof Number) {
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
eqNumericNames.put(values, (Number) eqc.getValue());
} else {
RSetMultimap<Object, Object> map = new RedissonSetMultimap<>(namingScheme.getCodec(), commandExecutor, indexName);
RSet<Object> values = map.get(eqc.getValue());
eqNames.add(((RedissonObject) values).getRawName());
}
}
if (cond instanceof GTCondition) {
GTCondition gtc = (GTCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, gtc.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
gtNumericNames.put(values, gtc.getValue());
}
if (cond instanceof GECondition) {
GECondition gec = (GECondition) cond;
String indexName = namingScheme.getIndexName(entityClass, gec.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
geNumericNames.put(values, gec.getValue());
}
if (cond instanceof LTCondition) {
LTCondition ltc = (LTCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, ltc.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
ltNumericNames.put(values, ltc.getValue());
}
if (cond instanceof LECondition) {
LECondition lec = (LECondition) cond;
String indexName = namingScheme.getIndexName(entityClass, lec.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
leNumericNames.put(values, lec.getValue());
}
if (cond instanceof ANDCondition) {
Collection<Object> ids = traverseAnd((ANDCondition) cond, namingScheme, entityClass);
allIds.addAll(ids);
}
}
if (!eqNames.isEmpty()) {
RSet<Object> set = new RedissonSet<>(commandExecutor, eqNames.get(0), null);
allIds.addAll(set.readUnion(eqNames.toArray(new String[eqNames.size()])));
}
for (Entry<RScoredSortedSet<Object>, Number> e : eqNumericNames.entrySet()) {
Collection<Object> ids = e.getKey().valueRange(e.getValue().doubleValue(), true, e.getValue().doubleValue(), true);
allIds.addAll(ids);
}
for (Entry<RScoredSortedSet<Object>, Number> e : gtNumericNames.entrySet()) {
Collection<Object> ids = e.getKey().valueRange(e.getValue().doubleValue(), false, Double.POSITIVE_INFINITY, false);
allIds.addAll(ids);
}
for (Entry<RScoredSortedSet<Object>, Number> e : geNumericNames.entrySet()) {
Collection<Object> ids = e.getKey().valueRange(e.getValue().doubleValue(), true, Double.POSITIVE_INFINITY, false);
allIds.addAll(ids);
}
for (Entry<RScoredSortedSet<Object>, Number> e : ltNumericNames.entrySet()) {
Collection<Object> ids = e.getKey().valueRange(Double.NEGATIVE_INFINITY, false, e.getValue().doubleValue(), false);
allIds.addAll(ids);
}
for (Entry<RScoredSortedSet<Object>, Number> e : leNumericNames.entrySet()) {
Collection<Object> ids = e.getKey().valueRange(Double.NEGATIVE_INFINITY, false, e.getValue().doubleValue(), true);
allIds.addAll(ids);
}
return allIds;
}
use of org.redisson.api.condition.Condition in project redisson by redisson.
the class LiveObjectSearch method traverseAnd.
private Set<Object> traverseAnd(ANDCondition condition, NamingScheme namingScheme, Class<?> entityClass) {
Set<Object> allIds = new HashSet<Object>();
List<String> eqNames = new ArrayList<String>();
Map<RScoredSortedSet<Object>, Number> gtNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> geNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> ltNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> leNumericNames = new HashMap<>();
Map<RScoredSortedSet<Object>, Number> eqNumericNames = new HashMap<>();
for (Condition cond : condition.getConditions()) {
if (cond instanceof EQCondition) {
EQCondition eqc = (EQCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, eqc.getName());
if (eqc.getValue() instanceof Number) {
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
eqNumericNames.put(values, (Number) eqc.getValue());
} else {
RSetMultimap<Object, Object> map = new RedissonSetMultimap<>(namingScheme.getCodec(), commandExecutor, indexName);
RSet<Object> values = map.get(eqc.getValue());
eqNames.add(((RedissonObject) values).getRawName());
}
}
if (cond instanceof LTCondition) {
LTCondition ltc = (LTCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, ltc.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
ltNumericNames.put(values, ltc.getValue());
}
if (cond instanceof LECondition) {
LECondition lec = (LECondition) cond;
String indexName = namingScheme.getIndexName(entityClass, lec.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
leNumericNames.put(values, lec.getValue());
}
if (cond instanceof GECondition) {
GECondition gec = (GECondition) cond;
String indexName = namingScheme.getIndexName(entityClass, gec.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
geNumericNames.put(values, gec.getValue());
}
if (cond instanceof GTCondition) {
GTCondition gtc = (GTCondition) cond;
String indexName = namingScheme.getIndexName(entityClass, gtc.getName());
RScoredSortedSet<Object> values = new RedissonScoredSortedSet<>(namingScheme.getCodec(), commandExecutor, indexName, null);
gtNumericNames.put(values, gtc.getValue());
}
if (cond instanceof ORCondition) {
Collection<Object> ids = traverseOr((ORCondition) cond, namingScheme, entityClass);
if (ids.isEmpty()) {
return Collections.emptySet();
}
if (!allIds.isEmpty()) {
allIds.retainAll(ids);
} else {
allIds.addAll(ids);
}
if (allIds.isEmpty()) {
return Collections.emptySet();
}
}
}
if (!eqNames.isEmpty()) {
RSet<Object> set = new RedissonSet<>(commandExecutor, eqNames.get(0), null);
Set<Object> intersect = set.readIntersection(eqNames.toArray(new String[eqNames.size()]));
if (!allIds.isEmpty()) {
allIds.retainAll(intersect);
if (allIds.isEmpty()) {
return Collections.emptySet();
}
} else {
allIds.addAll(intersect);
}
if (allIds.isEmpty()) {
return allIds;
}
}
if (!checkValueRange(allIds, eqNumericNames, (r, v) -> {
return r.valueRange(v.doubleValue(), true, v.doubleValue(), true);
})) {
return Collections.emptySet();
}
if (!checkValueRange(allIds, gtNumericNames, (r, v) -> {
return r.valueRange(v.doubleValue(), false, Double.POSITIVE_INFINITY, false);
})) {
return Collections.emptySet();
}
if (!checkValueRange(allIds, geNumericNames, (r, v) -> {
return r.valueRange(v.doubleValue(), true, Double.POSITIVE_INFINITY, false);
})) {
return Collections.emptySet();
}
if (!checkValueRange(allIds, ltNumericNames, (r, v) -> {
return r.valueRange(Double.NEGATIVE_INFINITY, false, v.doubleValue(), false);
})) {
return Collections.emptySet();
}
if (!checkValueRange(allIds, leNumericNames, (r, v) -> {
return r.valueRange(Double.NEGATIVE_INFINITY, false, v.doubleValue(), true);
})) {
return Collections.emptySet();
}
return allIds;
}
Aggregations