コード例 #1
0
  /**
   * Compares this <code>PropertyDescriptor</code> against the specified object. Returns true if the
   * objects are the same. Two <code>PropertyDescriptor</code>s are the same if the read, write,
   * property types, property editor and flags are equivalent.
   *
   * @since 1.4
   */
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj != null && obj instanceof PropertyDescriptor) {
      PropertyDescriptor other = (PropertyDescriptor) obj;
      Method otherReadMethod = other.getReadMethod();
      Method otherWriteMethod = other.getWriteMethod();

      if (!compareMethods(getReadMethod(), otherReadMethod)) {
        return false;
      }

      if (!compareMethods(getWriteMethod(), otherWriteMethod)) {
        return false;
      }

      if (getPropertyType() == other.getPropertyType()
          && getPropertyEditorClass() == other.getPropertyEditorClass()
          && bound == other.isBound()
          && constrained == other.isConstrained()
          && writeMethodName == other.writeMethodName
          && readMethodName == other.readMethodName) {
        return true;
      }
    }
    return false;
  }
コード例 #2
0
  /**
   * Package-private constructor. Merge two property descriptors. Where they conflict, give the
   * second argument (y) priority over the first argument (x).
   *
   * @param x The first (lower priority) PropertyDescriptor
   * @param y The second (higher priority) PropertyDescriptor
   */
  PropertyDescriptor(PropertyDescriptor x, PropertyDescriptor y) {
    super(x, y);

    if (y.baseName != null) {
      baseName = y.baseName;
    } else {
      baseName = x.baseName;
    }

    if (y.readMethodName != null) {
      readMethodName = y.readMethodName;
    } else {
      readMethodName = x.readMethodName;
    }

    if (y.writeMethodName != null) {
      writeMethodName = y.writeMethodName;
    } else {
      writeMethodName = x.writeMethodName;
    }

    if (y.propertyTypeRef != null) {
      propertyTypeRef = y.propertyTypeRef;
    } else {
      propertyTypeRef = x.propertyTypeRef;
    }

    // Figure out the merged read method.
    Method xr = x.getReadMethod();
    Method yr = y.getReadMethod();

    // Normally give priority to y's readMethod.
    try {
      if (yr != null && yr.getDeclaringClass() == getClass0()) {
        setReadMethod(yr);
      } else {
        setReadMethod(xr);
      }
    } catch (IntrospectionException ex) {
      // fall through
    }

    // However, if both x and y reference read methods in the same class,
    // give priority to a boolean "is" method over a boolean "get" method.
    if (xr != null
        && yr != null
        && xr.getDeclaringClass() == yr.getDeclaringClass()
        && xr.getReturnType() == boolean.class
        && yr.getReturnType() == boolean.class
        && xr.getName().indexOf("is") == 0
        && yr.getName().indexOf("get") == 0) {
      try {
        setReadMethod(xr);
      } catch (IntrospectionException ex) {
        // fall through
      }
    }

    Method xw = x.getWriteMethod();
    Method yw = y.getWriteMethod();

    try {
      if (yw != null && yw.getDeclaringClass() == getClass0()) {
        setWriteMethod(yw);
      } else {
        setWriteMethod(xw);
      }
    } catch (IntrospectionException ex) {
      // Fall through
    }

    if (y.getPropertyEditorClass() != null) {
      setPropertyEditorClass(y.getPropertyEditorClass());
    } else {
      setPropertyEditorClass(x.getPropertyEditorClass());
    }

    bound = x.bound | y.bound;
    constrained = x.constrained | y.constrained;
  }