/** * 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; }
/** * Merges the attribute maps in a controlled fashion. An entry is only merged with another entry, * if the physical filenames match. * * @param rce is another replica catalog entry to merge with. * @param overwrite resolves intersections. If true, uses rce's attribute to remain, if false, the * original attribute remains. * @return true if a merge was attempted, false if the PFNs did not match. */ public boolean merge(ReplicaCatalogEntry rce, boolean overwrite) { String pfn1 = this.m_pfn; String pfn2 = rce.getPFN(); boolean result = (pfn1 == null && pfn2 == null || pfn1 != null && pfn2 != null && pfn1.equals(pfn2)); // only merge if PFN match if (result) { String key; Object val; for (Iterator i = rce.getAttributeIterator(); i.hasNext(); ) { key = (String) i.next(); val = rce.getAttribute(key); if (hasAttribute(key)) { if (overwrite) setAttribute(key, val); } else { setAttribute(key, val); } } } return result; }