/** * * @param param * @return the hashcode consistent with the equals method for this comparator */ public static int hashCode(ParameterValue param){ if (parameterValueComparator == null){ parameterValueComparator = new ParameterValueComparator(); } if (param == null){ return 0; } int hashcode = 31; hashcode = 31*hashcode + (param.getFactor().multiply(BigDecimal.valueOf(Math.pow(param.getBase(), param.getExponent())))).hashCode(); return hashcode; } }
/** * It compares the BigDecimal value of factor.multiply(BigDecimal.valueOf(base^exponent)) * If both values are null, they are equals. * The value that is not null comes before the one that is null. * @param value1 * @param value2 * @return */ public int compare(ParameterValue value1, ParameterValue value2) { int EQUAL = 0; int BEFORE = -1; int AFTER = 1; if (value1 == null && value2 == null){ return EQUAL; } else if (value1 == null){ return AFTER; } else if (value2 == null){ return BEFORE; } else { return (value1.getFactor().multiply(BigDecimal.valueOf(Math.pow(value1.getBase(), value1.getExponent())))).compareTo(value2.getFactor().multiply(BigDecimal.valueOf(Math.pow(value2.getBase(), value2.getExponent())))); } }