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