API java : CollationElementIterator


java.text
Class CollationElementIterator

java.lang.Object
  extended by java.text.CollationElementIterator

public final class CollationElementIterator
extends Object

The CollationElementIterator class is used as an iterator to walk through each character of an international string. Use the iterator to return the ordering priority of the positioned character. The ordering priority of a character, which we refer to as a key, defines how a character is collated in the given collation object.

For example, consider the following in Spanish:

  1. "ca" -> the first key is key('c') and second key is key('a').
  2. "cha" -> the first key is key('ch') and second key is key('a').
And in German,
  1. "äb"-> the first key is key('a'), the second key is key('e'), and
  2. the third key is key('b').
The key of a character is an integer composed of primary order(short), secondary order(byte), and tertiary order(byte). Java strictly defines the size and signedness of its primitive data types. Therefore, the static functions primaryOrder, secondaryOrder, and tertiaryOrder return int, short, and short respectively to ensure the correctness of the key value.

Example of the iterator usage,

  1. String testString = "This is a test";
  2. RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)Collator.getInstance();
  3. CollationElementIterator collationElementIterator = ruleBasedCollator.getCollationElementIterator(testString);
  4. int primaryOrder = CollationElementIterator.primaryOrder(collationElementIterator.next());

CollationElementIterator.next returns the collation order of the next character. A collation order consists of primary order, secondary order and tertiary order. The data type of the collation order is int. The first 16 bits of a collation order is its primary order; the next 8 bits is the secondary order and the last 8 bits is the tertiary order.

See Also:
Collator, RuleBasedCollator

Field Summary
static intNULLORDER
          Null order which indicates the end of string is reached by the cursor.
 
Method Summary
 intgetMaxExpansion(int order)
          Return the maximum length of any expansion sequences that end with the specified comparison order.
 intgetOffset()
          Returns the character offset in the original text corresponding to the next collation element.
 intnext()
          Get the next collation element in the string.
 intprevious()
          Get the previous collation element in the string.
static intprimaryOrder(int order)
          Return the primary component of a collation element.
 voidreset()
          Resets the cursor to the beginning of the string.
static shortsecondaryOrder(int order)
          Return the secondary component of a collation element.
 voidsetOffset(int newOffset)
          Sets the iterator to point to the collation element corresponding to the specified character (the parameter is a CHARACTER offset in the original string, not an offset into its corresponding sequence of collation elements).
 voidsetText(CharacterIterator source)
          Set a new string over which to iterate.
 voidsetText(String source)
          Set a new string over which to iterate.
static shorttertiaryOrder(int order)
          Return the tertiary component of a collation element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULLORDER

public static final int NULLORDER
Null order which indicates the end of string is reached by the cursor.

See Also:
Constant Field Values
Method Detail

reset

public void reset()
Resets the cursor to the beginning of the string. The next call to next() will return the first collation element in the string.


next

public int next()
Get the next collation element in the string.

This iterator iterates over a sequence of collation elements that were built from the string. Because there isn't necessarily a one-to-one mapping from characters to collation elements, this doesn't mean the same thing as "return the collation element [or ordering priority] of the next character in the string".

This function returns the collation element that the iterator is currently pointing to and then updates the internal pointer to point to the next element. previous() updates the pointer first and then returns the element. This means that when you change direction while iterating (i.e., call next() and then call previous(), or call previous() and then call next()), you'll get back the same element twice.


previous

public int previous()
Get the previous collation element in the string.

This iterator iterates over a sequence of collation elements that were built from the string. Because there isn't necessarily a one-to-one mapping from characters to collation elements, this doesn't mean the same thing as "return the collation element [or ordering priority] of the previous character in the string".

This function updates the iterator's internal pointer to point to the collation element preceding the one it's currently pointing to and then returns that element, while next() returns the current element and then updates the pointer. This means that when you change direction while iterating (i.e., call next() and then call previous(), or call previous() and then call next()), you'll get back the same element twice.

Since:
1.2

primaryOrder

public static final int primaryOrder(int order)
Return the primary component of a collation element.

Parameters:
order - the collation element
Returns:
the element's primary component

secondaryOrder

public static final short secondaryOrder(int order)
Return the secondary component of a collation element.

Parameters:
order - the collation element
Returns:
the element's secondary component

tertiaryOrder

public static final short tertiaryOrder(int order)
Return the tertiary component of a collation element.

Parameters:
order - the collation element
Returns:
the element's tertiary component

setOffset

public void setOffset(int newOffset)
Sets the iterator to point to the collation element corresponding to the specified character (the parameter is a CHARACTER offset in the original string, not an offset into its corresponding sequence of collation elements). The value returned by the next call to next() will be the collation element corresponding to the specified position in the text. If that position is in the middle of a contracting character sequence, the result of the next call to next() is the collation element for that sequence. This means that getOffset() is not guaranteed to return the same value as was passed to a preceding call to setOffset().

Parameters:
newOffset - The new character offset into the original text.
Since:
1.2

getOffset

public int getOffset()
Returns the character offset in the original text corresponding to the next collation element. (That is, getOffset() returns the position in the text corresponding to the collation element that will be returned by the next call to next().) This value will always be the index of the FIRST character corresponding to the collation element (a contracting character sequence is when two or more characters all correspond to the same collation element). This means if you do setOffset(x) followed immediately by getOffset(), getOffset() won't necessarily return x.

Returns:
The character offset in the original text corresponding to the collation element that will be returned by the next call to next().
Since:
1.2

getMaxExpansion

public int getMaxExpansion(int order)
Return the maximum length of any expansion sequences that end with the specified comparison order.

Parameters:
order - a collation order returned by previous or next.
Returns:
the maximum length of any expansion sequences ending with the specified order.
Since:
1.2

setText

public void setText(String source)
Set a new string over which to iterate.

Parameters:
source - the new source text
Since:
1.2

setText

public void setText(CharacterIterator source)
Set a new string over which to iterate.

Parameters:
source - the new source text.
Since:
1.2

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

6 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-1938
Document créé le 31/08/06 00:56, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/text/CollationElementIterator.html Document affiché 1 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,95 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Il n'y a plus, de nos jours, que deux sortes de piétons : les rapides et les morts.

Pierre Dumayet
 
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)