当前位置: 首页>>代码示例>>Java>>正文


Java AttributedCharacterIterator.getIndex方法代码示例

本文整理汇总了Java中java.text.AttributedCharacterIterator.getIndex方法的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator.getIndex方法的具体用法?Java AttributedCharacterIterator.getIndex怎么用?Java AttributedCharacterIterator.getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.AttributedCharacterIterator的用法示例。


在下文中一共展示了AttributedCharacterIterator.getIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public void write(Text text, Writer writer) throws IOException {
  AttributedCharacterIterator iterator = text.getIterator();

  Entry<Attribute, Object> lastAttribute = null;
  while (true) {
    if (iterator.getIndex() == iterator.getEndIndex()) {
      break;
    }

    Entry<Attribute, Object> entry = getAttribute(iterator);

    if (!Objects.equals(entry, lastAttribute)) {
      endEntity(lastAttribute, writer);
      beginEntity(entry, writer);
    }

    writer.write(iterator.current());

    lastAttribute = entry;
    iterator.next();
  }

  endEntity(lastAttribute, writer);
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:26,代码来源:MarkdownTextWriter.java

示例2: getEntities

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private List<String> getEntities(TextEntity entity) {
  AttributedCharacterIterator iterator = getIterator();
  List<String> entities = new ArrayList<>();
  StringBuilder builder = new StringBuilder();

  Map<AttributedCharacterIterator.Attribute, Object> last = Collections.emptyMap();
  while (iterator.getIndex() != iterator.getEndIndex()) {
    Map<AttributedCharacterIterator.Attribute, Object> curr = iterator.getAttributes();
    if (curr.containsKey(entity)) {
      builder.append(iterator.current());
    } else {
      if (last.containsKey(entity)) {
        entities.add(builder.toString());
        builder.setLength(0);
      }
    }
    last = curr;

    iterator.next();
  }
  if (last.containsKey(entity)) {
    entities.add(builder.toString());
  }

  return entities;
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:27,代码来源:Text.java

示例3: while

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static AttributedCharacterIterator getTrimmedTrailingSpacesIterator
        (AttributedCharacterIterator iterator) {
    int curIdx = iterator.getIndex();

    char c = iterator.last();
    while(c != CharacterIterator.DONE && Character.isWhitespace(c)) {
        c = iterator.previous();
    }

    if (c != CharacterIterator.DONE) {
        int endIdx = iterator.getIndex();

        if (endIdx == iterator.getEndIndex() - 1) {
            iterator.setIndex(curIdx);
            return iterator;
        } else {
            AttributedString trimmedText = new AttributedString(iterator,
                    iterator.getBeginIndex(), endIdx + 1);
            return trimmedText.getIterator();
        }
    } else {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:SwingUtilities2.java

示例4: write

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public void write(Text text, Writer writer) throws IOException {
  AttributedCharacterIterator iterator = text.getIterator();
  StringBuilder builder = new StringBuilder();

  Entry<Attribute, Object> lastAttribute = null;
  while (true) {
    if (iterator.getIndex() == iterator.getEndIndex()) {
      break;
    }

    Entry<Attribute, Object> entry = getAttribute(iterator);

    if (!Objects.equals(entry, lastAttribute)) {
      writer.write(escape(builder.toString()));
      builder.setLength(0);
      endEntity(lastAttribute, writer);
      beginEntity(entry, writer);
    }

    builder.append(iterator.current());

    lastAttribute = entry;
    iterator.next();
  }
  writer.write(escape(builder.toString()));
  endEntity(lastAttribute, writer);
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:29,代码来源:HtmlTextWriter.java

示例5: getEntitiesWithValues

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> List<Map.Entry<String, T>> getEntitiesWithValues(TextEntity entity) {
  AttributedCharacterIterator iterator = getIterator();
  List<Map.Entry<String, T>> entities = new ArrayList<>();
  StringBuilder builder = new StringBuilder();

  Map<AttributedCharacterIterator.Attribute, T> last = Collections.emptyMap();
  while (iterator.getIndex() != iterator.getEndIndex()) {
    Map<AttributedCharacterIterator.Attribute, T> curr =
        (Map<AttributedCharacterIterator.Attribute, T>) iterator.getAttributes();
    if (curr.containsKey(entity)) {
      builder.append(iterator.current());
    } else {
      if (last.containsKey(entity)) {
        entities.add(
            new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
        );
        builder.setLength(0);
      }
    }
    last = curr;

    iterator.next();
  }
  if (last.containsKey(entity)) {
    entities.add(
        new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
    );
  }

  return entities;
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:33,代码来源:Text.java

示例6: equals

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }

  if(!(obj instanceof Text)) {
    return false;
  }

  Text text = (Text) obj;

  if (this.length() != text.length()) {
    return false;
  }

  AttributedCharacterIterator it1 = this.getIterator();
  AttributedCharacterIterator it2 = text.getIterator();
  while (true) {
    if (it1.getIndex() == it1.getEndIndex()) {
      break;
    }

    if (it1.next() != it2.next()) {
      return false;
    }
    Map map1 = it1.getAttributes();
    Map map2 = it2.getAttributes();
    if (!map1.equals(map2)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:AgeOfWar,项目名称:Telejam,代码行数:35,代码来源:Text.java

示例7: append

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
static void append(
        AttributedCharacterIterator iterator,
        int start,
        int limit,
        StringBuilder result) {
    int oldIndex = iterator.getIndex();
    iterator.setIndex(start);
    for (int i = start; i < limit; i++) {
        result.append(iterator.current());
        iterator.next();
    }
    iterator.setIndex(oldIndex);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:14,代码来源:ScientificNumberFormatter.java

示例8: copyAsSuperscript

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static void copyAsSuperscript(
        AttributedCharacterIterator iterator, int start, int limit, StringBuilder result) {
    int oldIndex = iterator.getIndex();
    iterator.setIndex(start);
    while (iterator.getIndex() < limit) {
        int aChar = char32AtAndAdvance(iterator);
        int digit = UCharacter.digit(aChar);
        if (digit < 0) {
            throw new IllegalArgumentException();
        }
        result.append(SUPERSCRIPT_DIGITS[digit]);
    }
    iterator.setIndex(oldIndex);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:15,代码来源:ScientificNumberFormatter.java

示例9: dumpIterator

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static final void dumpIterator(AttributedCharacterIterator iterator) {
    Set attributeKeys = iterator.getAllAttributeKeys();
    System.out.print("All attributes: ");
    Iterator keyIterator = attributeKeys.iterator();
    while (keyIterator.hasNext()) {
        Attribute key = (Attribute) keyIterator.next();
        System.out.print(key);
    }
    for(char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next()) {
        if (iterator.getIndex() == iterator.getBeginIndex() ||
                    iterator.getIndex() == iterator.getRunStart()) {
            System.out.println();
            Map attributes = iterator.getAttributes();
            Set entries = attributes.entrySet();
            Iterator attributeIterator = entries.iterator();
            while (attributeIterator.hasNext()) {
                Map.Entry entry = (Map.Entry) attributeIterator.next();
                System.out.print("<" + entry.getKey() + ": "
                            + entry.getValue() + ">");
            }
        }
        System.out.print(" ");
        System.out.print(c);
    }
    System.out.println();
    System.out.println("done");
    System.out.println();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:AttributedStringTest.java

示例10: formatAndAppend

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
public void formatAndAppend(Format formatter, Object arg) {
    if (attributes == null) {
        append(formatter.format(arg));
    } else {
        AttributedCharacterIterator formattedArg = formatter.formatToCharacterIterator(arg);
        int prevLength = length;
        append(formattedArg);
        // Copy all of the attributes from formattedArg to our attributes list.
        formattedArg.first();
        int start = formattedArg.getIndex();  // Should be 0 but might not be.
        int limit = formattedArg.getEndIndex();  // == start + length - prevLength
        int offset = prevLength - start;  // Adjust attribute indexes for the result string.
        while (start < limit) {
            Map<Attribute, Object> map = formattedArg.getAttributes();
            int runLimit = formattedArg.getRunLimit();
            if (map.size() != 0) {
                for (Map.Entry<Attribute, Object> entry : map.entrySet()) {
                   attributes.add(
                       new AttributeAndPosition(
                           entry.getKey(), entry.getValue(),
                           offset + start, offset + runLimit));
                }
            }
            start = runLimit;
            formattedArg.setIndex(start);
        }
    }
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:29,代码来源:MessageFormat.java


注:本文中的java.text.AttributedCharacterIterator.getIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。