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

hydra.compute.Coder Maven / Gradle / Ivy

package hydra.compute;

/**
 * An encoder and decoder; a bidirectional flow between two types
 */
public class Coder {
  public static final hydra.core.Name NAME = new hydra.core.Name("hydra/compute.Coder");
  
  public final java.util.function.Function> encode;
  
  public final java.util.function.Function> decode;
  
  public Coder (java.util.function.Function> encode, java.util.function.Function> decode) {
    this.encode = encode;
    this.decode = decode;
  }
  
  @Override
  public boolean equals(Object other) {
    if (!(other instanceof Coder)) {
      return false;
    }
    Coder o = (Coder) (other);
    return encode.equals(o.encode) && decode.equals(o.decode);
  }
  
  @Override
  public int hashCode() {
    return 2 * encode.hashCode() + 3 * decode.hashCode();
  }
  
  public Coder withEncode(java.util.function.Function> encode) {
    return new Coder(encode, decode);
  }
  
  public Coder withDecode(java.util.function.Function> decode) {
    return new Coder(encode, decode);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy