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

com.scalar.db.sql.TableRef Maven / Gradle / Ivy

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.sql;

import com.google.common.base.MoreObjects;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/** A table reference. */
@Immutable
public class TableRef {

  @Nullable public final String namespaceName;
  public final String tableName;

  private TableRef(@Nullable String namespaceName, String tableName) {
    this.namespaceName = namespaceName;
    this.tableName = Objects.requireNonNull(tableName);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof TableRef)) {
      return false;
    }
    TableRef table = (TableRef) o;
    return Objects.equals(namespaceName, table.namespaceName) && tableName.equals(table.tableName);
  }

  @Override
  public int hashCode() {
    return Objects.hash(namespaceName, tableName);
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper(this)
        .add("namespaceName", namespaceName)
        .add("tableName", tableName)
        .toString();
  }

  /**
   * Returns a {@code TableRef} object with the specified table name.
   *
   * @param tableName a table name
   * @return a {@code TableRef} object
   */
  public static TableRef of(String tableName) {
    return new TableRef(null, tableName);
  }

  /**
   * Returns a {@code TableRef} object with the specified namespace name and table name.
   *
   * @param namespaceName a namespace name
   * @param tableName a table name
   * @return a {@code TableRef} object
   */
  public static TableRef of(@Nullable String namespaceName, String tableName) {
    return new TableRef(namespaceName, tableName);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy