예제 #1
0
  /**
   * 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;
  }
예제 #2
0
  /**
   * Returns a copy of this list, therefore any changes to the copy cannot affect this original
   * list.
   */
  public Object clone() {

    String S = C + ": clone(): ";
    ParameterList list = new ParameterList();
    if (this.size() < 1) return list;
    int size = this.params.size();
    for (int i = 0; i < size; ++i) {
      ParameterAPI param = (ParameterAPI) params.get(i);
      list.addParameter((ParameterAPI) param.clone());
    }

    return list;
  }
예제 #3
0
  /**
   * Adds all parameters of the parameterlist to this one, if the named parameter is not already in
   * the list. If a named parameter exists already a Parameter Exception is thrown.
   */
  public void addParameterList(ParameterList list2) throws ParameterException {

    ListIterator<ParameterAPI<?>> it = list2.getParametersIterator();
    while (it.hasNext()) {
      ParameterAPI<?> param = (ParameterAPI<?>) it.next();
      if (!this.containsParameter(param)) {
        this.addParameter(param);
      }
    }
  }
예제 #4
0
  /**
   * 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;
  }
예제 #5
0
  /**
   * 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;
  }