Source Code Cross Referenced for ListOrderedSet.java in  » Development » OVal » net » sf » oval » internal » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » OVal » net.sf.oval.internal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
003:         * Thomschke.
004:         * 
005:         * All Rights Reserved. This program and the accompanying materials
006:         * are made available under the terms of the Eclipse Public License v1.0
007:         * which accompanies this distribution, and is available at
008:         * http://www.eclipse.org/legal/epl-v10.html
009:         * 
010:         * Contributors:
011:         *     Sebastian Thomschke - initial implementation.
012:         *******************************************************************************/package net.sf.oval.internal.util;
013:
014:        import java.util.Collection;
015:        import java.util.Iterator;
016:        import java.util.List;
017:        import java.util.ListIterator;
018:        import java.util.Set;
019:
020:        import net.sf.oval.internal.CollectionFactoryHolder;
021:
022:        /**
023:         *  @author Sebastian Thomschke
024:         */
025:        public class ListOrderedSet<E> implements  Cloneable, Set<E>, List<E> {
026:            private final List<E> list;
027:
028:            /**
029:             * Constructs a new, empty collection with an initial capacity (16).
030:             */
031:            public ListOrderedSet() {
032:                list = CollectionFactoryHolder.getFactory().createList(16);
033:            }
034:
035:            /**
036:             * Constructs a new, empty collection with the given initial capacity.
037:             *
038:             * @param initialCapacity the initial capacity
039:             */
040:            public ListOrderedSet(final int initialCapacity) {
041:                list = CollectionFactoryHolder.getFactory().createList(
042:                        initialCapacity);
043:            }
044:
045:            public boolean add(final E e) {
046:                return list.add(e);
047:            }
048:
049:            public void add(final int index, final E e) {
050:                if (!list.contains(e))
051:                    list.add(index, e);
052:            }
053:
054:            public boolean addAll(final Collection<? extends E> c) {
055:                boolean itemAdded = false;
056:                for (final E o : c) {
057:                    if (!list.contains(o)) {
058:                        add(o);
059:                        itemAdded = true;
060:                    }
061:                }
062:                return itemAdded;
063:            }
064:
065:            public boolean addAll(final int index,
066:                    final Collection<? extends E> c) {
067:                final List<E> tmp = CollectionFactoryHolder.getFactory()
068:                        .createList(c.size());
069:                for (final E o : c) {
070:                    if (!list.contains(o)) {
071:                        tmp.add(o);
072:                    }
073:                }
074:                return list.addAll(index, tmp);
075:            }
076:
077:            public void clear() {
078:                list.clear();
079:            }
080:
081:            @SuppressWarnings("unchecked")
082:            @Override
083:            public Object clone() throws CloneNotSupportedException {
084:                final ListOrderedSet<E> os = (ListOrderedSet<E>) super .clone();
085:                os.list.addAll(list);
086:                return os;
087:            }
088:
089:            public boolean contains(final Object o) {
090:                return list.contains(o);
091:            }
092:
093:            public boolean containsAll(final Collection<?> c) {
094:                return list.containsAll(c);
095:            }
096:
097:            @Override
098:            public boolean equals(final Object obj) {
099:                if (this  == obj)
100:                    return true;
101:                if (obj == null)
102:                    return false;
103:                if (getClass() != obj.getClass())
104:                    return false;
105:                final ListOrderedSet other = (ListOrderedSet) obj;
106:                if (list == null) {
107:                    if (other.list != null)
108:                        return false;
109:                } else if (!list.equals(other.list))
110:                    return false;
111:                return true;
112:            }
113:
114:            public E get(final int index) {
115:                return list.get(index);
116:            }
117:
118:            @Override
119:            public int hashCode() {
120:                final int PRIME = 31;
121:                int result = 1;
122:                result = PRIME * result
123:                        + ((list == null) ? 0 : list.hashCode());
124:                return result;
125:            }
126:
127:            public int indexOf(final Object o) {
128:                return list.indexOf(o);
129:            }
130:
131:            public boolean isEmpty() {
132:                return list.isEmpty();
133:            }
134:
135:            public Iterator<E> iterator() {
136:                return list.iterator();
137:            }
138:
139:            public int lastIndexOf(final Object o) {
140:                return list.lastIndexOf(o);
141:            }
142:
143:            public ListIterator<E> listIterator() {
144:                return list.listIterator();
145:            }
146:
147:            public ListIterator<E> listIterator(final int index) {
148:                return list.listIterator(index);
149:            }
150:
151:            public E remove(final int index) {
152:                return list.remove(index);
153:            }
154:
155:            public boolean remove(final Object o) {
156:                return list.remove(o);
157:            }
158:
159:            public boolean removeAll(final Collection<?> c) {
160:                return list.removeAll(c);
161:            }
162:
163:            public boolean retainAll(final Collection<?> c) {
164:                return list.retainAll(c);
165:            }
166:
167:            public E set(final int index, final E element) {
168:                final int elementIndex = list.indexOf(element);
169:
170:                if (elementIndex == index)
171:                    return element;
172:
173:                if (elementIndex == -1) {
174:                    return list.set(index, element);
175:                }
176:                if (elementIndex > index) {
177:                    list.remove(element);
178:                    return list.set(index, element);
179:                }
180:
181:                // if (elementIndex < index)
182:                list.remove(element);
183:                return list.set(index - 1, element);
184:            }
185:
186:            public int size() {
187:                return list.size();
188:            }
189:
190:            public List<E> subList(final int fromIndex, final int toIndex) {
191:                return list.subList(fromIndex, toIndex);
192:            }
193:
194:            public Object[] toArray() {
195:                return list.toArray();
196:            }
197:
198:            public <T> T[] toArray(final T[] a) {
199:                return list.toArray(a);
200:            }
201:
202:            @Override
203:            public String toString() {
204:                return list.toString();
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.