API java : CharacterIterator


java.text
Interface CharacterIterator

All Superinterfaces:
Cloneable
All Known Subinterfaces:
AttributedCharacterIterator
All Known Implementing Classes:
Segment, StringCharacterIterator

public interface CharacterIterator
extends Cloneable

This interface defines a protocol for bidirectional iteration over text. The iterator iterates over a bounded sequence of characters. Characters are indexed with values beginning with the value returned by getBeginIndex() and continuing through the value returned by getEndIndex()-1.

Iterators maintain a current character index, whose valid range is from getBeginIndex() to getEndIndex(); the value getEndIndex() is included to allow handling of zero-length text ranges and for historical reasons. The current index can be retrieved by calling getIndex() and set directly by calling setIndex(), first(), and last().

The methods previous() and next() are used for iteration. They return DONE if they would move outside the range from getBeginIndex() to getEndIndex() -1, signaling that the iterator has reached the end of the sequence. DONE is also returned by other methods to indicate that the current index is outside this range.

Examples:

Traverse the text from start to finish

  1. public void traverseForward(CharacterIterator iter) {
  2. for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
  3. processChar(c);
  4. }
  5. }
Traverse the text backwards, from end to start
  1. public void traverseBackward(CharacterIterator iter) {
  2. for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
  3. processChar(c);
  4. }
  5. }
Traverse both forward and backward from a given position in the text. Calls to notBoundary() in this example represents some additional stopping criteria.
  1. public void traverseOut(CharacterIterator iter, int pos) {
  2. for (char c = iter.setIndex(pos);
  3. c != CharacterIterator.DONE && notBoundary(c);
  4. c = iter.next()) {
  5. }
  6. int end = iter.getIndex();
  7. for (char c = iter.setIndex(pos);
  8. c != CharacterIterator.DONE && notBoundary(c);
  9. c = iter.previous()) {
  10. }
  11. int start = iter.getIndex();
  12. processSection(start, end);
  13. }

See Also:
StringCharacterIterator, AttributedCharacterIterator

Field Summary
static char DONE
          Constant that is returned when the iterator has reached either the end or the beginning of the text.
 
Method Summary
 Object clone()
          Create a copy of this iterator
 char current()
          Gets the character at the current position (as returned by getIndex()).
 char first()
          Sets the position to getBeginIndex() and returns the character at that position.
 int getBeginIndex()
          Returns the start index of the text.
 int getEndIndex()
          Returns the end index of the text.
 int getIndex()
          Returns the current index.
 char last()
          Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.
 char next()
          Increments the iterator's index by one and returns the character at the new index.
 char previous()
          Decrements the iterator's index by one and returns the character at the new index.
 char setIndex(int position)
          Sets the position to the specified position in the text and returns that character.
 

Field Detail

DONE

static final char DONE
Constant that is returned when the iterator has reached either the end or the beginning of the text. The value is '\\uFFFF', the "not a character" value which should not occur in any valid Unicode string.

See Also:
Constant Field Values
Method Detail

first

char first()
Sets the position to getBeginIndex() and returns the character at that position.

Returns:
the first character in the text, or DONE if the text is empty
See Also:
getBeginIndex()

last

char last()
Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.

Returns:
the last character in the text, or DONE if the text is empty
See Also:
getEndIndex()

current

char current()
Gets the character at the current position (as returned by getIndex()).

Returns:
the character at the current position or DONE if the current position is off the end of the text.
See Also:
getIndex()

next

char next()
Increments the iterator's index by one and returns the character at the new index. If the resulting index is greater or equal to getEndIndex(), the current index is reset to getEndIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the new position is off the end of the text range.

previous

char previous()
Decrements the iterator's index by one and returns the character at the new index. If the current index is getBeginIndex(), the index remains at getBeginIndex() and a value of DONE is returned.

Returns:
the character at the new position or DONE if the current position is equal to getBeginIndex().

setIndex

char setIndex(int position)
Sets the position to the specified position in the text and returns that character.

Parameters:
position - the position within the text. Valid values range from getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown if an invalid value is supplied.
Returns:
the character at the specified position or DONE if the specified position is equal to getEndIndex()

getBeginIndex

int getBeginIndex()
Returns the start index of the text.

Returns:
the index at which the text begins.

getEndIndex

int getEndIndex()
Returns the end index of the text. This index is the index of the first character following the end of the text.

Returns:
the index after the last character in the text

getIndex

int getIndex()
Returns the current index.

Returns:
the current index.

clone

Object clone()
Create a copy of this iterator

Returns:
A copy of this

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-1500
Document créé le 30/08/06 01:58, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/text/CharacterIterator.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,71 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
La connerie, c'est la décontraction de l'intelligence!

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