Example #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();
  }
Example #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;
  }