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

io.sirix.index.SearchMode Maven / Gradle / Ivy

package io.sirix.index;

import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Comparator;

/**
 * The search mode in a datastructure.
 *
 * @author Johannes Lichtenberger
 *
 */
public enum SearchMode {
  /** Greater than the specified key. */
  GREATER {
    @Override
    public > int compare(K firstKey, @NonNull K secondKey) {
      return secondKey.compareTo(firstKey) > 0 ? 0 : -1;
    }

    @Override
    public > int compare(K firstKey, K secondKey,
        Comparator comparator) {
      return comparator.compare(secondKey, firstKey) > 0 ? 0 : -1;
    }
  },

  /** Lower than the specified key. */
  LOWER {
    @Override
    public > int compare(K firstKey, @NonNull K secondKey) {
      return secondKey.compareTo(firstKey) < 0 ? 0 : -1;
    }

    @Override
    public > int compare(K firstKey, K secondKey,
        Comparator comparator) {
      return comparator.compare(secondKey, firstKey) < 0 ? 0 : -1;
    }
  },

  /** Greater or equal than the specified key. */
  GREATER_OR_EQUAL {
    @Override
    public > int compare(K firstKey, @NonNull K secondKey) {
      return secondKey.compareTo(firstKey) >= 0 ? 0 : -1;
    }

    @Override
    public > int compare(K firstKey, K secondKey,
        Comparator comparator) {
      return comparator.compare(secondKey, firstKey) >= 0 ? 0 : -1;
    }
  },

  /** Lower or equal than the specified key. */
  LOWER_OR_EQUAL {
    @Override
    public > int compare(K firstKey, @NonNull K secondKey) {
      return secondKey.compareTo(firstKey) <= 0 ? 0 : -1;
    }

    @Override
    public > int compare(K firstKey, K secondKey,
        Comparator comparator) {
      return comparator.compare(secondKey, firstKey) <= 0 ? 0 : -1;
    }
  },

  /** Equal to the specified key. */
  EQUAL {
    @Override
    public > int compare(K firstKey, @NonNull K secondKey) {
      return firstKey.compareTo(secondKey);
    }

    @Override
    public > int compare(K firstKey, K secondKey,
        Comparator comparator) {
      return comparator.compare(firstKey, secondKey);
    }
  };

  /**
   * Compare two keys.
   *
   * @param firstKey the search key
   * @param secondKey the potential result key
   * @return {@code 0} if it's in the search space, else {@code -1} or {@code +1}
   */
  public abstract > int compare(final K firstKey,
      final K secondKey);

  public abstract > int compare(final K firstKey, final K secondKey,
      final Comparator comparator);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy