Source Code Cross Referenced for LinkedHashMap.java in  » Internationalization-Localization » icu4j » com » ibm » icu » impl » 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 » Internationalization Localization » icu4j » com.ibm.icu.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * *****************************************************************************
003:         * Copyright (C) 2006, International Business Machines Corporation and others.
004:         * All Rights Reserved.
005:         * *****************************************************************************
006:         */
007:        package com.ibm.icu.impl;
008:
009:        import java.util.HashMap;
010:        import java.util.Iterator;
011:        import java.util.LinkedList;
012:        import java.util.Map;
013:        import java.util.Set;
014:
015:        /**
016:         * JDK1.4 LinkedHashMap equivalent implementation for
017:         * Java foundation profile support.  This class is used
018:         * by <code>com.ibm.icu.impl.LRUMap</code> on eclipse
019:         * distributions, which require JDK1.3/Java Foundation
020:         * profile support.
021:         */
022:        public class LinkedHashMap extends HashMap {
023:            private static final long serialVersionUID = -2497823480436618075L;
024:
025:            private boolean accessOrder = false;
026:            private LinkedList keyList = new LinkedList();
027:
028:            public LinkedHashMap() {
029:                super ();
030:            }
031:
032:            public LinkedHashMap(int initialCapacity) {
033:                super (initialCapacity);
034:            }
035:
036:            public LinkedHashMap(int initialCapacity, float loadFactor) {
037:                super (initialCapacity, loadFactor);
038:            }
039:
040:            public LinkedHashMap(int initialCapacity, float loadFactor,
041:                    boolean accessOrder) {
042:                super (initialCapacity, loadFactor);
043:                this .accessOrder = accessOrder;
044:            }
045:
046:            public LinkedHashMap(Map m) {
047:                super ();
048:                putAll(m);
049:            }
050:
051:            public void clear() {
052:                super .clear();
053:                keyList.clear();
054:            }
055:
056:            public Object remove(Object key) {
057:                Object value = super .remove(key);
058:                if (value == null) {
059:                    // null might be returned for a map entry
060:                    // for null value.  So we need to check if
061:                    // the key is actually available or not.
062:                    // If the key list contains the key, then
063:                    // remove the key from the list.
064:                    int index = getKeyIndex(key);
065:                    if (index >= 0) {
066:                        keyList.remove(index);
067:                    }
068:                }
069:                return value;
070:            }
071:
072:            public Object get(Object key) {
073:                Object value = super .get(key);
074:                if (accessOrder) {
075:                    // When accessOrder is true, move the key
076:                    // to the end of the list
077:                    int index = getKeyIndex(key);
078:                    if (index >= 0) {
079:                        if (index != keyList.size() - 1) {
080:                            keyList.remove(index);
081:                            keyList.addLast(key);
082:                        }
083:                    }
084:                }
085:                return value;
086:            }
087:
088:            public void putAll(Map m) {
089:                Set keySet = m.keySet();
090:                Iterator it = keySet.iterator();
091:                while (it.hasNext()) {
092:                    Object key = it.next();
093:                    Object value = m.get(key);
094:                    put(key, value);
095:                }
096:            }
097:
098:            public Object put(Object key, Object value) {
099:                Object oldValue = super .put(key, value);
100:
101:                // Move the key to the end of key list
102:                // if it exists.  If not, append the key
103:                // to the end of key list
104:                int index = getKeyIndex(key);
105:                if (index >= 0) {
106:                    if (index != keyList.size() - 1) {
107:                        keyList.remove(index);
108:                        keyList.addLast(key);
109:                    }
110:                } else {
111:                    keyList.addLast(key);
112:                }
113:
114:                // Check if we need to remove the eldest
115:                // entry.
116:                Object eldestKey = keyList.getFirst();
117:                Object eldestValue = super .get(eldestKey);
118:                MapEntry entry = new MapEntry(eldestKey, eldestValue);
119:                if (removeEldestEntry(entry)) {
120:                    keyList.removeFirst();
121:                    super .remove(eldestKey);
122:                }
123:
124:                return oldValue;
125:            }
126:
127:            protected boolean removeEldestEntry(Map.Entry eldest) {
128:                return false;
129:            }
130:
131:            private int getKeyIndex(Object key) {
132:                int index = -1;
133:                for (int i = 0; i < keyList.size(); i++) {
134:                    Object o = keyList.get(i);
135:                    if (o.equals(key)) {
136:                        index = i;
137:                        break;
138:                    }
139:                }
140:                return index;
141:            }
142:
143:            protected static class MapEntry implements  Map.Entry {
144:                private Object key;
145:                private Object value;
146:
147:                private MapEntry(Object key, Object value) {
148:                    this .key = key;
149:                    this .value = value;
150:                }
151:
152:                public boolean equals(Object o) {
153:                    Object otherKey = ((Map.Entry) o).getKey();
154:                    Object otherValue = ((Map.Entry) o).getValue();
155:                    if (key.equals(otherKey) && value.equals(otherValue)) {
156:                        return true;
157:                    }
158:                    return false;
159:                }
160:
161:                public Object getKey() {
162:                    return key;
163:                }
164:
165:                public Object getValue() {
166:                    return value;
167:                }
168:
169:                public Object setValue(Object value) {
170:                    Object oldValue = this.value;
171:                    this.value = value;
172:                    return oldValue;
173:                }
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.