/** * Returns true if all the parameters have the same names and values. One use will be to determine * if two DisctetizedFunctions are the same, i.e. set up with the same independent parameters. */ public boolean equalsParameterList(ParameterList list) { // Not same size, can't be equal if (this.size() != list.size()) return false; // Check each individual Parameter ListIterator<ParameterAPI<?>> it = this.getParametersIterator(); while (it.hasNext()) { // This list's parameter ParameterAPI<?> param1 = it.next(); // List may not contain parameter with this list's parameter name if (!list.containsParameter(param1.getName())) return false; // Found two parameters with same name, check equals, actually // redundent, // because that is what equals does ParameterAPI<?> param2 = list.getParameter(param1.getName()); if (!param1.equals(param2)) return false; // Now try compare to to see if value the same, can fail if two // values // are different, or if the value object types are different try { if (param1.compareTo(param2) != 0) return false; } catch (ClassCastException ee) { return false; } } // Passed all tests - return true return true; }
/** * Returns true if all the parameters have the same names. One use will be to determine if two * DisctetizedFunctions can be plotted on the same axis, i.e. set up with the same independent * parameters. */ public boolean equalNames(ParameterList list) { // Not same size, can't be equal if (this.size() != list.size()) return false; // Check each individual Parameter ListIterator<ParameterAPI<?>> it = this.getParametersIterator(); while (it.hasNext()) { // This list's parameter ParameterAPI<?> param1 = it.next(); // List may not contain parameter with this list's parameter name if (!list.containsParameter(param1.getName())) return false; } // Passed all tests - return true return true; }
/** * compares 2 ParameterList to see if they are equal. It compares them by checking each parameter * with the passed argument obj is present in the parameterList, it is compared with. It also * checks if both the parameterLists have same parameters and have the same values. * * @param obj instance of ParameterList * @return int 0 if both object are same else return -1 */ public int compareTo(Object obj) { int result = 0; if (!(obj instanceof ParameterList)) { throw new ClassCastException(C + "Object not a ParameterList, unable to compare"); } ParameterList paramList = (ParameterList) obj; ListIterator<ParameterAPI<?>> it = paramList.getParametersIterator(); if (size() != paramList.size()) return -1; while (it.hasNext()) { ParameterAPI param1 = (ParameterAPI) it.next(); ParameterAPI param2 = (ParameterAPI) getParameter(param1.getName()); result = param2.compareTo(param1); if (result != 0) break; } return result; }