1 11 package org.eclipse.core.internal.dependencies; 12 13 public class Element { 14 private final static String UNRESOLVABLE_PREREQUISITE = "<UNRESOLVABLE PREREQUISITE>"; private Object id; 16 private Object versionId; 17 private Dependency[] dependencies; 18 private boolean singleton; 19 private Object userObject; 20 21 public Element(Object id, Object versionId, Dependency[] dependencies, boolean singleton, Object userObject) { 22 Assert.isNotNull(id); 23 Assert.isNotNull(versionId); 24 Assert.isNotNull(dependencies); 25 this.id = id; 26 this.versionId = versionId; 27 this.dependencies = dependencies; 28 this.singleton = singleton; 29 this.userObject = userObject; 30 } 31 32 public Object getId() { 33 return id; 34 } 35 36 public Object getVersionId() { 37 return versionId; 38 } 39 40 41 public Dependency[] getDependencies() { 42 return dependencies; 43 } 44 45 46 public Dependency getDependency(Object id) { 47 for (int i = 0; i < dependencies.length; i++) 48 if (dependencies[i].getRequiredObjectId().equals(id)) 49 return dependencies[i]; 50 return null; 51 } 52 53 public boolean isSingleton() { 54 return singleton; 55 } 56 57 public Object getUserObject() { 58 return userObject; 59 } 60 61 public String toString() { 62 return this.id + "_" + this.versionId; } 64 65 public boolean equals(Object obj) { 66 if (!(obj instanceof Element)) 67 return false; 68 Element other = (Element) obj; 69 return (other.userObject != null && other.userObject.equals(this.userObject)) || (this.id.equals(other.id) && this.versionId.equals(other.versionId) && other.userObject == null && this.userObject == null); 70 } 71 72 public int hashCode() { 73 return (id.hashCode() << 16) | (versionId.hashCode() & 0xFFFF); 74 } 75 76 public void removeFromCycle() { 77 dependencies = new Dependency[] {new Dependency(UNRESOLVABLE_PREREQUISITE, new UnsatisfiableRule(), false, null)}; 78 } 79 80 private final static class UnsatisfiableRule implements IMatchRule { 81 public boolean isSatisfied(Object required, Object available) { 82 return false; 83 } 84 85 public String toString() { 86 return "unsatisfiable"; } 88 } 89 90 } | Popular Tags |