KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > packagehandlers > PackageVersionContainer


1 /*
2  * This software is OSI Certified Open Source Software.
3  * OSI Certified is a certification mark of the Open Source Initiative.
4  * The license (Mozilla version 1.0) can be read at the MMBase site.
5  * See http://www.MMBase.org/license
6  */

7 package org.mmbase.applications.packaging.packagehandlers;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import org.mmbase.applications.packaging.providerhandlers.ProviderInterface;
13 import org.mmbase.applications.packaging.sharehandlers.ShareInfo;
14
15 /**
16  * The package version container, keeps all track of all the packages with
17  * the same version (but multiple providers)
18  *
19  * @author Daniel Ockeloen (MMBased)
20  */

21 public class PackageVersionContainer {
22
23     private ShareInfo shareinfo;
24     private String JavaDoc version;
25
26     private HashMap JavaDoc packages = new HashMap JavaDoc();
27
28
29     /**
30      *Constructor for the PackageVersionContainer object
31      *
32      * @param p Description of the Parameter
33      */

34     public PackageVersionContainer(PackageInterface p) {
35
36         version = p.getVersion();
37     }
38
39
40     /**
41      * Adds a feature to the Package attribute of the PackageVersionContainer object
42      *
43      * @param p The feature to be added to the Package attribute
44      * @return Description of the Return Value
45      */

46     public Object JavaDoc addPackage(PackageInterface p) {
47         Object JavaDoc o = packages.put(p.getProvider(), p);
48         if (o != null) {
49             return (o);
50         }
51         return (null);
52     }
53
54
55     /**
56      * Description of the Method
57      *
58      * @param p Description of the Parameter
59      * @return Description of the Return Value
60      */

61     public boolean removePackage(PackageInterface p) {
62         packages.remove(p.getProvider());
63         return true;
64     }
65
66
67     /**
68      * Gets the packageCount attribute of the PackageVersionContainer object
69      *
70      * @return The packageCount value
71      */

72     public int getPackageCount() {
73         return packages.size();
74     }
75
76
77     /**
78      * Description of the Method
79      *
80      * @param provider Description of the Parameter
81      * @return Description of the Return Value
82      */

83     public Object JavaDoc get(ProviderInterface provider) {
84         Object JavaDoc o = packages.get(provider);
85         if (o != null) {
86             return (o);
87         }
88         return (null);
89     }
90
91
92     /**
93      * Gets the packages attribute of the PackageVersionContainer object
94      *
95      * @return The packages value
96      */

97     public Iterator JavaDoc getPackages() {
98         return ((HashMap JavaDoc)packages.clone()).values().iterator();
99     }
100
101
102     /**
103      * Description of the Method
104      *
105      * @param provider Description of the Parameter
106      * @return Description of the Return Value
107      */

108     public boolean contains(ProviderInterface provider) {
109         if (packages.get(provider) != null) {
110             return (true);
111         } else {
112             return (false);
113         }
114     }
115
116
117     /**
118      * Gets the shared attribute of the PackageVersionContainer object
119      *
120      * @return The shared value
121      */

122     public boolean isShared() {
123         if (shareinfo != null) {
124             return true;
125         }
126         return false;
127     }
128
129
130     /**
131      * Gets the version attribute of the PackageVersionContainer object
132      *
133      * @return The version value
134      */

135     public String JavaDoc getVersion() {
136         return version;
137     }
138
139
140     /**
141      * Gets the shareInfo attribute of the PackageVersionContainer object
142      *
143      * @return The shareInfo value
144      */

145     public ShareInfo getShareInfo() {
146         return shareinfo;
147     }
148
149
150     /**
151      * Gets the packageByScore attribute of the PackageVersionContainer object
152      *
153      * @return The packageByScore value
154      */

155     public PackageInterface getPackageByScore() {
156         PackageInterface winner = null;
157         Iterator JavaDoc e = packages.values().iterator();
158         while (e.hasNext()) {
159             PackageInterface p = (PackageInterface)e.next();
160             if (winner == null) {
161                 winner = p;
162             } else if (p.getProvider().getBaseScore() > winner.getProvider().getBaseScore()) {
163                 winner = p;
164             }
165         }
166         return winner;
167     }
168
169 }
170
171
Popular Tags