Exemplo n.º 1
0
 @Override
 public ListIterator<T> listIterator(int index) {
   MyIterator it = new MyIterator();
   for (int i = 0; i < index; ++i) {
     it.next();
   }
   return it;
 }
Exemplo n.º 2
0
  public void find() {
    int aMinSpread = Integer.MAX_VALUE;

    while (fIt.hasNext()) {
      HasSpread aNext = fIt.next();
      int aSpread = aNext.getSpread();
      if (aSpread < aMinSpread) {
        aMinSpread = aSpread;
        fMinSpread = aNext;
      }
    }
  }
 @JExercise(
     tests = "MyIterator iterator()",
     description =
         "The iterator method returns an instance of MyIterator that iterates over all the elements in this List.")
 public void testIterator() {
   addStrings();
   MyIterator it = list.iterator();
   for (int i = 0; i < strings.length; i++) {
     boolean isLast = (i == strings.length - 1);
     assertTrue(it.hasNext());
     assertEquals(list.get(i), it.next());
     assertEquals(!isLast, it.hasNext());
   }
   assertFalse(it.hasNext());
 }
Exemplo n.º 4
0
 public ComparableList<Value> execute(Expr expr, ArrayList<MyIterator> iterators, BoolExpr bool) {
   mList = new ComparableList<Value>();
   if (iterators.isEmpty()) {
     if (bool == null || bool.eval()) {
       mList.add(expr.eval()); // TODO auswerten
     }
     return mList;
   }
   MyIterator myIt = iterators.get(0);
   Value val = myIt.getExpr().eval();
   iterators.remove(0);
   if (val instanceof SetOrList) {
     SetOrList sol = (SetOrList) val;
     Iterator<Value> it = sol.iterator();
     while (it.hasNext()) {
       Environment.putValue(myIt.getVariable(), it.next());
       mList.addAll(execute(expr, iterators, bool));
     }
     return mList;
   } else {
     throw new RuntimeException();
   }
 }