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

io.resys.hdes.client.spi.expression.Operation Maven / Gradle / Ivy

There is a newer version: 3.130.78
Show newest version
package io.resys.hdes.client.spi.expression;

/*-
 * #%L
 * wrench-assets-dt
 * %%
 * Copyright (C) 2016 - 2019 Copyright 2016 ReSys OÜ
 * %%
 * 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.
 * #L%
 */

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

@FunctionalInterface
public interface Operation {
  Object apply(T entity);
    
  public static Builder builder() {
    return new Builder();
  }
  
  public static class Builder {
    
    @SuppressWarnings({"rawtypes", "unchecked"})
    public Operation and(Operation ... values) {
      Collection operations = Collections.unmodifiableList(Arrays.asList(values));
      return (Object parameter) -> {
          for(Operation value : operations) {
            if(!Boolean.TRUE.equals(value.apply(parameter))) {
              return false;
            }
          }
          return true;
      };
    }
    @SuppressWarnings({"rawtypes", "unchecked"})
    public Operation not(Operation values) {
      return (Object parameter) -> !Boolean.TRUE.equals(values.apply(parameter));
    }
  }
}