1 11 12 package org.eclipse.core.internal.dependencies; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 22 public class ResolutionDelta { 23 24 class ElementIdentifier { 25 private Object id; 26 private Object userObject; 27 private Object versionId; 28 29 ElementIdentifier(Object id, Object versionId, Object userObject) { 30 this.id = id; 31 this.versionId = versionId; 32 this.userObject = userObject; 33 } 34 35 public boolean equals(Object anObject) { 36 if (!(anObject instanceof ElementIdentifier)) 37 return false; 38 ElementIdentifier change = (ElementIdentifier) anObject; 39 return (change.userObject != null && change.userObject.equals(this.userObject)) || (this.id.equals(change.id) && this.versionId.equals(change.versionId) && change.userObject == null && this.userObject == null); 40 } 41 42 public int hashCode() { 43 return (id.hashCode() << 16) | (versionId.hashCode() & 0xFFFF); 44 } 45 } 46 47 private Map changes; 48 49 ResolutionDelta() { 50 this.changes = new HashMap (); 51 } 52 53 public ElementChange[] getAllChanges() { 54 return (ElementChange[]) changes.values().toArray(new ElementChange[changes.size()]); 55 } 56 57 public ElementChange getChange(Object id, Object versionId, Object userObject) { 58 return (ElementChange) changes.get(new ElementIdentifier(id, versionId, userObject)); 59 } 60 61 64 void recordChange(Element element, int kind) { 65 ElementChange existingChange = this.getChange(element.getId(), element.getVersionId(), element.getUserObject()); 67 if (existingChange == null) { 69 this.changes.put(new ElementIdentifier(element.getId(), element.getVersionId(), element.getUserObject()), new ElementChange(element, kind)); 70 return; 71 } 72 if (kind == ElementChange.REMOVED) 74 if (existingChange.getKind() == ElementChange.ADDED) { 75 this.changes.remove(new ElementIdentifier(element.getId(), element.getVersionId(), element.getUserObject())); 77 return; 78 } else if ((existingChange.getKind() & ElementChange.ADDED) != 0) { 79 existingChange.setKind((existingChange.getKind() & ~ElementChange.ADDED) | ElementChange.REMOVED); 81 return; 82 } 83 existingChange.setKind(existingChange.getKind() | kind); 85 } 86 87 public String toString() { 88 return changes.values().toString(); 89 } 90 } | Popular Tags |