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

edu.isi.nlp.io.MapOffsetIndex Maven / Gradle / Ivy

The newest version!
package edu.isi.nlp.io;

import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import edu.isi.nlp.strings.offsets.ByteOffset;
import edu.isi.nlp.strings.offsets.OffsetRange;
import edu.isi.nlp.symbols.Symbol;
import java.util.Map;
import java.util.Set;

/* package-private */ class MapOffsetIndex implements OffsetIndex {

  private final ImmutableMap> map;

  private MapOffsetIndex(final Map> map) {
    this.map = ImmutableMap.copyOf(map);
  }

  public static MapOffsetIndex fromMap(Map> map) {
    return new MapOffsetIndex(map);
  }

  @Override
  public Optional> byteOffsetsOf(final Symbol key) {
    return Optional.fromNullable(map.get(key));
  }

  @Override
  public Set keySet() {
    return map.keySet();
  }

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

  @Override
  public boolean equals(final Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
      return false;
    }
    final MapOffsetIndex other = (MapOffsetIndex) obj;
    return Objects.equal(this.map, other.map);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy