All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.speedment.runtime.field.predicate.CombinedPredicate Maven / Gradle / Ivy

Go to download

Partly generated model of the fields that represent columns in the database. Fields can be used to produce special predicates and functions that contain metadata that Speedment can analyze runtime.

There is a newer version: 3.2.10
Show newest version
/**
 *
 * Copyright (c) 2006-2017, 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.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 Predicate {

    /**
     * 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 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)
        );
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy