package net.sf.jasperreports.engine.util;

import java.io.Serializable;

public class Pair implements Serializable {
  private static final long serialVersionUID = 1L;
  
  private final Object o1;
  
  private final Object o2;
  
  private final int hash;
  
  public Pair(Object o1, Object o2) {
    this.o1 = o1;
    this.o2 = o2;
    this.hash = computeHash();
  }
  
  private int computeHash() {
    int hashCode = (this.o1 == null) ? 0 : this.o1.hashCode();
    hashCode *= 31;
    hashCode += (this.o2 == null) ? 0 : this.o2.hashCode();
    return hashCode;
  }
  
  public boolean equals(Object o) {
    if (o == this)
      return true; 
    if (o == null || !(o instanceof Pair))
      return false; 
    Pair p = (Pair)o;
    if ((p.o1 == null) ? (this.o1 == null) : (this.o1 != null && p.o1.equals(this.o1)))
      if ((p.o2 == null) ? (this.o2 == null) : (this.o2 != null && p.o2.equals(this.o2))); 
    return false;
  }
  
  public int hashCode() {
    return this.hash;
  }
  
  public String toString() {
    return "(" + String.valueOf(this.o1) + ", " + String.valueOf(this.o2) + ")";
  }
}
