org.redisson.api.condition.Conditions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-all Show documentation
Show all versions of redisson-all Show documentation
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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.api.condition;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.redisson.liveobject.condition.ANDCondition;
import org.redisson.liveobject.condition.EQCondition;
import org.redisson.liveobject.condition.GECondition;
import org.redisson.liveobject.condition.GTCondition;
import org.redisson.liveobject.condition.LECondition;
import org.redisson.liveobject.condition.LTCondition;
import org.redisson.liveobject.condition.ORCondition;
/**
* Conditions factory to search for Live Objects by fields.
*
* @author Nikita Koksharov
*
*/
public final class Conditions {
/**
* Returns "IN" condition for property by name
and allowed set of values
*
* @param name - name of property
* @param values - array of allowed values
* @return condition
*/
public static Condition in(String name, Object... values) {
List conditions = new ArrayList();
for (Object value : values) {
conditions.add(eq(name, value));
}
return or(conditions.toArray(new Condition[conditions.size()]));
}
/**
* Returns "IN" condition for property by name
and allowed set of values
*
* @param name - name of property
* @param values - collection of allowed values
* @return condition
*/
public static Condition in(String name, Collection> values) {
List conditions = new ArrayList();
for (Object value : values) {
conditions.add(eq(name, value));
}
return or(conditions.toArray(new Condition[conditions.size()]));
}
/**
* Returns "EQUALS" condition which restricts property by name
to defined value
*
* @param name - name of property
* @param value - defined value
* @return condition
*/
public static Condition eq(String name, Object value) {
return new EQCondition(name, value);
}
/**
* Returns "OR" condition for collection of nested conditions
*
* @param conditions - nested condition objects
* @return condition
*/
public static Condition or(Condition... conditions) {
return new ORCondition(conditions);
}
/**
* Returns "AND" condition for collection of nested conditions
*
* @param conditions - nested condition objects
* @return condition
*/
public static Condition and(Condition... conditions) {
return new ANDCondition(conditions);
}
/**
* Returns "GREATER THAN" condition which restricts property by name
to defined value
*
* @param name - name of property
* @param value - defined value
* @return condition
*/
public static Condition gt(String name, Number value) {
return new GTCondition(name, value);
}
/**
* Returns "LESS THAN" condition which restricts property by name
to defined value
*
* @param name - name of property
* @param value - defined value
* @return condition
*/
public static Condition lt(String name, Number value) {
return new LTCondition(name, value);
}
/**
* Returns "GREATER THAN ON EQUAL" condition which restricts property by name
to defined value
*
* @param name - name of property
* @param value - defined value
* @return condition
*/
public static Condition ge(String name, Number value) {
return new GECondition(name, value);
}
/**
* Returns "LESS THAN ON EQUAL" condition which restricts property by name
to defined value
*
* @param name - name of property
* @param value - defined value
* @return condition
*/
public static Condition le(String name, Number value) {
return new LECondition(name, value);
}
private Conditions() {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy