Java Doc for ClassChanger.java in  » GIS » GeoTools-2.4.1 » org » geotools » resources » 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 » GeoTools 2.4.1 » org.geotools.resources 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.geotools.resources.ClassChanger

ClassChanger
abstract public class ClassChanger (Code)
A central place to register transformations between an arbitrary class and a Number . For example, it is sometime convenient to consider Date objects as if they were Long objects for computation purpose in generic algorithms. Client can call the following method to convert an arbitrary object to a Number :
 Object someArbitraryObject = new Date();
 Number myObjectAsANumber = 
ClassChanger.toNumber ClassChanger.toNumber (someArbitraryObject);
 

since:
   2.0
version:
   $Id: ClassChanger.java 26581 2007-08-17 18:04:30Z desruisseaux $
author:
   Martin Desruisseaux



Constructor Summary
protected  ClassChanger(Class source, Class target)
     Construct a new class changer.

Method Summary
public static  Numbercast(Number n, Class c)
     Casts the number to the specified class.
abstract protected  Numberconvert(Comparable object)
     Returns the numerical value for an object.
Parameters:
  object - Object to convert (may be null).
public static  ClassgetFinestClass(Class c1, Class c2)
     Returns the class of the finest type.
public static  ClassgetFinestClass(double value)
     Returns the smallest class capable to hold the specified value.
public static synchronized  ClassgetTransformedClass(Class source)
     Returns the target class for the specified source class, if a suitable transformation is known.
public static  ClassgetWidestClass(Number n1, Number n2)
     Returns the class of the widest type.
public static  ClassgetWidestClass(Class c1, Class c2)
     Returns the class of the widest type.
abstract protected  ComparableinverseConvert(Number value)
     Returns an instance of the converted classe from a numerical value.
Parameters:
  value - The value to wrap.
public static synchronized  voidregister(ClassChanger converter)
     Registers a new transformation.
public static  ComparabletoComparable(Number value, Class classe)
     Wraps the specified number as an instance of the specified classe. For example toComparable(Date.class, new Long(time)) is equivalent to new Date(time).
public static  NumbertoNumber(Comparable object)
     Returns the numeric value for the specified object.
public static  ClasstoPrimitive(Class c)
     Converts a wrapper class to a primitive class.
public  StringtoString()
     Returns a string representation for this class changer.
public static  ClasstoWrapper(Class c)
     Converts a primitive class to a wrapper class.


Constructor Detail
ClassChanger
protected ClassChanger(Class source, Class target)(Code)
Construct a new class changer.
Parameters:
  source - Parent class for ClassChanger.convert's input objects.
Parameters:
  target - Parent class for ClassChanger.convert's output objects.




Method Detail
cast
public static Number cast(Number n, Class c)(Code)
Casts the number to the specified class. The class must by one of Byte , Short , Integer , Long , Float or Double . valueOf



convert
abstract protected Number convert(Comparable object) throws ClassCastException(Code)
Returns the numerical value for an object.
Parameters:
  object - Object to convert (may be null). The object's numerical value.
throws:
  ClassCastException - if object is not of the expected class.



getFinestClass
public static Class getFinestClass(Class c1, Class c2)(Code)
Returns the class of the finest type. Classes c1 and c2 must be of any of Byte , Short , Integer , Long , Float or Double types. At most one of the argument can be null.



getFinestClass
public static Class getFinestClass(double value)(Code)
Returns the smallest class capable to hold the specified value.



getTransformedClass
public static synchronized Class getTransformedClass(Class source)(Code)
Returns the target class for the specified source class, if a suitable transformation is known. The source class is a Comparable subclass that will be specified as input to ClassChanger.convert . The target class is a Number subclass that will be returned as output by ClassChanger.convert . If no suitable mapping is found, then source is returned.



getWidestClass
public static Class getWidestClass(Number n1, Number n2)(Code)
Returns the class of the widest type. Numbers n1 and n2 must be instance of any of Byte , Short , Integer , Long , Float or Double types. At most one of the argument can be null.



getWidestClass
public static Class getWidestClass(Class c1, Class c2)(Code)
Returns the class of the widest type. Classes c1 and c2 must be of any of Byte , Short , Integer , Long , Float or Double types. At most one of the argument can be null.



inverseConvert
abstract protected Comparable inverseConvert(Number value)(Code)
Returns an instance of the converted classe from a numerical value.
Parameters:
  value - The value to wrap. An instance of the source classe.



register
public static synchronized void register(ClassChanger converter) throws IllegalStateException(Code)
Registers a new transformation. All registered ClassChanger will be taken in account by the ClassChanger.toNumber method. The example below register a transformation for the Date class:
  ClassChanger.register(new ClassChanger(Date.class, Long.class) {
      protected Number convert(final Comparable o) {
          return new Long(((Date) o).getTime());
      }
  
      protected Comparable inverseConvert(final Number number) {
          return new Date(number.longValue());
      }
  });
 

Parameters:
  converter - The ClassChanger to add.
throws:
  IllegalStateException - if an other ClassChanger was alreadyregistered for the same source class. This is usuallynot a concern since the registration usually take place during theclass initialization ("static" constructor).



toComparable
public static Comparable toComparable(Number value, Class classe) throws ClassNotFoundException(Code)
Wraps the specified number as an instance of the specified classe. For example toComparable(Date.class, new Long(time)) is equivalent to new Date(time). There is of course no point to use this method if the destination class is know at compile time. This method is useful for creating instance of classes choosen dynamically at run time.
Parameters:
  value - The numerical value (may be null).
Parameters:
  classe - The desired classe for return value.
throws:
  ClassNotFoundException - if classe is not a registered class.



toNumber
public static Number toNumber(Comparable object) throws ClassNotFoundException(Code)
Returns the numeric value for the specified object. For example the code toNumber(new Date()) returns the Date.getTime value of the specified date object as a Long .
Parameters:
  object - Object to convert (may be null). null if object was null; otherwise object if the supplied object is already an instanceof Number; otherwise a new number with the numerical value.
throws:
  ClassNotFoundException - if object is not an instanceof a registered class.



toPrimitive
public static Class toPrimitive(Class c) throws IllegalArgumentException(Code)
Converts a wrapper class to a primitive class. For example this method converts .class to Double. .
Parameters:
  c - The wrapper class. The primitive class.
throws:
  IllegalArgumentException - if the specified class is not a wrapper for a primitive.



toString
public String toString()(Code)
Returns a string representation for this class changer.



toWrapper
public static Class toWrapper(Class c) throws IllegalArgumentException(Code)
Converts a primitive class to a wrapper class. For example this method converts Double. to .class.
Parameters:
  c - The primitive class. The wrapper class.
throws:
  IllegalArgumentException - if the specified class is not a primitive.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.