KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dependencies > Element


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.dependencies;
12
13 public class Element {
14     private final static String JavaDoc UNRESOLVABLE_PREREQUISITE = "<UNRESOLVABLE PREREQUISITE>"; //$NON-NLS-1$
15
private Object JavaDoc id;
16     private Object JavaDoc versionId;
17     private Dependency[] dependencies;
18     private boolean singleton;
19     private Object JavaDoc userObject;
20
21     public Element(Object JavaDoc id, Object JavaDoc versionId, Dependency[] dependencies, boolean singleton, Object JavaDoc 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 JavaDoc getId() {
33         return id;
34     }
35
36     public Object JavaDoc getVersionId() {
37         return versionId;
38     }
39
40     /** @return a non-null reference */
41     public Dependency[] getDependencies() {
42         return dependencies;
43     }
44
45     /** may return null */
46     public Dependency getDependency(Object JavaDoc 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 JavaDoc getUserObject() {
58         return userObject;
59     }
60
61     public String JavaDoc toString() {
62         return this.id + "_" + this.versionId; //$NON-NLS-1$
63
}
64
65     public boolean equals(Object JavaDoc 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 JavaDoc required, Object JavaDoc available) {
82             return false;
83         }
84
85         public String JavaDoc toString() {
86             return "unsatisfiable"; //$NON-NLS-1$
87
}
88     }
89
90 }
Popular Tags