Source Code Cross Referenced for NegotiableNumeric.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » javax » media » jai » remote » 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 » 6.0 JDK Modules » Java Advanced Imaging » javax.media.jai.remote 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: NegotiableNumeric.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:57:51 $
010:         * $State: Exp $
011:         */package javax.media.jai.remote;
012:
013:        /**
014:         * A class that wraps a numeric primitive data type or a subclass of 
015:         * <code>Number</code> to implement the <code>Negotiable</code> interface. 
016:         * <code>NegotiableNumeric</code> is a convenience class to specify a
017:         * <code>Negotiable</code> value for a parameter which has a single
018:         * valid numeric value.
019:         *
020:         * @since JAI 1.1
021:         */
022:        public class NegotiableNumeric implements  Negotiable {
023:
024:            // The numeric value stored as a Number subclass;
025:            Number number;
026:
027:            // The Class of the Number.    
028:            Class elementClass;
029:
030:            /**
031:             * Creates a <code>NegotiableNumeric</code> given a <code>byte</code>.
032:             *
033:             * @param b The <code>byte</code> to be wrapped to implement 
034:             *          <code>Negotiable</code>.
035:             */
036:            public NegotiableNumeric(byte b) {
037:                number = new Byte(b);
038:                elementClass = number.getClass();
039:            }
040:
041:            /**
042:             * Creates a <code>NegotiableNumeric</code> given a <code>short</code>.
043:             *
044:             * @param s The <code>short</code> to be wrapped to implement 
045:             *          <code>Negotiable</code>.
046:             */
047:            public NegotiableNumeric(short s) {
048:                number = new Short(s);
049:                elementClass = number.getClass();
050:            }
051:
052:            /**
053:             * Creates a <code>NegotiableNumeric</code> given an <code>int</code>.
054:             *
055:             * @param i The <code>int</code> to be wrapped to implement 
056:             *          <code>Negotiable</code>.
057:             */
058:            public NegotiableNumeric(int i) {
059:                number = new Integer(i);
060:                elementClass = number.getClass();
061:            }
062:
063:            /**
064:             * Creates a <code>NegotiableNumeric</code> given a <code>long</code>.
065:             *
066:             * @param l The <code>long</code> to be wrapped to implement 
067:             *          <code>Negotiable</code>.
068:             */
069:            public NegotiableNumeric(long l) {
070:                number = new Long(l);
071:                elementClass = number.getClass();
072:            }
073:
074:            /**
075:             * Creates a <code>NegotiableNumeric</code> given a <code>float</code>.
076:             *
077:             * @param f The <code>float</code> to be wrapped to implement 
078:             *          <code>Negotiable</code>.
079:             */
080:            public NegotiableNumeric(float f) {
081:                number = new Float(f);
082:                elementClass = number.getClass();
083:            }
084:
085:            /**
086:             * Creates a <code>NegotiableNumeric</code> given a <code>double</code>.
087:             *
088:             * @param d The <code>double</code> to be wrapped to implement 
089:             *          <code>Negotiable</code>.
090:             */
091:            public NegotiableNumeric(double d) {
092:                number = new Double(d);
093:                elementClass = number.getClass();
094:            }
095:
096:            /**
097:             * Creates a <code>NegotiableNumeric</code> given a <code>Number</code>.
098:             *
099:             * @param n The <code>Number</code> to be wrapped to implement 
100:             *          <code>Negotiable</code>.
101:             *
102:             * @throws IllegalArgumentException if n is null.
103:             */
104:            public NegotiableNumeric(Number n) {
105:
106:                if (n == null) {
107:                    throw new IllegalArgumentException(JaiI18N
108:                            .getString("NegotiableNumeric0"));
109:                }
110:
111:                number = n;
112:                elementClass = number.getClass();
113:            }
114:
115:            /**
116:             * Returns the <code>Number</code> that is currently the valid value
117:             * for this class. A valid primitive data type value, such as int, 
118:             * will be returned as a member of the corresponding wrapper class, 
119:             * such as <code>Integer</code>.
120:             */
121:            public Number getNumber() {
122:                return number;
123:            }
124:
125:            /**
126:             * Returns a <code>NegotiableNumeric</code> that contains the value
127:             * that is common to this <code>NegotiableNumeric</code>
128:             * and the one supplied, i.e the <code>Number</code> encapsulated in
129:             * both the <code>NegotiableNumeric</code> are equal. If the supplied
130:             * <code>Negotiable</code> is not a <code>NegotiableNumeric</code> with
131:             * its element being of the same <code>Class</code> as this class', or
132:             * if there is no common value (i.e the values are not equal), the
133:             * negotiation will fail and <code>null</code> will be returned.
134:             *
135:             * @param other The <code>Negotiable</code> to negotiate with.
136:             */
137:            public Negotiable negotiate(Negotiable other) {
138:                if (other == null)
139:                    return null;
140:
141:                if (!(other instanceof  NegotiableNumeric)
142:                        || other.getNegotiatedValueClass() != elementClass) {
143:                    return null;
144:                }
145:
146:                NegotiableNumeric otherNN = (NegotiableNumeric) other;
147:
148:                if (number.equals(otherNN.getNumber())) {
149:                    return new NegotiableNumeric(number);
150:                } else {
151:                    return null;
152:                }
153:            }
154:
155:            /**
156:             * Returns the result of the negotiation as a <code>Number</code> 
157:             * subclass. Values belonging to a base type, such as <code>int</code>, 
158:             * will be returned as a member of the corresponding <code>Number</code>
159:             * subclass, such as <code>Integer</code>.
160:             */
161:            public Object getNegotiatedValue() {
162:                return number;
163:            }
164:
165:            /**
166:             * Returns the <code>Class</code> of the negotiated value. Values
167:             * belonging to a base type, such as <code>int</code>, will be returned
168:             * as a member of the corresponding <code>Number</code> subclass, such as
169:             * <code>Integer</code>. The <code>Class</code> returned similarly will be
170:             * a <code>Number</code> subclass.
171:             */
172:            public Class getNegotiatedValueClass() {
173:                return elementClass;
174:            }
175:
176:            /**
177:             * A convenience method to return the single negotiated value as a
178:             * <code>byte</code>. 
179:             *
180:             * @throws ClassCastException if the value is of a different Class type.
181:             */
182:            public byte getNegotiatedValueAsByte() {
183:                if (elementClass != Byte.class)
184:                    throw new ClassCastException(JaiI18N
185:                            .getString("NegotiableNumeric1"));
186:                return number.byteValue();
187:            }
188:
189:            /**
190:             * A convenience method to return the single negotiated value as a 
191:             * <code>short</code>. 
192:             *
193:             * @throws ClassCastException if the value is of a different Class type.
194:             */
195:            public short getNegotiatedValueAsShort() {
196:                if (elementClass != Short.class)
197:                    throw new ClassCastException(JaiI18N
198:                            .getString("NegotiableNumeric1"));
199:                return number.shortValue();
200:            }
201:
202:            /**
203:             * A convenience method to return the single negotiated value as a
204:             * <code>int</code>. 
205:             *
206:             * @throws ClassCastException if the value is of a different Class type.
207:             */
208:            public int getNegotiatedValueAsInt() {
209:                if (elementClass != Integer.class)
210:                    throw new ClassCastException(JaiI18N
211:                            .getString("NegotiableNumeric1"));
212:                return number.intValue();
213:            }
214:
215:            /**
216:             * A convenience method to return the single negotiated value as a
217:             * <code>long</code>. 
218:             *
219:             * @throws ClassCastException if the value is of a different Class type.
220:             */
221:            public long getNegotiatedValueAsLong() {
222:                if (elementClass != Long.class)
223:                    throw new ClassCastException(JaiI18N
224:                            .getString("NegotiableNumeric1"));
225:                return number.longValue();
226:            }
227:
228:            /**
229:             * A convenience method to return the single negotiated value as a 
230:             * <code>float</code>. 
231:             *
232:             * @throws ClassCastException if the value is of a different Class type.
233:             */
234:            public float getNegotiatedValueAsFloat() {
235:                if (elementClass != Float.class)
236:                    throw new ClassCastException(JaiI18N
237:                            .getString("NegotiableNumeric1"));
238:                return number.floatValue();
239:            }
240:
241:            /**
242:             * A convenience method to return the single negotiated value as a
243:             * <code>double</code>. 
244:             *
245:             * @throws ClassCastException if the value is of a different Class type.
246:             */
247:            public double getNegotiatedValueAsDouble() {
248:                if (elementClass != Double.class)
249:                    throw new ClassCastException(JaiI18N
250:                            .getString("NegotiableNumeric1"));
251:                return number.doubleValue();
252:            }
253:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.