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


Java Iterator.forEachRemaining方法代码示例

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


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

示例1: testForEachRemaining

import java.util.Iterator; //导入方法依赖的package包/类
public void testForEachRemaining() {
    Iterator<String> it = Collections.singleton("TheOne").iterator();
    AtomicInteger cnt = new AtomicInteger(0);

    it.forEachRemaining(s -> {
        assertEquals("TheOne", s);
        cnt.incrementAndGet();
    });

    assertEquals(cnt.get(), 1);
    assertFalse(it.hasNext());

    try {
        String str = it.next();
        fail("Should throw NoSuchElementException at end");
    } catch (NoSuchElementException ex) {
        // ignore;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SingletonIterator.java

示例2: testIteratorForEachRemaining

import java.util.Iterator; //导入方法依赖的package包/类
@Test(dataProvider = "all")
public void testIteratorForEachRemaining(List<Integer> list, int from, int to) {
    List<Integer> subList = list.subList(from, to);
    for (int k = 0; k < 16; ++k) {
        int r = from + rnd.nextInt(1 + to - from);
        Iterator<Integer> it = subList.iterator();
        for (int i = from; i < to; ++i) {
            assertTrue(it.hasNext());
            if (i == r) {
                Iterator<Integer> jt = list.listIterator(r);
                it.forEachRemaining(x ->
                    assertTrue(jt.hasNext() && x == jt.next()));
                break;
            }
            assertEquals(list.get(i), it.next());
        }
        it.forEachRemaining(x -> fail());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:SubList.java

示例3: assertIteratorExhausted

import java.util.Iterator; //导入方法依赖的package包/类
void assertIteratorExhausted(Iterator it) {
    if (rnd.nextBoolean()) {
        assertTrue(!it.hasNext());
        assertTrue(isDetached(it));
    }
    if (rnd.nextBoolean()) {
        it.forEachRemaining(e -> { throw new AssertionError(); });
        assertTrue(isDetached(it));
    }
    if (rnd.nextBoolean())
        try { it.next(); fail("should throw"); }
        catch (NoSuchElementException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:WhiteBox.java

示例4: serverStarting

import java.util.Iterator; //导入方法依赖的package包/类
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
    Iterator<CommandModule> modules = Iterators.forArray(
            new RegionCommands(),
            new OperationCommands(),
            new SessionCommands());
    modules.forEachRemaining(m -> m.addCommands(event::registerServerCommand));
}
 
开发者ID:kenzierocks,项目名称:HardVox,代码行数:9,代码来源:HardVox.java

示例5: onPreStart

import java.util.Iterator; //导入方法依赖的package包/类
@Override
public void onPreStart() {
    this.startPosition = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
    for(Player player : Bukkit.getOnlinePlayers()) {
        if(!this.getAPI().getGameManager().isAlive(player)) continue;
        player.teleport(startPosition);
        player.setGameMode(GameMode.ADVENTURE);
    }
    this.targetPosition = Utils.parseLocation((String) this.getGameMap().fetchSetting("targetPosition"));
    this.towards = (String) this.getGameMap().fetchSetting("targetTowards");
    ((RelativeDistanceSidebar) this.getSidebar()).setTarget(targetPosition, towards);
    Cuboid minefield = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("minefieldBoundsA")),
            Utils.parseLocation((String) this.getGameMap().fetchSetting("minefieldBoundsB")));
    Iterator<Block> blocks = minefield.iterator();
    Random random = new Random();
    blocks.forEachRemaining(block -> {
        Block next = blocks.next();
        if(next.getRelative(BlockFace.UP).getType() == Material.AIR) {
            if(random.nextFloat() < 0.6F) {
                next.setType(Material.STONE_PLATE);
            }
        }
    });
    this.glass = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("glassBoundsA")),
            Utils.parseLocation((String) this.getGameMap().fetchSetting("glassBoundsB")));
    Iterator<Block> glassBlocks = glass.iterator();
    while(glassBlocks.hasNext()) {
        glassBlocks.next().setType(Material.GLASS);
    }
}
 
开发者ID:ArcadiaPlugins,项目名称:Arcadia-Spigot,代码行数:31,代码来源:MineFieldGame.java

示例6: testForEachRemaining

import java.util.Iterator; //导入方法依赖的package包/类
public void testForEachRemaining() {
  for (int i = 0; i < expectedElements.size() - 1; i++) {
    List<E> targetElements = new ArrayList<E>();
    Iterator<E> iterator = newTargetIterator();
    for (int j = 0; j < i; j++) {
      targetElements.add(iterator.next());
    }
    iterator.forEachRemaining(targetElements::add);
    if (knownOrder == KnownOrder.KNOWN_ORDER) {
      assertEquals(expectedElements, targetElements);
    } else {
      Helpers.assertEqualIgnoringOrder(expectedElements, targetElements);
    }
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:AbstractIteratorTester.java

示例7: toArray

import java.util.Iterator; //导入方法依赖的package包/类
private Object[] toArray(Iterator<?> iter) {
  List<Object> list = new ArrayList<>();
  iter.forEachRemaining(list::add);
  return list.toArray();
}
 
开发者ID:btk5h,项目名称:skript-mirror,代码行数:6,代码来源:ExprSpread.java

示例8: generate

import java.util.Iterator; //导入方法依赖的package包/类
@Override
public List<Ability> generate(Random random, AbilityStage stage, AbilityType type) {
    Potion potion;
    int ticks;
    int amplifier;

    if(type == AbilityType.ARMOR_PASSIVE) {
        ticks = 20 * 15;
    } else {
        ticks = Generator.ticks.randomElement(random);
    }

    Iterator<Potion> potionIterator = Potion.REGISTRY.iterator();
    List<Potion> potions = new ArrayList<>();
    potionIterator.forEachRemaining(potions::add);

    int index = random.nextInt(potions.size());

    do {
        potion = potions.get(index);
        index++;
        if(index >= potions.size()) {
            index = 0;
        }
    } while (!goodFor(potion, type));

    if(potion.isInstant()) {
        ticks = 1;
    }

    amplifier = Generator.amplifier.randomElement(random);

    return Items.buildList(new PotionEffectAbility(potion, ticks, amplifier));
}
 
开发者ID:Randores,项目名称:Randores2,代码行数:35,代码来源:PotionEffectAbility.java

示例9: assertIteratorExhausted

import java.util.Iterator; //导入方法依赖的package包/类
static void assertIteratorExhausted(Iterator<?> it) {
    assertFalse(it.hasNext());
    try {
        it.next();
        fail("should have thrown NoSuchElementException");
    } catch (NoSuchElementException success) { }
    it.forEachRemaining(e -> { throw new AssertionError("action called incorrectly"); });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:SingletonIterator.java

示例10: addTextToRepresentation

import java.util.Iterator; //导入方法依赖的package包/类
private void addTextToRepresentation(String oldFieldName, 
 		String newFieldName, 
 		Representation oldRepresentation, 
 		Representation newRepresentation, String lang, ValueFactory vf){
 	Iterator<Text> it = oldRepresentation.get(oldFieldName, lang);
 	
 	if(it != null){
 		it.forEachRemaining(obj -> {
	Text t = vf.createText(obj.getText(), lang);
	newRepresentation.set(newFieldName, t);
});
 	}
 }
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:14,代码来源:OntonethubOntologiesResource.java

示例11: addObjectToRepresentation

import java.util.Iterator; //导入方法依赖的package包/类
private void addObjectToRepresentation(String oldFieldName, 
 		String newFieldName, 
 		Representation oldRepresentation, 
 		Representation newRepresentation, ValueFactory vf){
 	Iterator<Object> it = oldRepresentation.get(oldFieldName);
 	if(it != null)
it.forEachRemaining(obj -> {
	newRepresentation.set(newFieldName, obj);
});
 }
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:11,代码来源:OntonethubOntologiesResource.java

示例12: testThrowFromForEachRemaining

import java.util.Iterator; //导入方法依赖的package包/类
public void testThrowFromForEachRemaining() {
    Iterator<String> it = Collections.singleton("TheOne").iterator();

    try {
        it.forEachRemaining(s -> { throw new SingletonException(); });
    } catch (SingletonException ignore) { }

    assertIteratorExhausted(it);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:SingletonIterator.java

示例13: testForEachRemaining

import java.util.Iterator; //导入方法依赖的package包/类
public void testForEachRemaining() {
    Iterator<String> it = Collections.singleton("TheOne").iterator();
    AtomicInteger cnt = new AtomicInteger(0);

    it.forEachRemaining(s -> {
        assertEquals("TheOne", s);
        cnt.incrementAndGet();
    });

    assertEquals(cnt.get(), 1);
    assertIteratorExhausted(it);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SingletonIterator.java

示例14: consume

import java.util.Iterator; //导入方法依赖的package包/类
@Override
public void consume(Iterator<KeyMessage<String,String>> updateIterator, Configuration hadoopConf) {
  updateIterator.forEachRemaining(update -> holder.add(new KeyMessageImpl<>(update.getKey(), update.getMessage())));
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:5,代码来源:MockSpeedModelManager.java

示例15: executeCommands

import java.util.Iterator; //导入方法依赖的package包/类
public void executeCommands(){
    Iterator<Army> iter = armyList.iterator();
    iter.forEachRemaining(Army::executeCommand);
}
 
开发者ID:Team-Fourtran,项目名称:OOPIter2,代码行数:5,代码来源:ArmyManager.java


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