forEach ( )源码实例Demo

java.util.Vector#forEach ( )源码实例Demo

下面列出了java.util.Vector#forEach ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tankbattle   文件: GameEventService.java
public void refreshState() {
    RealTimeGameData resource = context.getRealTimeGameData();
    Vector<EnemyTank> enemies = resource.getEnemies();
    Vector<MyTank> myTanks = resource.getMyTanks();

    if (!myTanks.isEmpty()) {
        enemies.forEach(enemyTank -> {
            enemyTank.setMyTankDirect(myTanks.get(0).getDirect());
        });
    }


}
 
源代码2 项目: tankbattle   文件: TaskExecutor.java
public void startEnemyTankThreads() {
    Vector<EnemyTank> enemies = gameContext.getRealTimeGameData().getEnemies();
    enemies.forEach(e -> {
        taskExecutor.execute(new EnemyTankMoveTask(e, enemyTankEventService));
        e.getTimer().schedule(new EnemyTankAutoShotTask(e, gameEventService), 0, 500);
    });
}
 
源代码3 项目: j2objc   文件: VectorTest.java
public void test_forEach() throws Exception {
  Vector<Integer> vector = new Vector<Integer>();
  vector.add(0);
  vector.add(1);
  vector.add(2);

  Vector<Integer> output = new Vector<Integer>();
  vector.forEach ( k -> output.add(k) );

  assertEquals(vector, output);
}
 
源代码4 项目: j2objc   文件: VectorTest.java
public void test_forEach_NPE() throws Exception {
    Vector<Integer> vector = new Vector<>();
    try {
        vector.forEach(null);
        fail();
    } catch(NullPointerException expected) {}
}
 
源代码5 项目: j2objc   文件: VectorTest.java
public void test_forEach_CME() throws Exception {
    Vector<Integer> vector = new Vector<>();
    vector.add(1);
    vector.add(2);
    try {
        vector.forEach(new java.util.function.Consumer<Integer>() {
                @Override
                public void accept(Integer t) {vector.add(t);}
            });
        fail();
    } catch(ConcurrentModificationException expected) {}
}
 
源代码6 项目: tankbattle   文件: GameEventService.java
/**
 * Bullets Event...
 */
public void doBulletEvent() {
    RealTimeGameData resource = context.getRealTimeGameData();

    Vector<MyTank> myTanks = resource.getMyTanks();
    Vector<EnemyTank> enemies = resource.getEnemies();
    Vector<Bomb> bombs = resource.getBombs();
    Map map = resource.getMap();

    if (myTanks.isEmpty()) {
        enemies.forEach(enemyTank -> enemyTank.setShot(false));
    }

    myTanks.forEach(myTank ->
            enemies.forEach(enemyTank -> {

                tankEventService.enemyFindAndKill(enemyTank, myTank, map);

                enemyTank.getBullets().forEach(eb -> {
                    if (isHitting(eb, myTank)) {
                        this.afterShotTank(eb, myTank, bombs);
                    }

                    map.getBricks().stream().filter(brick -> isHitting(eb, brick))
                            .forEach(brick -> afterShotStuff(eb, brick, bombs, enemyTank));

                    map.getIrons().stream().filter(iron -> isHitting(eb, iron))
                            .forEach(iron -> afterShotStuff(eb, iron, bombs, enemyTank));
                });

                myTank.getBullets().forEach(mb -> {
                    enemyTank.getBullets().stream().filter(eb -> isHitting(mb, eb))
                            .forEach(eb -> {
                                mb.setLive(false);
                                eb.setLive(false);
                                Bomb bomb = new Bomb(mb.getX(), mb.getY());
                                bomb.setL(20);
                                bombs.add(bomb);
                            });


                    if (isHitting(mb, enemyTank)) {
                        this.afterShotTank(mb, enemyTank, bombs);
                    }

                    map.getBricks().stream().filter(brick -> isHitting(mb, brick))
                            .forEach(brick -> afterShotStuff(mb, brick, bombs, myTank));

                    map.getIrons().stream().filter(iron -> isHitting(mb, iron))
                            .forEach(iron -> afterShotStuff(mb, iron, bombs, myTank));
                });


            })
    );
}