Exemplo n.º 1
0
  /**
   * Matches two ReplicaCatalogEntry objects. The primary key in this case is the pfn and all the
   * attributes.
   *
   * @return true if the pfn and all the attributes match, false otherwise.
   */
  public boolean equals(Object obj) {
    // null check
    if (obj == null) return false;

    // see if type of objects match
    if (!(obj instanceof ReplicaCatalogEntry)) return false;

    ReplicaCatalogEntry rce = (ReplicaCatalogEntry) obj;
    String pfn1 = this.m_pfn;
    String pfn2 = rce.getPFN();

    // rce with null pfns are assumed to match
    boolean result =
        (pfn1 == null && pfn2 == null
            || pfn1 != null
                && pfn2 != null
                && pfn1.equals(pfn2)
                && this.getAttributeCount() == rce.getAttributeCount());

    if (result) {
      String key;
      Object val;

      // do the matching on attributes now
      for (Iterator it = rce.getAttributeIterator(); it.hasNext(); ) {
        key = (String) it.next();
        val = rce.getAttribute(key);
        if (hasAttribute(key)) {
          if (!(getAttribute(key).equals(val))) {
            result = false;
            break;
          }
        }
      }
    }

    return result;
  }