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

org.sirix.api.Move Maven / Gradle / Ivy

package org.sirix.api;

import static com.google.common.base.Preconditions.checkNotNull;
import java.util.NoSuchElementException;
import java.util.Optional;

/**
 * Determines if the {@link NodeCursor} moved to a node or not. Based on the idea of providing a
 * wrapper just like in Google Guava's {@link Optional} class.
 *
 * @author Johannes Lichtenberger
 *
 * @param  type parameter, the cursor
 */
public abstract class Move {
  /**
   * Returns a {@link Moved} instance with no contained reference.
   *
   * @param  type of NodeCursor
   * @return Move Move of NodeCursor
   */
  @SuppressWarnings("unchecked")
  public static  Move notMoved() {
    return (Move) NotMoved.INSTANCE;
  }

  /**
   * Returns a {@code Moved} instance containing the given non-null reference.
   * @param  type of NodeCursor
   * @param moved reference to get Moved instance for
   * @return Move Move of NodeCursor
   */
  public static  Moved moved(final T moved) {
    return new Moved(checkNotNull(moved));
  }

  /**
   * Determines if the cursor has moved.
   *
   * @return {@code true} if it has moved, {@code false} otherwise
   */
  public abstract boolean hasMoved();

  /**
   * Get the cursor reference.
   *
   * @return cursor reference
   * @throws NoSuchElementException if the cursor couldn't be moved
   */
  public abstract T trx();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy