svn-gvsig-desktop / tags / v1_1_Build_1002 / applications / appgvSIG / src / com / vividsolutions / jump / util / UniqueList.java @ 12070
History | View | Annotate | Download (3.86 KB)
1 | 312 | fernando | |
---|---|---|---|
2 | /*
|
||
3 | * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
|
||
4 | * for visualizing and manipulating spatial features with geometry and attributes.
|
||
5 | *
|
||
6 | * Copyright (C) 2003 Vivid Solutions
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Vivid Solutions
|
||
25 | * Suite #1A
|
||
26 | * 2328 Government Street
|
||
27 | * Victoria BC V8T 5G5
|
||
28 | * Canada
|
||
29 | *
|
||
30 | * (250)385-6040
|
||
31 | * www.vividsolutions.com
|
||
32 | */
|
||
33 | |||
34 | package com.vividsolutions.jump.util; |
||
35 | |||
36 | 8765 | jjdelcerro | import java.util.ArrayList; |
37 | import java.util.Collection; |
||
38 | import java.util.Iterator; |
||
39 | import java.util.List; |
||
40 | import java.util.ListIterator; |
||
41 | 312 | fernando | |
42 | |||
43 | /**
|
||
44 | * A List that ignores duplicates. Note: performance is not optimized - a simple linear
|
||
45 | * search is performed.
|
||
46 | */
|
||
47 | public class UniqueList implements List { |
||
48 | private List list; |
||
49 | |||
50 | /**
|
||
51 | * Creates a UniqueList.
|
||
52 | */
|
||
53 | public UniqueList() {
|
||
54 | this(new ArrayList()); |
||
55 | } |
||
56 | |||
57 | /**
|
||
58 | * Creates a UniqueList backed by the given List.
|
||
59 | * @param list a List that will be this UniqueList's underlying List
|
||
60 | */
|
||
61 | public UniqueList(List list) { |
||
62 | this.list = list;
|
||
63 | } |
||
64 | |||
65 | public int size() { |
||
66 | return list.size();
|
||
67 | } |
||
68 | |||
69 | public boolean isEmpty() { |
||
70 | return list.isEmpty();
|
||
71 | } |
||
72 | |||
73 | public boolean contains(Object o) { |
||
74 | return list.contains(o);
|
||
75 | } |
||
76 | |||
77 | public Iterator iterator() { |
||
78 | return list.iterator();
|
||
79 | } |
||
80 | |||
81 | public Object[] toArray() { |
||
82 | return list.toArray();
|
||
83 | } |
||
84 | |||
85 | public Object[] toArray(Object[] a) { |
||
86 | return list.toArray(a);
|
||
87 | } |
||
88 | |||
89 | public boolean add(Object o) { |
||
90 | if (list.contains(o)) {
|
||
91 | return false; |
||
92 | } |
||
93 | |||
94 | return list.add(o);
|
||
95 | } |
||
96 | |||
97 | public boolean remove(Object o) { |
||
98 | return list.remove(o);
|
||
99 | } |
||
100 | |||
101 | public boolean containsAll(Collection c) { |
||
102 | return list.containsAll(c);
|
||
103 | } |
||
104 | |||
105 | public boolean addAll(Collection c) { |
||
106 | return addAll(size(), c);
|
||
107 | } |
||
108 | |||
109 | public boolean addAll(int index, Collection c) { |
||
110 | ArrayList itemsToAdd = new ArrayList(c); |
||
111 | itemsToAdd.removeAll(this);
|
||
112 | return list.addAll(index, itemsToAdd);
|
||
113 | } |
||
114 | |||
115 | public boolean removeAll(Collection c) { |
||
116 | return list.removeAll(c);
|
||
117 | } |
||
118 | |||
119 | public boolean retainAll(Collection c) { |
||
120 | return list.retainAll(c);
|
||
121 | } |
||
122 | |||
123 | public void clear() { |
||
124 | list.clear(); |
||
125 | } |
||
126 | |||
127 | public boolean equals(Object o) { |
||
128 | return list.equals(o);
|
||
129 | } |
||
130 | |||
131 | public Object get(int index) { |
||
132 | return list.get(index);
|
||
133 | } |
||
134 | |||
135 | public Object set(int index, Object element) { |
||
136 | return list.set(index, element);
|
||
137 | } |
||
138 | |||
139 | public void add(int index, Object element) { |
||
140 | if (list.contains(element)) {
|
||
141 | return;
|
||
142 | } |
||
143 | |||
144 | list.add(index, element); |
||
145 | } |
||
146 | |||
147 | public Object remove(int index) { |
||
148 | return list.remove(index);
|
||
149 | } |
||
150 | |||
151 | public int indexOf(Object o) { |
||
152 | return list.indexOf(o);
|
||
153 | } |
||
154 | |||
155 | public int lastIndexOf(Object o) { |
||
156 | return list.lastIndexOf(o);
|
||
157 | } |
||
158 | |||
159 | public ListIterator listIterator() { |
||
160 | return list.listIterator();
|
||
161 | } |
||
162 | |||
163 | public ListIterator listIterator(int index) { |
||
164 | return list.listIterator(index);
|
||
165 | } |
||
166 | |||
167 | public List subList(int fromIndex, int toIndex) { |
||
168 | return list.subList(fromIndex, toIndex);
|
||
169 | } |
||
170 | } |