KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > bundlehandlers > BundleVersionContainer


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

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

25 public class BundleVersionContainer {
26
27     private ShareInfo shareinfo;
28
29     private HashMap JavaDoc bundles=new HashMap JavaDoc();
30
31     public BundleVersionContainer(BundleInterface b) {
32         bundles.put(b.getProvider(),b);
33     }
34
35     public Object JavaDoc addBundle(BundleInterface b) {
36         Object JavaDoc o=bundles.put(b.getProvider(),b);
37         if (o!=null) {
38             return(o);
39         }
40         return(null);
41     }
42
43
44     public boolean removeBundle(BundleInterface b) {
45         bundles.remove(b.getProvider());
46         return true;
47     }
48
49     public int getBundleCount() {
50         return bundles.size();
51     }
52
53     public Object JavaDoc get(ProviderInterface provider) {
54         Object JavaDoc o = bundles.get(provider);
55         if (o != null) {
56             return o;
57         }
58         return null;
59     }
60
61    public Iterator JavaDoc getBundles() {
62        return ((HashMap JavaDoc)bundles.clone()).values().iterator();
63    }
64
65
66     public boolean contains(ProviderInterface provider) {
67         if (bundles.get(provider) != null) {
68             return true;
69         } else {
70             return false;
71         }
72     }
73    
74     public boolean isShared() {
75         if (shareinfo != null) {
76             return true;
77         }
78         return false;
79     }
80
81     public ShareInfo getShareInfo() {
82         return shareinfo;
83     }
84
85     public BundleInterface getBundleByScore() {
86         BundleInterface winner = null;
87         Iterator JavaDoc e = bundles.values().iterator();
88         while (e.hasNext()) {
89             BundleInterface b = (BundleInterface)e.next();
90             if (winner == null) {
91                 winner = b;
92             } else if (b.getProvider().getBaseScore() > winner.getProvider().getBaseScore()) {
93                 winner = b;
94             }
95         }
96         return winner;
97     }
98
99 }
100
Popular Tags