001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-api/src/java/org/sakaiproject/api/app/messageforums/UniqueArrayList.java $
003: * $Id: UniqueArrayList.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.api.app.messageforums;
021:
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Iterator;
025: import java.util.List;
026: import java.util.ListIterator;
027:
028: public class UniqueArrayList implements List {
029: private List _list = new ArrayList();
030:
031: public int size() {
032: return _list.size();
033: }
034:
035: public boolean isEmpty() {
036: return _list.isEmpty();
037: }
038:
039: public boolean contains(Object o) {
040: return _list.contains(o);
041: }
042:
043: public Iterator iterator() {
044: return _list.iterator();
045: }
046:
047: public Object[] toArray() {
048: return _list.toArray();
049: }
050:
051: public Object[] toArray(Object[] arg0) {
052: return _list.toArray(arg0);
053: }
054:
055: public boolean add(Object arg0) {
056: if (_list.contains(arg0)) {
057: return false;
058: }
059: return _list.add(arg0);
060: }
061:
062: public boolean remove(Object o) {
063: return _list.remove(o);
064: }
065:
066: public boolean containsAll(Collection arg0) {
067: return _list.containsAll(arg0);
068: }
069:
070: public boolean addAll(Collection arg0) {
071: boolean collectionMutated = false;
072: for (Iterator iter = arg0.iterator(); iter.hasNext();) {
073: Object element = iter.next();
074: if (!_list.contains(element)) {
075: _list.add(element);
076: collectionMutated = true;
077: }
078: }
079: return collectionMutated;
080: }
081:
082: public boolean retainAll(Collection arg0) {
083: return _list.retainAll(arg0);
084: }
085:
086: public boolean removeAll(Collection arg0) {
087: return _list.removeAll(arg0);
088: }
089:
090: public void clear() {
091: _list.clear();
092: }
093:
094: public boolean addAll(int arg0, Collection arg1) {
095: throw new UnsupportedOperationException();
096: }
097:
098: public Object get(int index) {
099: return _list.get(index);
100: }
101:
102: public Object set(int arg0, Object arg1) {
103: Object o = _list.get(arg0);
104: if (!_list.contains(arg1)) {
105: _list.set(arg0, arg1);
106: }
107: return o;
108: }
109:
110: public void add(int arg0, Object arg1) {
111: if (!_list.contains(arg1)) {
112: _list.add(arg0, arg1);
113: }
114: }
115:
116: public Object remove(int index) {
117: return _list.remove(index);
118: }
119:
120: public int indexOf(Object o) {
121: return _list.indexOf(o);
122: }
123:
124: public int lastIndexOf(Object o) {
125: return _list.lastIndexOf(o);
126: }
127:
128: public ListIterator listIterator() {
129: return _list.listIterator();
130: }
131:
132: public ListIterator listIterator(int index) {
133: return _list.listIterator(index);
134: }
135:
136: public List subList(int fromIndex, int toIndex) {
137: return _list.subList(fromIndex, toIndex);
138: }
139:
140: /**
141: * @see java.lang.Object#equals(java.lang.Object)
142: */
143: public boolean equals(Object obj) {
144: return _list.equals(obj);
145: }
146:
147: /**
148: * @see java.lang.Object#hashCode()
149: */
150: public int hashCode() {
151: return _list.hashCode();
152: }
153:
154: /**
155: * @see java.lang.Object#toString()
156: */
157: public String toString() {
158: return _list.toString();
159: }
160:
161: }
|