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

org.immutables.criteria.expression.SimpleCall Maven / Gradle / Ivy

/*
 * Copyright 2019 Immutables Authors and Contributors
 *
 * 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.immutables.criteria.expression;

import com.google.common.collect.ImmutableList;

import javax.annotation.Nullable;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Objects;

/**
 * Simple implementation of {@link Call}
 */
class SimpleCall implements Call {

  private final List arguments;
  private final Operator operator;

  SimpleCall(List arguments, Operator operator) {
    this.arguments = ImmutableList.copyOf(arguments);
    this.operator = Objects.requireNonNull(operator, "operator");
  }

  @Override
  public List arguments() {
    return arguments;
  }

  @Override
  public Operator operator() {
    return operator;
  }

  @Nullable
  @Override
  public  R accept(ExpressionBiVisitor visitor, @Nullable C context) {
    return visitor.visit(this, context);
  }

  @Override
  public Type returnType() {
    return operator.returnType();
  }

  @Override
  public String toString() {
    final StringWriter writer = new StringWriter();
    final PrintWriter printer = new PrintWriter(writer);
    printer.append(SimpleCall.class.getSimpleName());
    printer.append("{");
    printer.println(operator().name());
    DebugExpressionVisitor debug = new DebugExpressionVisitor<>(printer);
    arguments().forEach(a -> {
      printer.println();
      a.accept(debug);
    });
    printer.append("}");
    return writer.toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy