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

com.github.liblevenshtein.transducer.Transducer Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package com.github.liblevenshtein.transducer;

import java.io.Serializable;
import java.util.Objects;

/**
 * This wrapper around {@link LazyTransducerCollection}, which handles all the
 * heavy lifting.
 *
 * @author Dylon Edwards
 * @param  Kind of nodes of the dictionary automaton.
 * @param  Kind of the spelling candidates returned from the
 *   dictionary.
 * @since 2.1.0
 */
public class Transducer
  implements ITransducer, Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * Attributes required for this transducer to search the dictionary.
   */
  private TransducerAttributes attributes;

  public Transducer(TransducerAttributes attributes) {
    this.attributes = attributes;
  }

  public TransducerAttributes attributes() {
    return attributes;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Iterable transduce(final String term) {
    return transduce(term, attributes.maxDistance());
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public Iterable transduce(
      final String term,
      final int maxDistance) {
    return new LazyTransducerCollection(
        term, maxDistance, attributes);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Transducer that = (Transducer) o;
    return Objects.equals(attributes, that.attributes);
  }

  @Override
  public int hashCode() {

    return Objects.hash(attributes);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy