Source Code Cross Referenced for Comparable.java in  » 6.0-JDK-Modules » j2me » java » lang » 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 » j2me » java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package java.lang;
026:
027:        /**
028:         * This interface imposes a total ordering on the objects of each class that
029:         * implements it.  This ordering is referred to as the class's <i>natural
030:         * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
031:         * its <i>natural comparison method</i>.
032:         *
033:         * <p><b><i>This interface is provided as part of the JSR 239 NIO Buffer
034:         * building block.</i></b>
035:         *
036:         * <p> <b><i>This interface is used by the <code>java.nio.ByteBuffer</code>,
037:         * <code>ShortBuffer</code>, <code>IntBuffer</code>, and
038:         * <code>FloatBuffer</code> classes.  The documentation that follows
039:         * is taken from Java Standard Edition version 1.4.2 and may not
040:         * reflect the actual classes and interfaces that are present on a
041:         * particular Java platform that supports the JSR 239 building
042:         * block.</i></b>
043:         * 
044:         * <p>
045:         * Lists (and arrays) of objects that implement this interface can
046:         * be sorted automatically by <tt>Collections.sort</tt> (and
047:         * <tt>Arrays.sort</tt>).  Objects that implement this interface can
048:         * be used as keys in a sorted map or elements in a sorted set,
049:         * without the need to specify a comparator.<p>
050:         *
051:         * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
052:         * with equals</i> if and only if <tt>(e1.compareTo((Object)e2) == 0)</tt> has
053:         * the same boolean value as <tt>e1.equals((Object)e2)</tt> for every
054:         * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>.  Note that <tt>null</tt>
055:         * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
056:         * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
057:         * returns <tt>false</tt>.<p>
058:         *
059:         * It is strongly recommended (though not required) that natural orderings be
060:         * consistent with equals.  This is so because sorted sets (and sorted maps)
061:         * without explicit comparators behave "strangely" when they are used with
062:         * elements (or keys) whose natural ordering is inconsistent with equals.  In
063:         * particular, such a sorted set (or sorted map) violates the general contract
064:         * for set (or map), which is defined in terms of the <tt>equals</tt>
065:         * method.<p>
066:         *
067:         * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
068:         * <tt>(!a.equals((Object)b) && a.compareTo((Object)b) == 0)</tt> to a sorted
069:         * set that does not use an explicit comparator, the second <tt>add</tt>
070:         * operation returns false (and the size of the sorted set does not increase)
071:         * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
072:         * perspective.<p>
073:         *
074:         * Virtually all Java core classes that implement comparable have natural
075:         * orderings that are consistent with equals.  One exception is
076:         * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
077:         * <tt>BigDecimal</tt> objects with equal values and different precisions 
078:         * (such as 4.0 and 4.00).<p>
079:         *
080:         * For the mathematically inclined, the <i>relation</i> that defines
081:         * the natural ordering on a given class C is:<pre>
082:         *       {(x, y) such that x.compareTo((Object)y) &lt;= 0}.
083:         * </pre> The <i>quotient</i> for this total order is: <pre>
084:         *       {(x, y) such that x.compareTo((Object)y) == 0}.
085:         * </pre>
086:         *
087:         * It follows immediately from the contract for <tt>compareTo</tt> that the
088:         * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
089:         * natural ordering is a <i>total order</i> on <tt>C</tt>.  When we say that a
090:         * class's natural ordering is <i>consistent with equals</i>, we mean that the
091:         * quotient for the natural ordering is the equivalence relation defined by
092:         * the class's <tt>equals(Object)</tt> method:<pre>
093:         *     {(x, y) such that x.equals((Object)y)}.
094:         * </pre><p>
095:         *
096:         * This interface is a member of the Java Collections Framework.
097:         *
098:         * @version 1.20, 01/23/03
099:         * @see java.util.Comparator
100:         * @see java.util.Collections#sort(java.util.List)
101:         * @see java.util.Arrays#sort(Object[])
102:         * @see java.util.SortedSet
103:         * @see java.util.SortedMap
104:         * @see java.util.TreeSet
105:         * @see java.util.TreeMap
106:         * @since 1.2
107:         */
108:
109:        public interface Comparable {
110:            /**
111:             * Compares this object with the specified object for order.  Returns a
112:             * negative integer, zero, or a positive integer as this object is less
113:             * than, equal to, or greater than the specified object.<p>
114:             *
115:             * In the foregoing description, the notation
116:             * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
117:             * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
118:             * <tt>0</tt>, or <tt>1</tt> according to whether the value of <i>expression</i>
119:             * is negative, zero or positive.
120:             *
121:             * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
122:             * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
123:             * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
124:             * <tt>y.compareTo(x)</tt> throws an exception.)<p>
125:             *
126:             * The implementor must also ensure that the relation is transitive:
127:             * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
128:             * <tt>x.compareTo(z)&gt;0</tt>.<p>
129:             *
130:             * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
131:             * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
132:             * all <tt>z</tt>.<p>
133:             *
134:             * It is strongly recommended, but <i>not</i> strictly required that
135:             * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
136:             * class that implements the <tt>Comparable</tt> interface and violates
137:             * this condition should clearly indicate this fact.  The recommended
138:             * language is "Note: this class has a natural ordering that is
139:             * inconsistent with equals."
140:             * 
141:             * @param   o the Object to be compared.
142:             * @return  a negative integer, zero, or a positive integer as this object
143:             *		is less than, equal to, or greater than the specified object.
144:             * 
145:             * @throws ClassCastException if the specified object's type prevents it
146:             *         from being compared to this Object.
147:             */
148:            public int compareTo(Object o);
149:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.