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

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

Go to download

A library that provides a distributed storage abstraction and client-coordinated distributed transaction manager on the storage.

There is a newer version: 3.13.0
Show newest version
package com.scalar.database.api;

import com.google.common.base.MoreObjects;
import com.scalar.database.io.Key;
import com.scalar.database.io.Value;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;

/**
 * An abstraction for the selection operations such as {@link Get} and {@link Scan}.
 *
 * @author Hiroyuki Yamada
 */
public abstract class Selection extends Operation {
  private List projections;

  public Selection(Key partitionKey, Key clusteringKey) {
    super(partitionKey, clusteringKey);
    projections = new ArrayList<>();
  }

  /**
   * Appends the specified name of {@link Value} to the list of projections.
   *
   * @param projection a name of {@code Value} to project
   * @return this object
   */
  public Selection withProjection(String projection) {
    projections.add(projection);
    return this;
  }

  /**
   * Appends the specified collection of the specified names of {@code Value}s to the list of
   * projections.
   *
   * @param projections a collection of the name of {@code Value}s to project
   * @return this object
   */
  public Selection withProjections(Collection projections) {
    projections.forEach(p -> this.projections.add(p));
    return this;
  }

  public void clearProjections() {
    projections.clear();
  }

  @Nonnull
  public List getProjections() {
    // TODO: use guava immutable.of
    return Collections.unmodifiableList(projections);
  }

  /**
   * Indicates whether some other object is "equal to" this object. The other object is considered
   * equal if:
   *
   * 
    *
  • both super class instances are equal and *
  • it is also an {@code Selection} and *
  • both instances have the same projections *
* * @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 (!super.equals(o)) { return false; } if (o == this) { return true; } if (!(o instanceof Selection)) { return false; } Selection other = (Selection) o; if (projections.equals(other.projections)) { return true; } return false; } @Override public String toString() { return MoreObjects.toStringHelper(this) .add("namespace", forNamespace()) .add("table", forTable()) .add("partitionKey", getPartitionKey()) .add("clusteringKey", getClusteringKey()) .add("projections", getProjections()) .add("consistency", getConsistency()) .toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy