KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > DefaultListBackedValueList


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh;
22
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27
28 /** Wrapper for a <CODE>List</CODE> and a <CODE>ValueListInfo</CODE> object.
29  * This is the Default implementation of ValueList.
30  *
31  * @author Matthew L. Wilson, Andrej Zachar
32  * @version $Revision: 1.10 $ $Date: 2005/08/19 15:46:25 $
33  */

34 public class DefaultListBackedValueList implements ValueList
35 {
36     private List JavaDoc list = null;
37     private ValueListInfo info = null;
38     private Iterator JavaDoc iter = null;
39
40     /** Creates a new instance of DefaultValueList
41      */

42     public DefaultListBackedValueList()
43     {
44         this(new ArrayList JavaDoc(), new ValueListInfo());
45     }
46
47     /** Default constructor.
48      * Here is always the same the list.size and info.getTotalNumberOfEntries.
49      * @param list The List to be sorted.
50      */

51     public DefaultListBackedValueList(List JavaDoc list)
52     {
53         this.list = list;
54         this.info = new ValueListInfo();
55         if (list != null)
56         {
57             info.setTotalNumberOfEntries(list.size());
58         }
59         
60     }
61
62     /** Default constructor.
63      * Warning! list.size and info.getTotalNumberOfEntries could be different!
64      * @param list The List to be sorted.
65      * @param info The sorting/paging/filtering info.
66      */

67     public DefaultListBackedValueList(List JavaDoc list, ValueListInfo info)
68     {
69         this.list = list;
70         this.info = info;
71     }
72
73     /** @see com.mlw.vlh.ValueList.getList()
74      */

75     public List JavaDoc getList()
76     {
77         return list;
78     }
79
80     /** @see com.mlw.vlh.ValueList.getListInfo()
81      */

82     public ValueListInfo getValueListInfo()
83     {
84         return info;
85     }
86
87     /** @see com.mlw.vlh.ValueList.hasNext()
88      */

89     public boolean hasNext()
90     {
91         if (iter == null && list != null)
92         {
93             this.iter = list.iterator();
94         }
95
96         return (iter == null) ? false : iter.hasNext();
97     }
98
99     /** @see java.util.Iterator#next()
100      */

101     public Object JavaDoc next() throws NoSuchElementException JavaDoc
102     {
103         if (iter == null)
104         {
105             if (list != null)
106             {
107                 this.iter = list.iterator();
108             }
109             else
110             {
111                 throw new NoSuchElementException JavaDoc();
112             }
113         }
114
115         return iter.next();
116     }
117
118     /** @see java.util.Iterator#remove()
119      */

120     public void remove()
121     {
122     }
123     
124     /** Resets the Iterator in this ValueList.
125      */

126     public void reset()
127     {
128        iter = null;
129     }
130 }
131
Popular Tags