public final class CollationElementIterator extends Object
CollationElementIterator类用作遍历国际字符串的每个字符的迭代器。 
       使用迭代器返回定位字符的排序优先级。 
       字符的排序优先级,我们将其称为键,定义了字符在给定的排序规则对象中的整理方式。 
       例如,考虑以下西班牙语:
 
        
 "ca" → the first key is key('c') and second key is key('a').
 "cha" → the first key is key('ch') and second key is key('a').
  
        
       在德国, 
        
        
 "�b" → the first key is key('a'), the second key is key('e'), and
 the third key is key('b').
  
        
       一个字符的键是一个整数,由一个小阶(short),二次(byte)和三阶(byte)组成。 
       Java严格定义了其原始数据类型的大小和签名。 
       因此,静态函数primaryOrder , secondaryOrder和tertiaryOrder回报int , short和short分别以确保密钥值的正确性。 
       迭代器使用的示例,
 
        
  String testString = "This is a test";
  Collator col = Collator.getInstance();
  if (col instanceof RuleBasedCollator) {
      RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)col;
      CollationElementIterator collationElementIterator = ruleBasedCollator.getCollationElementIterator(testString);
      int primaryOrder = CollationElementIterator.primaryOrder(collationElementIterator.next());
          :
  }
  
        
        CollationElementIterator.next返回下一个字符的排序规则顺序。 整理订单由一级订单,二级订单和三级订单组成。 归类顺序的数据类型为int 。 排序顺序的前16位是其主要顺序; 接下来的8位是次级,最后8位是第三级。 
 注: CollationElementIterator是的一部分RuleBasedCollator实现。 它只能用于RuleBasedCollator实例。 
Collator , RuleBasedCollator 
       | Modifier and Type | Field and Description | 
|---|---|
static int |  
           NULLORDER 
            
              指示字符串结束的空白顺序由光标到达。 
               |  
          
| Modifier and Type | Method and Description | 
|---|---|
int |  
           getMaxExpansion(int order) 
            
              返回以指定的比较顺序结束的任何扩展序列的最大长度。 
               |  
          
int |  
           getOffset() 
            
              返回与下一个排序规则元素对应的原始文本中的字符偏移量。 
               |  
          
int |  
           next() 
            
              获取字符串中的下一个排序规则元素。 
               |  
          
int |  
           previous() 
            
              获取字符串中的以前的排序规则元素。 
               |  
          
static int |  
           primaryOrder(int order) 
            
              返回排序规则元素的主要组件。 
               |  
          
void |  
           reset() 
            
              将光标重置为字符串的开头。 
               |  
          
static short |  
           secondaryOrder(int order) 
            
              返回排序规则元素的次要组件。 
               |  
          
void |  
           setOffset(int newOffset) 
            
              将迭代器设置为指向与指定字符对应的排序规则元素(参数是原始字符串中的CHARACTER偏移量,而不是其对应的排序规则元素序列中的偏移量)。 
               |  
          
void |  
           setText(CharacterIterator source) 
            
              设置要迭代的新字符串。 
               |  
          
void |  
           setText(String source) 
            
              设置要迭代的新字符串。 
               |  
          
static short |  
           tertiaryOrder(int order) 
            
              返回排序规则元素的三级分量。 
               |  
          
public static final int NULLORDER
public void reset()
public int next()
该迭代器遍历从字符串构建的一系列排序规则元素。 因为没有必要从字符到排序规则元素的一对一映射,这并不意味着与“返回字符串中下一个字符的排序规则元素[或排序优先级]”相同。
此函数返回迭代器当前指向的排序规则元素,然后更新内部指针以指向下一个元素。 previous()首先更新指针,然后返回该元素。 这意味着当您在迭代时更改方向(即,调用next(),然后调用previous()或调用previous()然后调用next()),您将返回相同的元素两次。
public int previous()
该迭代器遍历从字符串构建的一系列排序规则元素。 因为没有必要从字符到排序规则元素的一对一映射,这并不意味着与“返回字符串中前一个字符的排序规则元素[或排序优先级]”相同。
此函数将迭代器的内部指针更新为指向当前指向的collation元素,然后返回该元素,而next()返回当前元素,然后更新指针。 这意味着当您在迭代时更改方向(即,调用next(),然后调用previous()或调用previous()然后调用next()),您将返回相同的元素两次。
public static final int primaryOrder(int order)
order - 排序规则元素 
           public static final short secondaryOrder(int order)
order - 排序规则元素 
           public static final short tertiaryOrder(int order)
order - 排序规则元素 
           public void setOffset(int newOffset)
newOffset - 新的字符偏移到原始文本。 
           public int getOffset()
public int getMaxExpansion(int order)
order - 上一个或下一个返回的归类顺序。 
           public void setText(String source)
source - 新的源文本 
           public void setText(CharacterIterator source)
source - 新的源文本。 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.