001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.util;
034:
035: import java.util.*;
036:
037: /**
038: * A List that ignores duplicates. Note: performance is not optimized - a simple linear
039: * search is performed.
040: */
041: public class UniqueList implements List {
042: private List list;
043:
044: /**
045: * Creates a UniqueList.
046: */
047: public UniqueList() {
048: this (new ArrayList());
049: }
050:
051: /**
052: * Creates a UniqueList backed by the given List.
053: * @param list a List that will be this UniqueList's underlying List
054: */
055: public UniqueList(List list) {
056: this .list = list;
057: }
058:
059: public int size() {
060: return list.size();
061: }
062:
063: public boolean isEmpty() {
064: return list.isEmpty();
065: }
066:
067: public boolean contains(Object o) {
068: return list.contains(o);
069: }
070:
071: public Iterator iterator() {
072: return list.iterator();
073: }
074:
075: public Object[] toArray() {
076: return list.toArray();
077: }
078:
079: public Object[] toArray(Object[] a) {
080: return list.toArray(a);
081: }
082:
083: public boolean add(Object o) {
084: if (list.contains(o)) {
085: return false;
086: }
087:
088: return list.add(o);
089: }
090:
091: public boolean remove(Object o) {
092: return list.remove(o);
093: }
094:
095: public boolean containsAll(Collection c) {
096: return list.containsAll(c);
097: }
098:
099: public boolean addAll(Collection c) {
100: return addAll(size(), c);
101: }
102:
103: public boolean addAll(int index, Collection c) {
104: ArrayList itemsToAdd = new ArrayList(c);
105: itemsToAdd.removeAll(this );
106: return list.addAll(index, itemsToAdd);
107: }
108:
109: public boolean removeAll(Collection c) {
110: return list.removeAll(c);
111: }
112:
113: public boolean retainAll(Collection c) {
114: return list.retainAll(c);
115: }
116:
117: public void clear() {
118: list.clear();
119: }
120:
121: public boolean equals(Object o) {
122: return list.equals(o);
123: }
124:
125: public Object get(int index) {
126: return list.get(index);
127: }
128:
129: public Object set(int index, Object element) {
130: return list.set(index, element);
131: }
132:
133: public void add(int index, Object element) {
134: if (list.contains(element)) {
135: return;
136: }
137:
138: list.add(index, element);
139: }
140:
141: public Object remove(int index) {
142: return list.remove(index);
143: }
144:
145: public int indexOf(Object o) {
146: return list.indexOf(o);
147: }
148:
149: public int lastIndexOf(Object o) {
150: return list.lastIndexOf(o);
151: }
152:
153: public ListIterator listIterator() {
154: return list.listIterator();
155: }
156:
157: public ListIterator listIterator(int index) {
158: return list.listIterator(index);
159: }
160:
161: public List subList(int fromIndex, int toIndex) {
162: return list.subList(fromIndex, toIndex);
163: }
164: }
|