KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > theme > Region


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server.theme;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.Iterator JavaDoc;
14
15 /**
16  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
17  * @version $Revision: 1.1 $
18  */

19 public class Region
20 {
21
22    private String JavaDoc name;
23    private boolean sorted;
24    private ArrayList JavaDoc items;
25
26    public Region(String JavaDoc name)
27    {
28       if (name == null)
29       {
30          throw new NullPointerException JavaDoc();
31       }
32       this.name = name;
33       sorted = false;
34    }
35
36    public String JavaDoc getName()
37    {
38       return name;
39    }
40
41    public void add(Item item)
42    {
43       if (items == null)
44       {
45          items = new ArrayList JavaDoc();
46       }
47       items.add(item);
48    }
49
50    public boolean isEmpty()
51    {
52       if (items == null)
53       {
54          return true;
55       }
56       else
57       {
58          return items.isEmpty();
59       }
60    }
61
62    public Iterator JavaDoc items()
63    {
64       if (items == null)
65       {
66          return Collections.EMPTY_LIST.iterator();
67       }
68       if (!sorted)
69       {
70          Collections.sort(items);
71          sorted = true;
72       }
73       return items.iterator();
74    }
75 }
76
Popular Tags