// Copyright 2010-2021 Google LLC
// 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.google.ortools.sat;

import com.google.ortools.sat.CpModelProto;
import com.google.ortools.sat.TableConstraintProto;

/**
 * Specialized assignment constraint.
 *
 * <p>This constraint allows adding tuples to the allowed/forbidden assignment constraint
 * incrementally.
 */
public class TableConstraint extends Constraint {
  public TableConstraint(CpModelProto.Builder builder) {
    super(builder);
  }

  /**
   * Adds a tuple of possible/forbidden values to the constraint.
   *
   * @param tuple the tuple to add to the constraint.
   * @throws CpModel.WrongLength if the tuple does not have the same length as the array of
   *     variables of the constraint.
   */
  public void addTuple(int[] tuple) {
    TableConstraintProto.Builder table = getBuilder().getTableBuilder();
    if (tuple.length != table.getVarsCount()) {
      throw new CpModel.WrongLength(
          "addTuple", "tuple does not have the same length as the variables");
    }
    for (int value : tuple) {
      table.addValues(value);
    }
  }

  /**
   * Adds a tuple of possible/forbidden values to the constraint.
   *
   * @param tuple the tuple to add to the constraint.
   * @throws CpModel.WrongLength if the tuple does not have the same length as the array of
   *     variables of the constraint.
   */
  public void addTuple(long[] tuple) {
    TableConstraintProto.Builder table = getBuilder().getTableBuilder();
    if (tuple.length != table.getVarsCount()) {
      throw new CpModel.WrongLength(
          "addTuple", "tuple does not have the same length as the variables");
    }
    for (long value : tuple) {
      table.addValues(value);
    }
  }
}

@@ -2240,11 +2240,1402 @@
    %7D%0A  %7D
+%0A%0A  /**%0A   * Adds a list of tuples of possible/forbidden values to the constraint.%0A   *%0A   * @param tuples the list of tuples to add to the constraint.%0A   * @throws CpModel.WrongLength if one tuple does not have the same length as the array of%0A   *     variables of the constraint.%0A   */%0A  public void addTuples(int%5B%5D%5B%5D tuples) %7B%0A    TableConstraintProto.Builder table = getBuilder().getTableBuilder();%0A    for (int%5B%5D tuple : tuples %7B%0A      if (tuple.length != table.getVarsCount()) %7B%0A        throw new CpModel.WrongLength(%0A            %22addTuple%22, %22tuple does not have the same length as the variables%22);%0A      %7D%0A      for (int value : tuple) %7B%0A        table.addValues(value);%0A      %7D%0A    %7D%0A  %7D%0A%0A  /**%0A   * Adds a list of tuples of possible/forbidden values to the constraint.%0A   *%0A   * @param tuples the list of tuples to add to the constraint.%0A   * @throws CpModel.WrongLength if one tuple does not have the same length as the array of%0A   *     variables of the constraint.%0A   */%0A  public void addTuples(long%5B%5D%5B%5D tuples) %7B%0A    TableConstraintProto.Builder table = getBuilder().getTableBuilder();%0A    for (long%5B%5D tuple : tuples %7B%0A      if (tuple.length != table.getVarsCount()) %7B%0A        throw new CpModel.WrongLength(%0A            %22addTuple%22, %22tuple does not have the same length as the variables%22);%0A      %7D%0A      for (long value : tuple) %7B%0A        table.addValues(value);%0A      %7D%0A    %7D%0A  %7D
 %0A%7D%0A

add TableConstraint.addTuples in java CP-SAT