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

com.scalar.database.io.BooleanValue 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.io;

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

import com.google.common.base.MoreObjects;
import com.google.common.collect.ComparisonChain;
import javax.annotation.Nonnull;

/**
 * A {@code Value} for a boolean data
 *
 * @author Hiroyuki Yamada
 */
public final class BooleanValue implements Value {
  private static final String ANONYMOUS = "";
  private final String name;
  private final boolean value;

  /**
   * Constructs a {@code BooleanValue} with the specified name and value
   *
   * @param name name of the {@code Value}
   * @param value content of the {@code Value}
   */
  public BooleanValue(String name, boolean value) {
    this.name = checkNotNull(name);
    this.value = value;
  }

  /**
   * Constructs a {@code BooleanValue} with the specified value. The name of this value is
   * anonymous.
   *
   * @param value content of the {@code Value}
   */
  public BooleanValue(boolean value) {
    this(ANONYMOUS, value);
  }

  /**
   * Returns the content of this {@code Value}
   *
   * @return the content of this {@code Value}
   */
  public boolean get() {
    return value;
  }

  @Override
  @Nonnull
  public String getName() {
    return name;
  }

  @Override
  public BooleanValue copyWith(String name) {
    return new BooleanValue(name, value);
  }

  @Override
  public void accept(ValueVisitor v) {
    v.visit(this);
  }

  @Override
  public int hashCode() {
    return Boolean.hashCode(value);
  }

  /**
   * 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 BooleanValue} and *
  • both instances have the same name and value *
* * @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 BooleanValue)) { return false; } BooleanValue other = (BooleanValue) o; return (this.name.equals(other.name) && this.value == other.value); } @Override public String toString() { return MoreObjects.toStringHelper(this).add("name", name).add("value", value).toString(); } @Override public int compareTo(BooleanValue o) { return ComparisonChain.start() .compareFalseFirst(this.value, o.value) .compare(this.name, o.name) .result(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy