Ejemplo n.º 1
0
  @Override
  public String toString() {
    StringBuffer result = new StringBuffer();

    result.append(getKindString());

    switch (kind) {
      case CONSTANT_Qname:
      case CONSTANT_QnameA:
      case CONSTANT_Multiname:
      case CONSTANT_MultinameA:
        {
          result.append(": ");
          // Display the base name first since the qualifiers can be very long
          // and you don't want to have to scroll to see the base name.
          result.append(getBaseName());
          result.append("::");
          if (qualifiers != null) {
            result.append(qualifiers.toString());
          }
          break;
        }
      case CONSTANT_RTQname:
      case CONSTANT_RTQnameA:
        {
          result.append(": ");
          result.append(getBaseName());
          break;
        }
      case CONSTANT_RTQnameL:
      case CONSTANT_RTQnameLA:
        {
          break;
        }
      case CONSTANT_MultinameL:
      case CONSTANT_MultinameLA:
        {
          result.append(": ");
          if (qualifiers != null) {
            result.append(qualifiers.toString());
          }
          break;
        }
      case CONSTANT_TypeName:
        {
          result.append(": ");
          result.append(typeNameBase.toString());
          result.append(".<");
          if (typeNameParameter != null) result.append(typeNameParameter.toString());
          else result.append("*");
          result.append(">");
          break;
        }
    }

    return result.toString();
  }
Ejemplo n.º 2
0
  /**
   * Generate a composite hash code using the Name's fields' hashes.
   *
   * <p>{@inheritDoc}
   */
  @Override
  public int hashCode() {
    if (cachedHashCode == null) {
      int result = kind;

      if (kind != CONSTANT_TypeName) {
        result = (int) (PRIME_MULTIPLIER * result + (baseName != null ? baseName.hashCode() : 0));
        result =
            (int) (PRIME_MULTIPLIER * result + (qualifiers != null ? qualifiers.hashCode() : 0));
      } else {
        result = (int) (PRIME_MULTIPLIER * result) + typeNameBase.hashCode();
        if (typeNameParameter != null)
          result = (int) (PRIME_MULTIPLIER * result) + typeNameParameter.hashCode();
      }

      cachedHashCode = result;
    }

    return cachedHashCode;
  }
Ejemplo n.º 3
0
  /**
   * Compare two Names for equality.
   *
   * @param other - the Name to compare to.
   * @return true if the components of these Names are equal.
   */
  private boolean isEqualTo(Name other) {
    //  Checking kind has already been done (via the hashCode())
    //  when called from equals().
    boolean result = true; /* this.kind == other.kind; */

    if (result && kind != CONSTANT_TypeName) {
      //  Check qualifiers, then base.
      if (this.qualifiers == other.qualifiers) {
        // result = true;
      } else if (this.qualifiers != null && other.qualifiers != null) {
        result = this.qualifiers.equals(other.qualifiers);
      } else {
        //  One qualifier is null, but not both
        result = false;
      }

      if (result) {
        String this_base = this.getBaseName();
        String other_base = other.getBaseName();

        if (this_base != null && other_base != null) {
          result = this_base.equals(other_base);
        } else {
          result = this_base == null && other_base == null;
        }
      }
    } else if (result) {
      // When comparing C1.<T1> to C2.<T2>,
      // first compare C1 to C2; if they're equal, compare T1 to T2.

      result = this.typeNameBase.equals(other.typeNameBase);

      if (result && this.typeNameParameter != null) {
        if (other.typeNameParameter != null)
          result = this.typeNameParameter.equals(other.typeNameParameter);
        else result = false;
      }
    }

    return result;
  }