com.speedment.runtime.field.predicate.CombinedPredicate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of runtime-deploy Show documentation
Show all versions of runtime-deploy Show documentation
A Speedment bundle that shades all dependencies into one jar. This is
useful when deploying an application on a server.
/**
*
* Copyright (c) 2006-2019, Speedment, Inc. All Rights Reserved.
*
* 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 com.speedment.runtime.field.predicate;
import com.speedment.runtime.field.internal.predicate.AbstractCombinedPredicate;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
* Aggregation of a number of {@link Predicate Predicates} of the same type
* (e.g. AND or OR) that can be applied in combination.
*
* @param the entity type
*
* @author Per Minborg
* @author Emil Forslund
*/
public interface CombinedPredicate extends SpeedmentPredicate {
/**
* This enum list all the different types of combinations
*/
enum Type {
AND, OR
}
/**
* Creates and returns a {link Stream} of all predicates that this
* CombinedPredicate holds.
*
* @return a {link Stream} of all predicates that this CombinedPredicate
* holds
*/
Stream> stream();
/**
* Returns the number of predicates that this CombinedBasePredicate holds
*
* @return the number of predicates that this CombinedBasePredicate holds
*/
int size();
/**
* Returns the {@link Type} of this CombinedBasePredicate
*
* @return the {@link Type} of this CombinedBasePredicate
*/
Type getType();
@Override
CombinedPredicate and(Predicate other);
@Override
CombinedPredicate or(Predicate other);
@Override
CombinedPredicate negate();
/**
* Creates and returns a new CombinedPredicate that is the logical AND
* combination of the given predicates.
*
* @param entity type
* @param first the first predicate used in the AND operation
* @param second the first predicate used in the AND operation
* @return a new CombinedPredicate that is the logical AND combination of
* the given predicates
*/
static CombinedPredicate and(Predicate first, Predicate second) {
@SuppressWarnings("unchecked")
final Predicate secondCasted = (Predicate) second;
return new AbstractCombinedPredicate.AndCombinedBasePredicate<>(
Arrays.asList(first, secondCasted)
);
}
/**
* Creates and returns a new CombinedPredicate that is the logical AND
* combination of the given predicates.
*
* @param entity type
* @param predicates the predicates that make up the AND operation
* @return a new CombinedPredicate that is the logical AND combination of
* the given predicates
*/
static CombinedPredicate and(List> predicates) {
return new AbstractCombinedPredicate.AndCombinedBasePredicate<>(predicates);
}
/**
* Creates and returns a new CombinedPredicate that is the logical OR
* combination of the given predicates.
*
* @param entity type
* @param first the first predicate used in the OR operation
* @param second the first predicate used in the OR operation
* @return a new CombinedPredicate that is the logical OR combination of the
* given predicates
*/
static CombinedPredicate or(Predicate first, Predicate second) {
@SuppressWarnings("unchecked")
final Predicate secondCasted = (Predicate) second;
return new AbstractCombinedPredicate.OrCombinedBasePredicate<>(
Arrays.asList(first, secondCasted)
);
}
/**
* Creates or returns a new CombinedPredicate that is the logical OR
* combination of the given predicates.
*
* @param entity type
* @param predicates the predicates that make up the OR operation
* @return a new CombinedPredicate that is the logical OR combination of
* the given predicates
*/
static CombinedPredicate or(List> predicates) {
return new AbstractCombinedPredicate.OrCombinedBasePredicate<>(predicates);
}
}