API java : CollationKey


java.text
Class CollationKey

java.lang.Object
  extended by java.text.CollationKey
All Implemented Interfaces:
Comparable<CollationKey>

public final class CollationKey
extends Object
implements Comparable<CollationKey>

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. Using CollationKeys to compare Strings is generally faster than using Collator.compare. Thus, when the Strings must be compared multiple times, for example when sorting a list of Strings. It's more efficient to use CollationKeys.

You can not create CollationKeys directly. Rather, generate them by calling Collator.getCollationKey. You can only compare CollationKeys generated from the same Collator object.

Generating a CollationKey for a String involves examining the entire String and converting it to series of bits that can be compared bitwise. This allows fast comparisons once the keys are generated. The cost of generating keys is recouped in faster comparisons when Strings need to be compared many times. On the other hand, the result of a comparison is often determined by the first couple of characters of each String. Collator.compare examines only as many characters as it needs which allows it to be faster when doing single comparisons.

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

  1. // Create an array of CollationKeys for the Strings to be sorted.
  2. Collator myCollator = Collator.getInstance();
  3. CollationKey[] keys = new CollationKey[3];
  4. keys[0] = myCollator.getCollationKey("Tom");
  5. keys[1] = myCollator.getCollationKey("Dick");
  6. keys[2] = myCollator.getCollationKey("Harry");
  7. sort( keys );
  8. <br>
  9. //...
  10. <br>
  11. // Inside body of sort routine, compare keys this way
  12. if( keys[i].compareTo( keys[j] ) > 0 )
  13. // swap keys[i] and keys[j]
  14. <br>
  15. //...
  16. <br>
  17. // Finally, when we've returned from sort.
  18. System.out.println( keys[0].getSourceString() );
  19. System.out.println( keys[1].getSourceString() );
  20. System.out.println( keys[2].getSourceString() );

See Also:
Collator, RuleBasedCollator

Method Summary
 int compareTo(CollationKey target)
          Compare this CollationKey to the target CollationKey.
 boolean equals(Object target)
          Compare this CollationKey and the target CollationKey for equality.
 String getSourceString()
          Returns the String that this CollationKey represents.
 int hashCode()
          Creates a hash code for this CollationKey.
 byte[] toByteArray()
          Converts the CollationKey to a sequence of bits.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compareTo

public int compareTo(CollationKey target)
Compare this CollationKey to the target CollationKey. The collation rules of the Collator object which created these keys are applied. Note: CollationKeys created by different Collators can not be compared.

Specified by:
compareTo in interface Comparable<CollationKey>
Parameters:
target - target CollationKey
Returns:
Returns an integer value. Value is less than zero if this is less than target, value is zero if this and target are equal and value is greater than zero if this is greater than target.
See Also:
Collator.compare(java.lang.String, java.lang.String)

equals

public boolean equals(Object target)
Compare this CollationKey and the target CollationKey for equality. The collation rules of the Collator object which created these keys are applied. Note: CollationKeys created by different Collators can not be compared.

Overrides:
equals in class Object
Parameters:
target - the CollationKey to compare to.
Returns:
Returns true if two objects are equal, false otherwise.
See Also:
Object.hashCode(), Hashtable

hashCode

public int hashCode()
Creates 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. See the CollatinKey class description for an example.

Overrides:
hashCode in class Object
Returns:
the hash value based on the string's collation order.
See Also:
Object.equals(java.lang.Object), Hashtable

getSourceString

public String getSourceString()
Returns the String that this CollationKey represents.


toByteArray

public byte[] toByteArray()
Converts the CollationKey to a sequence of bits. If two CollationKeys could be legitimately compared, then one could compare the byte arrays for each of those keys to obtain the same result. Byte arrays are organized most significant byte first.


Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-677
Document créé le 19/07/06 06:58, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/text/CollationKey.html Document affiché 2 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,73 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Compter en octal, c’est comme compter en décimal, si on n’utilise pas ses pouces

Tom Lehrer
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 19:46, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)