本文整理汇总了Java中java.util.ListIterator类的典型用法代码示例。如果您正苦于以下问题:Java ListIterator类的具体用法?Java ListIterator怎么用?Java ListIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListIterator类属于java.util包,在下文中一共展示了ListIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: merge
import java.util.ListIterator; //导入依赖的package包/类
/**
* merges two collections
*
* @param first result list
* @param second merges with first list
* @param comparator
*/
public static <T> void merge(List<T> first, List<T> second, Comparator<T> comparator) {
ListIterator<T> firstIter = first.listIterator();
ListIterator<T> secondIter = second.listIterator();
T a = getNext(firstIter);
T b = getNext(secondIter);
while (a != null && b != null) {
if (comparator.compare(a, b) > 0) {
firstIter.previous();
firstIter.add(b);
firstIter.next();
b = getNext(secondIter);
} else {
a = getNext(firstIter);
}
}
while (b != null) {
firstIter.add(b);
b = getNext(secondIter);
}
}
示例2: process
import java.util.ListIterator; //导入依赖的package包/类
public boolean process(TextDocument doc) throws BoilerpipeProcessingException {
boolean changes = false;
List<TextBlock> list = doc.getTextBlocks();
for (ListIterator<TextBlock> it = list.listIterator(list.size()); it.hasPrevious();) {
TextBlock tb = it.previous();
if (tb.isContent()) {
if (tb.hasLabel(DefaultLabels.HEADING)) {
tb.setIsContent(false);
changes = true;
} else {
break;
}
}
}
return changes;
}
示例3: reverse
import java.util.ListIterator; //导入依赖的package包/类
@Override
protected Iterable<LayoutHelper> reverse() {
final ListIterator<LayoutHelper> i = mLayoutHelpers.listIterator(mLayoutHelpers.size());
return new Iterable<LayoutHelper>() {
@Override
public Iterator<LayoutHelper> iterator() {
return new Iterator<LayoutHelper>() {
public boolean hasNext() {
return i.hasPrevious();
}
public LayoutHelper next() {
return i.previous();
}
public void remove() {
i.remove();
}
};
}
};
}
示例4: subListImpl
import java.util.ListIterator; //导入依赖的package包/类
/**
* An implementation of {@link List#subList(int, int)}.
*/
static <E> List<E> subListImpl(
final List<E> list, int fromIndex, int toIndex) {
List<E> wrapper;
if (list instanceof RandomAccess) {
wrapper = new RandomAccessListWrapper<E>(list) {
@Override public ListIterator<E> listIterator(int index) {
return backingList.listIterator(index);
}
private static final long serialVersionUID = 0;
};
} else {
wrapper = new AbstractListWrapper<E>(list) {
@Override public ListIterator<E> listIterator(int index) {
return backingList.listIterator(index);
}
private static final long serialVersionUID = 0;
};
}
return wrapper.subList(fromIndex, toIndex);
}
示例5: findSendablePacket
import java.util.ListIterator; //导入依赖的package包/类
private Packet findSendablePacket(LinkedList<Packet> outgoingQueue,
boolean clientTunneledAuthenticationInProgress) {
synchronized (outgoingQueue) {
if (outgoingQueue.isEmpty()) {
return null;
}
if (outgoingQueue.getFirst().bb != null // If we've already starting sending the first packet, we better finish
|| !clientTunneledAuthenticationInProgress) {
return outgoingQueue.getFirst();
}
// Since client's authentication with server is in progress,
// send only the null-header packet queued by primeConnection().
// This packet must be sent so that the SASL authentication process
// can proceed, but all other packets should wait until
// SASL authentication completes.
ListIterator<Packet> iter = outgoingQueue.listIterator();
while (iter.hasNext()) {
Packet p = iter.next();
if (p.requestHeader == null) {
// We've found the priming-packet. Move it to the beginning of the queue.
iter.remove();
outgoingQueue.add(0, p);
return p;
} else {
// Non-priming packet: defer it until later, leaving it in the queue
// until authentication completes.
if (LOG.isDebugEnabled()) {
LOG.debug("deferring non-priming packet: " + p +
"until SASL authentication completes.");
}
}
}
// no sendable packet found.
return null;
}
}
示例6: processKeyWithUsesInList
import java.util.ListIterator; //导入依赖的package包/类
/**
* Checks key values are set correctly.
*/
@Test
public void processKeyWithUsesInList() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/KeyWithUsesInList.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild().getNextSibling();
assertThat(yangList.getName(), is("valid"));
ListIterator<String> keyList = yangList.getKeyList().listIterator();
assertThat(keyList.next(), is("invalid-interval"));
}
示例7: removeAnimatedEventFromView
import java.util.ListIterator; //导入依赖的package包/类
public void removeAnimatedEventFromView(int viewTag, String eventName, int animatedValueTag) {
String key = viewTag + eventName;
if (mEventDrivers.containsKey(key)) {
List<EventAnimationDriver> driversForKey = mEventDrivers.get(key);
if (driversForKey.size() == 1) {
mEventDrivers.remove(viewTag + eventName);
} else {
ListIterator<EventAnimationDriver> it = driversForKey.listIterator();
while (it.hasNext()) {
if (it.next().mValueNode.mTag == animatedValueTag) {
it.remove();
break;
}
}
}
}
}
示例8: getSelectedAnnotation
import java.util.ListIterator; //导入依赖的package包/类
private PageAnnotation getSelectedAnnotation()
{
if (mAnnotations != null)
{
// iterate in reverse order
ListIterator<PageAnnotation> li = mAnnotations.listIterator(mAnnotations.size());
while (li.hasPrevious())
{
PageAnnotation annot = li.previous();
if (annot.isSelected())
{
return annot;
}
}
}
return null;
}
示例9: next
import java.util.ListIterator; //导入依赖的package包/类
/**
* Returns the next element from the iterator.
*
* @return the next element from the iterator
* @throws NoSuchElementException if there are no more elements
*/
public E next() throws NoSuchElementException {
if (iterator instanceof ListIterator) {
return iterator.next();
}
if (currentIndex < wrappedIteratorIndex) {
++currentIndex;
return list.get(currentIndex - 1);
}
final E retval = iterator.next();
list.add(retval);
++currentIndex;
++wrappedIteratorIndex;
removeState = true;
return retval;
}
示例10: processListSubStatementKey
import java.util.ListIterator; //导入依赖的package包/类
/**
* Checks key statement as sub-statement of list.
*/
@Test
public void processListSubStatementKey() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ListSubStatementKey.yang");
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
ListIterator<String> keyList = yangList.getKeyList().listIterator();
assertThat(keyList.next(), is("invalid-interval"));
}
示例11: iteratorBinarySearch
import java.util.ListIterator; //导入依赖的package包/类
private static <T> int iteratorBinarySearch(final List<? extends Comparable<? super T>> list, final T key, int low, int high) {
final ListIterator<? extends Comparable<? super T>> i = list.listIterator();
int mid, cmp;
while (low <= high) {
mid = (low + high) >>> 1;
cmp = get(i, mid).compareTo(key);
if (cmp < 0) {
low = mid + 1;
} else if (cmp > 0) {
high = mid - 1;
} else {
return mid;
} // key found
}
return -(low + 1); // key not found
}
示例12: processPatternStatementWithPlus
import java.util.ListIterator; //导入依赖的package包/类
/**
* Checks valid pattern statement with plus symbol in pattern.
*/
@Test
public void processPatternStatementWithPlus() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/PatternStatementWithPlus.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
YangLeafList leafListInfo = leafListIterator.next();
assertThat(leafListInfo.getName(), is("invalid-interval"));
assertThat(leafListInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
YangStringRestriction stringRestriction = (YangStringRestriction) leafListInfo
.getDataType().getDataTypeExtendedInfo();
ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
.getPatternList().listIterator();
assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+"));
}
示例13: seg2sentence
import java.util.ListIterator; //导入依赖的package包/类
/**
* 切分为句子形式
*
* @param text
* @return
*/
public static List<List<Term>> seg2sentence(String text)
{
List<List<Term>> sentenceList = SEGMENT.seg2sentence(text);
for (List<Term> sentence : sentenceList)
{
ListIterator<Term> listIterator = sentence.listIterator();
while (listIterator.hasNext())
{
if (!CoreStopWordDictionary.shouldInclude(listIterator.next()))
{
listIterator.remove();
}
}
}
return sentenceList;
}
示例14: processValidPatternStatement
import java.util.ListIterator; //导入依赖的package包/类
/**
* Checks valid pattern statement as sub-statement of leaf statement.
*/
@Test
public void processValidPatternStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/ValidPatternStatement.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
.getDataType().getDataTypeExtendedInfo();
ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
.getPatternList().listIterator();
assertThat(patternListIterator.next(), is("[a-zA-Z]"));
}
示例15: processDescriptionValidStatement
import java.util.ListIterator; //导入依赖的package包/类
/**
* Checks valid description statement.
*/
@Test
public void processDescriptionValidStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/DescriptionValidStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
// Check whether the module name is set correctly.
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
// Check whether the description is set correctly.
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
}