Source Code Cross Referenced for CollectionMap.java in  » GIS » openjump » com » vividsolutions » jump » 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 » GIS » openjump » com.vividsolutions.jump.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        import com.vividsolutions.jts.util.Assert;
038:
039:        /**
040:         *  A Map whose values are Collections.
041:         */
042:        public class CollectionMap implements  Map {
043:            private Map map;
044:            private Class collectionClass = ArrayList.class;
045:
046:            /**
047:             * Creates a CollectionMap backed by the given Map class.
048:             * @param mapClass a Class that implements Map
049:             */
050:            public CollectionMap(Class mapClass) {
051:                try {
052:                    map = (Map) mapClass.newInstance();
053:                } catch (InstantiationException e) {
054:                    Assert.shouldNeverReachHere();
055:                } catch (IllegalAccessException e) {
056:                    Assert.shouldNeverReachHere();
057:                }
058:            }
059:
060:            public CollectionMap(Class mapClass, Class collectionClass) {
061:                this .collectionClass = collectionClass;
062:                try {
063:                    map = (Map) mapClass.newInstance();
064:                } catch (InstantiationException e) {
065:                    Assert.shouldNeverReachHere();
066:                } catch (IllegalAccessException e) {
067:                    Assert.shouldNeverReachHere();
068:                }
069:            }
070:
071:            /**
072:             * Creates a CollectionMap.
073:             */
074:            public CollectionMap() {
075:                this (HashMap.class);
076:            }
077:
078:            private Collection getItemsInternal(Object key) {
079:                Collection collection = (Collection) map.get(key);
080:                if (collection == null) {
081:                    try {
082:                        collection = (Collection) collectionClass.newInstance();
083:                    } catch (InstantiationException e) {
084:                        Assert.shouldNeverReachHere();
085:                    } catch (IllegalAccessException e) {
086:                        Assert.shouldNeverReachHere();
087:                    }
088:                    map.put(key, collection);
089:                }
090:                return collection;
091:            }
092:
093:            /**
094:             * Adds the item to the Collection at the given key, creating a new Collection if
095:             * necessary.
096:             * @param key the key to the Collection to which the item should be added
097:             * @param item the item to add
098:             */
099:            public void addItem(Object key, Object item) {
100:                getItemsInternal(key).add(item);
101:            }
102:
103:            public void removeItem(Object key, Object item) {
104:                getItemsInternal(key).remove(item);
105:            }
106:
107:            public void clear() {
108:                map.clear();
109:            }
110:
111:            /**
112:             * Adds the items to the Collection at the given key, creating a new Collection if
113:             * necessary.
114:             * @param key the key to the Collection to which the items should be added
115:             * @param items the items to add
116:             */
117:            public void addItems(Object key, Collection items) {
118:                for (Iterator i = items.iterator(); i.hasNext();) {
119:                    addItem(key, i.next());
120:                }
121:            }
122:
123:            public void addItems(CollectionMap other) {
124:                for (Iterator i = other.keySet().iterator(); i.hasNext();) {
125:                    Object key = i.next();
126:                    addItems(key, other.getItems(key));
127:                }
128:            }
129:
130:            /**
131:             * Returns the values.
132:             * @return a view of the values, backed by this CollectionMap
133:             */
134:            public Collection values() {
135:                return map.values();
136:            }
137:
138:            /**
139:             * Returns the keys.
140:             * @return a view of the keys, backed by this CollectionMap
141:             */
142:            public Set keySet() {
143:                return map.keySet();
144:            }
145:
146:            /**
147:             * Returns the number of mappings.
148:             * @return the number of key-value pairs
149:             */
150:            public int size() {
151:                return map.size();
152:            }
153:
154:            public Object get(Object key) {
155:                return getItems(key);
156:            }
157:
158:            public Collection getItems(Object key) {
159:                return Collections
160:                        .unmodifiableCollection(getItemsInternal(key));
161:            }
162:
163:            public Object remove(Object key) {
164:                return map.remove(key);
165:            }
166:
167:            public boolean containsKey(Object key) {
168:                return map.containsKey(key);
169:            }
170:
171:            public boolean containsValue(Object value) {
172:                return map.containsValue(value);
173:            }
174:
175:            public Set entrySet() {
176:                return map.entrySet();
177:            }
178:
179:            public boolean isEmpty() {
180:                return map.isEmpty();
181:            }
182:
183:            public Object put(Object key, Object value) {
184:                Assert.isTrue(value instanceof  Collection);
185:
186:                return map.put(key, value);
187:            }
188:
189:            public void putAll(Map map) {
190:                for (Iterator i = map.keySet().iterator(); i.hasNext();) {
191:                    Object key = i.next();
192:                    //Delegate to #put so that the assertion is made. [Jon Aquino]
193:                    put(key, map.get(key));
194:                }
195:            }
196:
197:            public void removeItems(Object key, Collection items) {
198:                getItemsInternal(key).removeAll(items);
199:            }
200:
201:            public Map getMap() {
202:                return map;
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.