KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > workingset > AdaptableTocsArray


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

11 package org.eclipse.help.internal.workingset;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.HashMap JavaDoc;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.help.*;
18
19 /**
20  * Makes help resources adaptable and persistable
21  */

22 public class AdaptableTocsArray implements IAdaptable {
23
24     IToc[] element;
25     AdaptableToc[] children;
26     HashMap JavaDoc map;
27
28     /**
29      * This constructor will be called when wrapping help resources.
30      */

31     public AdaptableTocsArray(IToc[] tocs) {
32         this.element = tocs;
33     }
34
35     /**
36      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
37      */

38     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
39         if (adapter == IToc[].class)
40             return element;
41         return null;
42     }
43
44     public IAdaptable[] getChildren() {
45
46         if (children == null) {
47             children = new AdaptableToc[element.length];
48             for (int i = 0; i < element.length; i++) {
49                 children[i] = new AdaptableToc(element[i]);
50                 children[i].setParent(this);
51             }
52         }
53         return children;
54
55     }
56
57     public AdaptableToc getAdaptableToc(String JavaDoc href) {
58         if (map == null) {
59             getChildren(); // make sure children are initialized
60
map = new HashMap JavaDoc(children.length);
61             for (int i = 0; i < children.length; i++)
62                 map.put(children[i].getHref(), children[i]);
63         }
64         return (AdaptableToc) map.get(href);
65     }
66
67     IToc[] asArray() {
68         return element;
69     }
70
71     /**
72      * Tests the receiver and the object for equality
73      *
74      * @param object
75      * object to compare the receiver to
76      * @return true=the object equals the receiver, the name is the same. false
77      * otherwise
78      */

79     public boolean equals(Object JavaDoc object) {
80         if (this == object) {
81             return true;
82         }
83         if (!(object instanceof AdaptableTocsArray)) {
84             return false;
85         }
86
87         AdaptableTocsArray res = (AdaptableTocsArray) object;
88         return (Arrays.equals(asArray(), res.asArray()));
89
90     }
91
92     /**
93      * Returns the hash code.
94      *
95      * @return the hash code.
96      */

97     public int hashCode() {
98         if (element == null)
99             return -1;
100         return element.hashCode();
101     }
102 }
103
104
Popular Tags