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

io.sirix.index.redblacktree.RBNodeValue Maven / Gradle / Ivy

Go to download

SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.

There is a newer version: 0.11.0
Show newest version
package io.sirix.index.redblacktree;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import io.sirix.index.redblacktree.interfaces.MutableRBNodeValue;
import io.sirix.node.AbstractForwardingNode;
import io.sirix.node.NodeKind;
import io.sirix.node.SirixDeweyID;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import io.sirix.node.delegates.NodeDelegate;
import io.sirix.settings.Fixed;

import static java.util.Objects.requireNonNull;

/**
 * Red-black tree node which is mutable.
 *
 * @author Johannes Lichtenberger
 */
public final class RBNodeValue extends AbstractForwardingNode
    implements MutableRBNodeValue {
  /** The value. */
  private V value;

  /** Reference to the left node. */
  private static final long LEFT = Fixed.NULL_NODE_KEY.getStandardProperty();

  /** Reference to the right node. */
  private static final long RIGHT = Fixed.NULL_NODE_KEY.getStandardProperty();

  /** {@link NodeDelegate} reference. */
  private NodeDelegate nodeDelegate;

  /**
   * Constructor.
   *
   * @param value the value
   * @param nodeDelegate the used node delegate
   */
  public RBNodeValue(final V value, final NodeDelegate nodeDelegate) {
    this.value = requireNonNull(value);
    this.nodeDelegate = requireNonNull(nodeDelegate);
  }

  @Override
  public NodeKind getKind() {
    return NodeKind.RB_NODE_VALUE;
  }

  @Override
  protected @NonNull NodeDelegate delegate() {
    return nodeDelegate;
  }

  @Override
  public V getValue() {
    return value;
  }

  @Override
  public boolean hasLeftChild() {
    return LEFT != Fixed.NULL_NODE_KEY.getStandardProperty();
  }

  @Override
  public boolean hasRightChild() {
    return RIGHT != Fixed.NULL_NODE_KEY.getStandardProperty();
  }

  @Override
  public long getLeftChildKey() {
    return LEFT;
  }

  @Override
  public long getRightChildKey() {
    return RIGHT;
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(nodeDelegate.getNodeKey());
  }

  @Override
  public boolean equals(final @Nullable Object obj) {
    if (obj instanceof RBNodeValue) {
      @SuppressWarnings("unchecked")
      final RBNodeValue other = (RBNodeValue) obj;
      return this.nodeDelegate.getNodeKey() == other.nodeDelegate.getNodeKey();
    }
    return false;
  }

  @Override
  public @NonNull String toString() {
    return MoreObjects.toStringHelper(this)
                      .add("node delegate", nodeDelegate)
                      .add("value", value)
                      .toString();
  }

  @Override
  public SirixDeweyID getDeweyID() {
    return null;
  }

  @Override
  public byte[] getDeweyIDAsBytes() {
    return null;
  }

  @Override
  public int getPreviousRevisionNumber() {
    throw new UnsupportedOperationException();
  }

  @Override
  public void setValue(V value) {
    this.value = value;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy