Exemplo n.º 1
0
  public Identifier(Identifier that) {
    this();

    if (that == null || that.isEmpty()) return;

    add(that.components.toArray());
  }
Exemplo n.º 2
0
  /**
   * Compares this identifer to another, returning -1, 0, or 1 depending on whether this identifier
   * is less-than, equal-to, or greater-than the other identifier, respectively.
   *
   * @return -1, 0, 1 to indicate less-than, equal-to, or greater-than, respectively.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public int compareTo(Identifier that) {
    if (that == null) return 1;
    if (this.size() < that.size()) return -1;
    if (this.size() > that.size()) return 1;

    int i = 0;
    int result = 0;

    while (result == 0 && i < size()) {
      Object cThis = this.components.get(i);
      Object cThat = that.components.get(i);

      if (ObjectUtils.areComparable(cThis, cThat)) {
        result = ((Comparable) cThis).compareTo(((Comparable) cThat));
      } else {
        result = (cThis.toString().compareTo(cThat.toString()));
      }

      ++i;
    }

    return result;
  }