@SuppressWarnings("unchecked")
  public GenericPairComparator(TypeComparator<T1> comparator1, TypeComparator<T2> comparator2) {
    this.comparator1 = comparator1;
    this.comparator2 = comparator2;
    this.comparators1 = comparator1.getFlatComparators();
    this.comparators2 = comparator2.getFlatComparators();

    if (comparators1.length != comparators2.length) {
      throw new IllegalArgumentException("Number of key fields and comparators differ.");
    }

    int numKeys = comparators1.length;

    for (int i = 0; i < numKeys; i++) {
      this.comparators1[i] = comparators1[i].duplicate();
      this.comparators2[i] = comparators2[i].duplicate();
    }

    this.referenceKeyFields = new Object[numKeys];
    this.candidateKeyFields = new Object[numKeys];
  }