Java Doc for CollationKey.java in  » Internationalization-Localization » icu4j » com » ibm » icu » text » 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 » Internationalization Localization » icu4j » com.ibm.icu.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.ibm.icu.text.CollationKey

CollationKey
final public class CollationKey implements Comparable(Code)

A CollationKey represents a String under the rules of a specific Collator object. Comparing two CollationKeys returns the relative order of the Strings they represent.

Since the rule set of Collators can differ, the sort orders of the same string under two different Collators might differ. Hence comparing CollationKeys generated from different Collators can give incorrect results.

Both the method CollationKey.compareTo(CollationKey) and the method Collator.compare(String, String) compare two strings and returns their relative order. The performance characterictics of these two approaches can differ.

During the construction of a CollationKey, the entire source string is examined and processed into a series of bits terminated by a null, that are stored in the CollationKey. When CollationKey.compareTo(CollationKey) executes, it performs bitwise comparison on the bit sequences. This can incurs startup cost when creating the CollationKey, but once the key is created, binary comparisons are fast. This approach is recommended when the same strings are to be compared over and over again.

On the other hand, implementations of Collator.compare(String, String) can examine and process the strings only until the first characters differing in order. This approach is recommended if the strings are to be compared only once.

More information about the composition of the bit sequence can be found in the user guide.

The following example shows how CollationKeys can be used to sort a list of Strings.

 // Create an array of CollationKeys for the Strings to be sorted.
 Collator myCollator = Collator.getInstance();
 CollationKey[] keys = new CollationKey[3];
 keys[0] = myCollator.getCollationKey("Tom");
 keys[1] = myCollator.getCollationKey("Dick");
 keys[2] = myCollator.getCollationKey("Harry");
 sort( keys );
 
//...
// Inside body of sort routine, compare keys this way if( keys[i].compareTo( keys[j] ) > 0 ) // swap keys[i] and keys[j]
//...
// Finally, when we've returned from sort. System.out.println( keys[0].getSourceString() ); System.out.println( keys[1].getSourceString() ); System.out.println( keys[2].getSourceString() );

This class is not subclassable


See Also:   Collator
See Also:   RuleBasedCollator
author:
   Syn Wee Quek

Inner Class :final public static class BoundMode


Constructor Summary
public  CollationKey(String source, byte key)
     CollationKey constructor. This constructor is given public access, unlike the JDK version, to allow access to users extending the Collator class.
public  CollationKey(String source, RawCollationKey key)
     CollationKey constructor that forces key to release its internal byte array for adoption.

Method Summary
public  intcompareTo(CollationKey target)
    

Compare this CollationKey to another CollationKey.

public  intcompareTo(Object obj)
    

Compare this CollationKey with the specified Object.

public  booleanequals(Object target)
    

Compare this CollationKey and the specified Object for equality.

public  booleanequals(CollationKey target)
    

Compare this CollationKey and the argument target CollationKey for equality. The collation rules of the Collator object which created these objects are applied.

See note in compareTo(CollationKey) for warnings of incorrect results


Parameters:
  target - the CollationKey to compare to.
public  CollationKeygetBound(int boundType, int noOfLevels)
    

Produce a bound for the sort order of a given collation key and a strength level.

public  StringgetSourceString()
     Return the source string that this CollationKey represents.
public  inthashCode()
    

Returns a hash code for this CollationKey.

public  CollationKeymerge(CollationKey source)
    

Merges this CollationKey with another.

public  byte[]toByteArray()
    

Duplicates and returns the value of this CollationKey as a sequence of big-endian bytes terminated by a null.

If two CollationKeys can be legitimately compared, then one can compare the byte arrays of each to obtain the same result, e.g.



Constructor Detail
CollationKey
public CollationKey(String source, byte key)(Code)
CollationKey constructor. This constructor is given public access, unlike the JDK version, to allow access to users extending the Collator class. See Collator.getCollationKey(String) .
Parameters:
  source - string this CollationKey is to represent
Parameters:
  key - array of bytes that represent the collation order of argumentsource terminated by a null
See Also:   Collator



CollationKey
public CollationKey(String source, RawCollationKey key)(Code)
CollationKey constructor that forces key to release its internal byte array for adoption. key will have a null byte array after this construction.
Parameters:
  source - string this CollationKey is to represent
Parameters:
  key - RawCollationKey object that represents the collation order of argument source.
See Also:   Collator
See Also:   RawCollationKey




Method Detail
compareTo
public int compareTo(CollationKey target)(Code)

Compare this CollationKey to another CollationKey. The collation rules of the Collator that created this key are applied.

Note: Comparison between CollationKeys created by different Collators might return incorrect results. See class documentation.


Parameters:
  target - target CollationKey an integer value. If the value is less than zero this CollationKeyis less than than target, if the value is zero they are equal, andif the value is greater than zero this CollationKey is greater than target.
exception:
  NullPointerException - is thrown if argument is null.
See Also:   Collator.compare(StringString)



compareTo
public int compareTo(Object obj)(Code)

Compare this CollationKey with the specified Object. The collation rules of the Collator that created this key are applied.

See note in compareTo(CollationKey) for warnings about possible incorrect results.


Parameters:
  obj - the Object to be compared to. Returns a negative integer, zero, or a positive integer respectively if this CollationKey is less than, equal to, or greater than the given Object.
exception:
  ClassCastException - is thrown when the argument is not a CollationKey. NullPointerException is thrown when the argument is null.
See Also:   CollationKey.compareTo(CollationKey)



equals
public boolean equals(Object target)(Code)

Compare this CollationKey and the specified Object for equality. The collation rules of the Collator that created this key are applied.

See note in compareTo(CollationKey) for warnings about possible incorrect results.


Parameters:
  target - the object to compare to. true if the two keys compare as equal, false otherwise.
See Also:   CollationKey.compareTo(CollationKey)
exception:
  ClassCastException - is thrown when the argument is not a CollationKey. NullPointerException is thrown when the argument is null.



equals
public boolean equals(CollationKey target)(Code)

Compare this CollationKey and the argument target CollationKey for equality. The collation rules of the Collator object which created these objects are applied.

See note in compareTo(CollationKey) for warnings of incorrect results


Parameters:
  target - the CollationKey to compare to. true if two objects are equal, false otherwise.
exception:
  NullPointerException - is thrown when the argument is null.



getBound
public CollationKey getBound(int boundType, int noOfLevels)(Code)

Produce a bound for the sort order of a given collation key and a strength level. This API does not attempt to find a bound for the CollationKey String representation, hence null will be returned in its place.

Resulting bounds can be used to produce a range of strings that are between upper and lower bounds. For example, if bounds are produced for a sortkey of string "smith", strings between upper and lower bounds with primary strength would include "Smith", "SMITH", "sMiTh".

There are two upper bounds that can be produced. If BoundMode.UPPER is produced, strings matched would be as above. However, if a bound is produced using BoundMode.UPPER_LONG is used, the above example will also match "Smithsonian" and similar.

For more on usage, see example in test procedure src/com/ibm/icu/dev/test/collator/CollationAPITest/TestBounds.

Collation keys produced may be compared using the compare API.


Parameters:
  boundType - Mode of bound required. It can be BoundMode.LOWER, which produces a lower inclusive bound, BoundMode.UPPER, that produces upper bound that matches strings of the same length or BoundMode.UPPER_LONG that matches strings that have the same starting substring as the source string.
Parameters:
  noOfLevels - Strength levels required in the resulting bound (for most uses, the recommended value is PRIMARY). Thisstrength should be less than the maximum strength of this CollationKey.See users guide for explanation on the strength levels a collation key can have. the result bounded CollationKey with a valid sort order but a null String representation.
exception:
  IllegalArgumentException - thrown when the strength level requested is higher than or equal to the strength in thisCollationKey. In the case of an Exception, information about the maximum strength to use will be returned in the Exception. The user can then call getBound() again with the appropriate strength.
See Also:   CollationKey
See Also:   CollationKey.BoundMode
See Also:   Collator.PRIMARY
See Also:   Collator.SECONDARY
See Also:   Collator.TERTIARY
See Also:   Collator.QUATERNARY
See Also:   Collator.IDENTICAL



getSourceString
public String getSourceString()(Code)
Return the source string that this CollationKey represents. source string that this CollationKey represents



hashCode
public int hashCode()(Code)

Returns a hash code for this CollationKey. The hash value is calculated on the key itself, not the String from which the key was created. Thus if x and y are CollationKeys, then x.hashCode(x) == y.hashCode() if x.equals(y) is true. This allows language-sensitive comparison in a hash table.

the hash value.



merge
public CollationKey merge(CollationKey source)(Code)

Merges this CollationKey with another. Only the sorting order of the CollationKeys will be merged. This API does not attempt to merge the String representations of the CollationKeys, hence null will be returned as the String representation.

The strength levels are merged with their corresponding counterparts (PRIMARIES with PRIMARIES, SECONDARIES with SECONDARIES etc.).

The merged String representation of the result CollationKey will be a concatenation of the String representations of the 2 source CollationKeys.

Between the values from the same level a separator is inserted. example (uncompressed):

 
 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00
 will be merged as 
 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00
 

This allows for concatenating of first and last names for sorting, among other things.


Parameters:
  source - CollationKey to merge with a CollationKey that contains the valid merged sorting order with a null String representation, i.e. new CollationKey(null, merge_sort_order)
exception:
  IllegalArgumentException - thrown if source CollationKeyargument is null or of 0 length.



toByteArray
public byte[] toByteArray()(Code)

Duplicates and returns the value of this CollationKey as a sequence of big-endian bytes terminated by a null.

If two CollationKeys can be legitimately compared, then one can compare the byte arrays of each to obtain the same result, e.g.

 byte key1[] = collationkey1.toByteArray();
 byte key2[] = collationkey2.toByteArray();
 int key, targetkey;
 int i = 0;
 do {
 key = key1[i] & 0xFF;
 targetkey = key2[i] & 0xFF;
 if (key < targetkey) {
 System.out.println("String 1 is less than string 2");
 return;
 }
 if (targetkey < key) {
 System.out.println("String 1 is more than string 2");
 }
 i ++;
 } while (key != 0 && targetKey != 0);
 System.out.println("Strings are equal.");
 

CollationKey value in a sequence of big-endian byte bytes terminated by a null.



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.