Source Code Cross Referenced for TransformerMap.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » 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 » Science » Apache commons math 1.1 » org.apache.commons.math.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2004 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.math.util;
017:
018:        import java.io.Serializable;
019:        import java.util.Collection;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import java.util.Set;
023:
024:        import org.apache.commons.math.MathException;
025:
026:        /**
027:         * This TansformerMap automates the transformation of of mixed object types.
028:         * It provides a means to set NumberTransformers that will be selected 
029:         * based on the Class of the object handed to the Maps
030:         * <code>double transform(Object o)</code> method.
031:         * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
032:         */
033:        public class TransformerMap implements  NumberTransformer, Serializable {
034:
035:            /** Serializable version identifier */
036:            private static final long serialVersionUID = -942772950698439883L;
037:
038:            /**
039:             * A default Number Transformer for Numbers and numeric Strings.
040:             */
041:            private NumberTransformer defaultTransformer = null;
042:
043:            /**
044:             * The internal Map.
045:             */
046:            private Map map = null;
047:
048:            /**
049:             * 
050:             */
051:            public TransformerMap() {
052:                map = new HashMap();
053:                defaultTransformer = new DefaultTransformer();
054:            }
055:
056:            /**
057:             * Tests if a Class is present in the TransformerMap.
058:             * @param key Class to check
059:             * @return true|false
060:             */
061:            public boolean containsClass(Class key) {
062:                return map.containsKey(key);
063:            }
064:
065:            /**
066:             * Tests if a NumberTransformer is present in the TransformerMap.
067:             * @param value NumberTransformer to check
068:             * @return true|false
069:             */
070:            public boolean containsTransformer(NumberTransformer value) {
071:                return map.containsValue(value);
072:            }
073:
074:            /**
075:             * Returns the Transformer that is mapped to a class
076:             * if mapping is not present, this returns null.
077:             * @param key The Class of the object
078:             * @return the mapped NumberTransformer or null.
079:             */
080:            public NumberTransformer getTransformer(Class key) {
081:                return (NumberTransformer) map.get(key);
082:            }
083:
084:            /**
085:             * Sets a Class to Transformer Mapping in the Map. If
086:             * the Class is already present, this overwrites that
087:             * mapping.
088:             * @param key The Class
089:             * @param transformer The NumberTransformer
090:             * @return the replaced transformer if one is present
091:             */
092:            public Object putTransformer(Class key,
093:                    NumberTransformer transformer) {
094:                return map.put(key, transformer);
095:            }
096:
097:            /**
098:             * Removes a Class to Transformer Mapping in the Map.
099:             * @param key The Class
100:             * @return the removed transformer if one is present or
101:             * null if none was present.
102:             */
103:            public Object removeTransformer(Class key) {
104:                return map.remove(key);
105:            }
106:
107:            /**
108:             * Clears all the Class to Transformer mappings.
109:             */
110:            public void clear() {
111:                map.clear();
112:            }
113:
114:            /**
115:             * Returns the Set of Classes used as keys in the map.
116:             * @return Set of Classes
117:             */
118:            public Set classes() {
119:                return map.keySet();
120:            }
121:
122:            /**
123:             * Returns the Set of NumberTransformers used as values 
124:             * in the map.
125:             * @return Set of NumberTransformers
126:             */
127:            public Collection transformers() {
128:                return map.values();
129:            }
130:
131:            /**
132:             * Attempts to transform the Object against the map of
133:             * NumberTransformers. Otherwise it returns Double.NaN.
134:             * 
135:             * @see org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
136:             */
137:            public double transform(Object o) throws MathException {
138:                double value = Double.NaN;
139:
140:                if (o instanceof  Number || o instanceof  String) {
141:                    value = defaultTransformer.transform(o);
142:                } else {
143:                    NumberTransformer trans = getTransformer(o.getClass());
144:                    if (trans != null) {
145:                        value = trans.transform(o);
146:                    }
147:                }
148:
149:                return value;
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.