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


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.j2me.global;
027:
028:        import javax.microedition.global.StringComparator;
029:        import javax.microedition.global.ResourceManager;
030:        import javax.microedition.global.ResourceException;
031:        import javax.microedition.global.UnsupportedLocaleException;
032:
033:        /**
034:         * This class realizes string comparison methods of
035:         * {@link javax.microedition.global.StringComparator}. Specifically, these are:
036:         * <ul>
037:         *   <li> {@link #compare(String, String)}
038:         *   <li> {@link #equals(String, String)}
039:         * </ul>
040:         * <p>
041:         * This realization of <code>StringComparator</code> is intended to be based on
042:         * native string comparison functions. Regarding this,
043:         * <code>StringComparatorImpl</code> uses locale index that points to its locale
044:         * instead of working with explicit locale code.
045:         */
046:        public class StringComparatorImpl implements  CommonStringComparator {
047:
048:            /**
049:             * Current <code>StringComparatorImpl</code> level of comparison.
050:             * Possible values are:
051:             * <ul>
052:             *  <li> javax.microedition.global.StringComparator#LEVEL1
053:             *  <li> javax.microedition.global.StringComparator#LEVEL2
054:             *  <li> javax.microedition.global.StringComparator#LEVEL3
055:             *  <li> javax.microedition.global.StringComparator#IDENTICAL
056:             * </ul>
057:             */
058:            private int level;
059:
060:            /**
061:             * Current <code>StringComparatorImpl</code> locale index in the list of
062:             * supported locales.
063:             */
064:            private int locale_index;
065:
066:            /**
067:             * Constructs an instance using the specified locale and collation level.
068:             * <p>
069:             * If the specified locale is <code>null</code> or the empty string, this 
070:             * class uses the generic collation algorithm.
071:             *
072:             * @param locale  the locale to use, or <code>null</code> to use the generic
073:             *      collation algorithm
074:             * @param level   the collation level to use
075:             * @throws UnsupportedLocaleException if the specified locale is not 
076:             *      supported by the StringComparator implementation
077:             * @throws IllegalArgumentException if the specified locale is 
078:             *      non-<code>null</code> but is not valid according to the MIDP 
079:             *      specification, or if <code>level</code> is not one of the constants 
080:             *      defined in this class
081:             * @see javax.microedition.global.StringComparator#LEVEL1
082:             * @see javax.microedition.global.StringComparator#LEVEL2
083:             * @see javax.microedition.global.StringComparator#LEVEL3
084:             * @see javax.microedition.global.StringComparator#IDENTICAL
085:             */
086:            public StringComparatorImpl(String locale, int level) {
087:                this .level = level;
088:
089:                locale_index = CollationAbstractionLayerImpl
090:                        .getCollationLocaleIndex(locale);
091:                if (locale_index == -1) {
092:                    throw new UnsupportedLocaleException("Locale \"" + locale
093:                            + "\" unsupported.");
094:                }
095:            }
096:
097:            /**
098:             * Compares the two strings using the rules specific to the associated 
099:             * locale of this instance. Use the <code>equals</code> method to more 
100:             * conveniently test for equality.
101:             * 
102:             * @param s1 first string to compare
103:             * @param s2 second string to compare
104:             * @return negative if <code>s1</code> belongs before <code>s2</code>,
105:             *      zero if the strings are equal, positive if <code>s1</code> belongs
106:             *      after <code>s2</code>
107:             * @throws NullPointerException if either <code>s1</code> or <code>s2</code>
108:             *      is <code>null</code>
109:             * @see #equals(String, String)
110:             */
111:            public int compare(String s1, String s2) {
112:                if (s1 == null || s2 == null) {
113:                    throw new NullPointerException(
114:                            "Cannot compare null strings");
115:                }
116:                return compare0(locale_index, s1, s2, level);
117:            }
118:
119:            /**
120:             * Tests if the two strings are equal according to the rules specific to 
121:             * the associated locale of this instance.
122:             *
123:             * @param s1 first string to compare
124:             * @param s2 second string to compare
125:             * @return <code>true</code> if the strings are equal, <code>false</code> 
126:             *      if not
127:             * @throws NullPointerException if either s1 or s2 is <code>null</code>
128:             */
129:            public boolean equals(String s1, String s2) {
130:                return compare(s1, s2) == 0;
131:            }
132:
133:            /**
134:             *  Compare two strings using locale- and level-specific rules.
135:             *
136:             * @param s1            first string to compare
137:             * @param s2            second string to compare
138:             * @param locale_index  the locale index in supported locales list
139:             * @param level         the collation level to use
140:             * @return negative if <code>s1</code> belongs before <code>s2</code>,
141:             *      zero if the strings are equal, positive if <code>s1</code> belongs
142:             *      after <code>s2</code>
143:             */
144:            private static native int compare0(int locale_index, String s1,
145:                    String s2, int level);
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.