/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.core;

// TODO: doc what this is used for
public class CompoundKey
  implements Comparable
{
  private PropertyInfo[] properties_;
  private Object[]       values_;

  public CompoundKey(Object[] values, PropertyInfo[] properties) {
    values_     = values;
    properties_ = properties;
  }

  public Object[] getValues() { return values_; }

  public int compareTo(Object o) {
    CompoundKey other = (CompoundKey) o;
    int         result;

    for ( int i = 0 ; i < properties_.length ; i++ ) {
      result = properties_[i].compare(this, other);
      if ( result != 0 ) return result;
    }

    return 0;
  }

  public String toString() {
    StringBuilder out = new StringBuilder();

    out.append("[");
    for ( int i = 0 ; i < getValues().length ; i++ ) {
      out.append(getValues()[i]);
      out.append("||");
    }
    out.append("]");

    return out.toString();
  }

  @Override
  public boolean equals(Object o) {
    if(o instanceof CompoundKey) {
      Object[] v1 = getValues(), v2 = ((CompoundKey) o).getValues();
      if ( v1.length != v2.length ) return false;
      for ( int i = 0 ; i < v1.length ; i++ ) {
        if ( ! v1[i].equals(v2[i]) ) return false;
      }
      return true;
    }
    return false;
  }

  @Override
  public int hashCode() {
    Object[] v = getValues();
    int hash = 17;
    for (Object aV : v) {
      hash = 37 * hash + aV.hashCode();
    }
    return hash;
  }
}

@@ -832,119 +832,97 @@
     
-out.append(%22%5B%22);%0A    for ( int i = 0 ; i %3C getValues().length ; i++ ) %7B%0A      out.append(getValues()%5Bi%5D);%0A     
+int len =  getValues().length;%0A    for ( int i = 0 ; i %3C len ; i++ ) %7B%0A      if ( i %3E 0 )
  out
@@ -934,28 +934,24 @@
 nd(%22%7C%7C%22);%0A  
-  %7D%0A
     out.appe
@@ -957,13 +957,30 @@
 end(
-%22%5D%22);
+getValues()%5Bi%5D);%0A    %7D
 %0A%0A  

Simplify CompoundKey toString() output.