Пример #1
0
  /**
   * Compares two terms. This functions implements a total order.
   *
   * @param o object to which this term is compared
   * @return a negative integer, zero, or a positive integer as this term is less than, equal to, or
   *     greater than the argument
   * @throws ClassCastException in case of invalid arguments
   * @throws RuntimeException if unable to compare childs
   */
  @Override
  public int compareTo(Object o) {
    /*
     * We do not want to compare with any object, only members of the module
     * In case of invalid argument, throw a ClassCastException, as the java api
     * asks for it
     */
    parser.rec.RecAbstractType ao = (parser.rec.RecAbstractType) o;
    /* return 0 for equality */
    if (ao == this) {
      return 0;
    }
    /* use the hash values to discriminate */

    if (hashCode != ao.hashCode()) {
      return (hashCode < ao.hashCode()) ? -1 : 1;
    }

    /* If not, compare the symbols : back to the normal order */
    int symbCmp = this.symbolName().compareTo(ao.symbolName());
    if (symbCmp != 0) {
      return symbCmp;
    }
    /* last resort: compare the childs */
    RelExpMoreEqual tco = (RelExpMoreEqual) ao;
    int _a5Cmp = (this._a5).compareTo(tco._a5);
    if (_a5Cmp != 0) {
      return _a5Cmp;
    }

    throw new RuntimeException("Unable to compare");
  }
Пример #2
0
  /**
   * Compares two terms. This functions implements a total lexicographic path ordering.
   *
   * @param o object to which this term is compared
   * @return a negative integer, zero, or a positive integer as this term is less than, equal to, or
   *     greater than the argument
   * @throws ClassCastException in case of invalid arguments
   * @throws RuntimeException if unable to compare childs
   */
  @Override
  public int compareToLPO(Object o) {
    /*
     * We do not want to compare with any object, only members of the module
     * In case of invalid argument, throw a ClassCastException, as the java api
     * asks for it
     */
    parser.rec.RecAbstractType ao = (parser.rec.RecAbstractType) o;
    /* return 0 for equality */
    if (ao == this) {
      return 0;
    }
    /* compare the symbols */
    int symbCmp = this.symbolName().compareTo(ao.symbolName());
    if (symbCmp != 0) {
      return symbCmp;
    }
    /* compare the childs */
    RelExpMoreEqual tco = (RelExpMoreEqual) ao;
    int _a5Cmp = (this._a5).compareToLPO(tco._a5);
    if (_a5Cmp != 0) {
      return _a5Cmp;
    }

    throw new RuntimeException("Unable to compare");
  }