01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/help/tags/sakai_2-4-1/help-component/src/java/org/sakaiproject/component/app/help/SizedList.java $
03: * $Id: SizedList.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.component.app.help;
21:
22: import java.util.ArrayList;
23: import java.util.Collection;
24: import java.util.Iterator;
25:
26: /**
27: * size list
28: * @version $Id: SizedList.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
29: */
30: public class SizedList extends ArrayList {
31: private int size = -1;
32:
33: /**
34: * constructor
35: */
36: public SizedList() {
37: super ();
38: }
39:
40: /**
41: * overloaded constructor
42: * @param size
43: */
44: public SizedList(int size) {
45: super ();
46: this .size = size;
47: }
48:
49: /**
50: * @see java.util.Collection#add(java.lang.Object)
51: */
52: public boolean add(Object item) {
53: if (this .contains(item)) {
54: this .remove(item);
55: }
56: super .add(0, item);
57: if (this .size() > size) {
58: this .remove(this .size() - 1);
59: }
60: return true;
61: }
62:
63: /**
64: * @see java.util.Collection#addAll(java.util.Collection)
65: */
66: public boolean addAll(Collection c) {
67: for (Iterator i = c.iterator(); i.hasNext();) {
68: add(i.next());
69: }
70: return true;
71: }
72:
73: }
|