Source Code Cross Referenced for TiedMapEntry.java in  » Library » Apache-common-Collections » org » apache » commons » collections » keyvalue » 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 » Library » Apache common Collections » org.apache.commons.collections.keyvalue 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2003-2006 The Apache Software Foundation
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.apache.commons.collections.keyvalue;
017:
018:        import java.io.Serializable;
019:        import java.util.Map;
020:
021:        import org.apache.commons.collections.KeyValue;
022:
023:        /**
024:         * A {@link java.util.Map.Entry Map.Entry} tied to a map underneath.
025:         * <p>
026:         * This can be used to enable a map entry to make changes on the underlying
027:         * map, however this will probably mess up any iterators.
028:         *
029:         * @since Commons Collections 3.0
030:         * @version $Revision: 405927 $ $Date: 2006-05-12 23:57:03 +0100 (Fri, 12 May 2006) $
031:         * 
032:         * @author Stephen Colebourne
033:         */
034:        public class TiedMapEntry implements  Map.Entry, KeyValue, Serializable {
035:
036:            /** Serialization version */
037:            private static final long serialVersionUID = -8453869361373831205L;
038:
039:            /** The map underlying the entry/iterator */
040:            private final Map map;
041:            /** The key */
042:            private final Object key;
043:
044:            /**
045:             * Constructs a new entry with the given Map and key.
046:             *
047:             * @param map  the map
048:             * @param key  the key
049:             */
050:            public TiedMapEntry(Map map, Object key) {
051:                super ();
052:                this .map = map;
053:                this .key = key;
054:            }
055:
056:            // Map.Entry interface
057:            //-------------------------------------------------------------------------
058:            /**
059:             * Gets the key of this entry
060:             * 
061:             * @return the key
062:             */
063:            public Object getKey() {
064:                return key;
065:            }
066:
067:            /**
068:             * Gets the value of this entry direct from the map.
069:             * 
070:             * @return the value
071:             */
072:            public Object getValue() {
073:                return map.get(key);
074:            }
075:
076:            /**
077:             * Sets the value associated with the key direct onto the map.
078:             * 
079:             * @param value  the new value
080:             * @return the old value
081:             * @throws IllegalArgumentException if the value is set to this map entry
082:             */
083:            public Object setValue(Object value) {
084:                if (value == this ) {
085:                    throw new IllegalArgumentException(
086:                            "Cannot set value to this map entry");
087:                }
088:                return map.put(key, value);
089:            }
090:
091:            /**
092:             * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>.
093:             * <p>
094:             * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
095:             * 
096:             * @param obj  the object to compare to
097:             * @return true if equal key and value
098:             */
099:            public boolean equals(Object obj) {
100:                if (obj == this ) {
101:                    return true;
102:                }
103:                if (obj instanceof  Map.Entry == false) {
104:                    return false;
105:                }
106:                Map.Entry other = (Map.Entry) obj;
107:                Object value = getValue();
108:                return (key == null ? other.getKey() == null : key.equals(other
109:                        .getKey()))
110:                        && (value == null ? other.getValue() == null : value
111:                                .equals(other.getValue()));
112:            }
113:
114:            /**
115:             * Gets a hashCode compatible with the equals method.
116:             * <p>
117:             * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}
118:             * 
119:             * @return a suitable hash code
120:             */
121:            public int hashCode() {
122:                Object value = getValue();
123:                return (getKey() == null ? 0 : getKey().hashCode())
124:                        ^ (value == null ? 0 : value.hashCode());
125:            }
126:
127:            /**
128:             * Gets a string version of the entry.
129:             * 
130:             * @return entry as a string
131:             */
132:            public String toString() {
133:                return getKey() + "=" + getValue();
134:            }
135:
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.