Example #1
0
  /**
   * This method has the same behavior as {@link #equals(Object)}. The only difference being that it
   * takes a {@code DataFlavor} instance as a parameter.
   *
   * @param that the <code>DataFlavor</code> to compare with <code>this</code>
   * @return <code>true</code> if <code>that</code> is equivalent to this <code>DataFlavor</code>;
   *     <code>false</code> otherwise
   * @see #selectBestTextFlavor
   */
  public boolean equals(DataFlavor that) {
    if (that == null) {
      return false;
    }
    if (this == that) {
      return true;
    }

    if (representationClass == null) {
      if (that.getRepresentationClass() != null) {
        return false;
      }
    } else {
      if (!representationClass.equals(that.getRepresentationClass())) {
        return false;
      }
    }

    if (mimeType == null) {
      if (that.mimeType != null) {
        return false;
      }
    } else {
      if (!mimeType.match(that.mimeType)) {
        return false;
      }

      if ("text".equals(getPrimaryType())
          && DataTransferer.doesSubtypeSupportCharset(this)
          && representationClass != null
          && !(isRepresentationClassReader()
              || String.class.equals(representationClass)
              || isRepresentationClassCharBuffer()
              || DataTransferer.charArrayClass.equals(representationClass))) {
        String thisCharset = DataTransferer.canonicalName(getParameter("charset"));
        String thatCharset = DataTransferer.canonicalName(that.getParameter("charset"));
        if (thisCharset == null) {
          if (thatCharset != null) {
            return false;
          }
        } else {
          if (!thisCharset.equals(thatCharset)) {
            return false;
          }
        }
      }
    }

    return true;
  }