本文整理汇总了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;
}
}
示例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());
}
}
示例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) {}
}
示例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));
}
示例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);
}
}
示例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);
}
}
}
示例7: toArray
import java.util.Iterator; //导入方法依赖的package包/类
private Object[] toArray(Iterator<?> iter) {
List<Object> list = new ArrayList<>();
iter.forEachRemaining(list::add);
return list.toArray();
}
示例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));
}
示例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"); });
}
示例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);
});
}
}
示例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);
});
}
示例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);
}
示例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);
}
示例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())));
}
示例15: executeCommands
import java.util.Iterator; //导入方法依赖的package包/类
public void executeCommands(){
Iterator<Army> iter = armyList.iterator();
iter.forEachRemaining(Army::executeCommand);
}