Java Code Examples for java.util.Vector#forEach()

The following examples show how to use java.util.Vector#forEach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameEventService.java    From tankbattle with MIT License 5 votes vote down vote up
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());
        });
    }


}
 
Example 2
Source File: TaskExecutor.java    From tankbattle with MIT License 5 votes vote down vote up
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);
    });
}
 
Example 3
Source File: VectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: VectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_forEach_NPE() throws Exception {
    Vector<Integer> vector = new Vector<>();
    try {
        vector.forEach(null);
        fail();
    } catch(NullPointerException expected) {}
}
 
Example 5
Source File: VectorTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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) {}
}