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

com.scalar.database.api.PutIf Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0-alpha.1
Show newest version
package com.scalar.database.api;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

/**
 * An optional parameter of {@link Put} for conditional put. {@link Put} with this condition makes
 * the operation take effect only if a specified condition is met.
 */
@Immutable
public class PutIf implements MutationCondition {
  private final List expressions;

  /**
   * Constructs a {@code PutIf} with the specified conditional expressions.
   *
   * @param expressions a variable length expressions specified with {@code ConditionalExpression}s
   */
  public PutIf(ConditionalExpression... expressions) {
    checkNotNull(expressions);
    this.expressions = new ArrayList<>(expressions.length);
    Arrays.stream(expressions).forEach(v -> this.expressions.add(v));
  }

  /**
   * Returns the immutable list of conditional expressions.
   *
   * @return an immutable list of conditional expressions
   */
  @Override
  @Nonnull
  public List getExpressions() {
    return ImmutableList.copyOf(expressions);
  }

  @Override
  public void accept(MutationConditionVisitor visitor) {
    visitor.visit(this);
  }

  /**
   * Indicates whether some other object is "equal to" this object. The other object is considered
   * equal if:
   *
   * 
    *
  • it is also an {@code PutIf} and *
  • both instances have the same expressions *
* * @param o an object to be tested for equality * @return {@code true} if the other object is "equal to" this object otherwise {@code false} */ @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof PutIf)) { return false; } PutIf other = (PutIf) o; return expressions.equals(other.expressions); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy