1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.zel.instr.var;
20
21 import net.sf.zel.instr.*;
22 import net.sf.zel.vm.*;
23 import java.util.*;
24 import net.sf.zel.nr.OperableInteger;
25
26
27
28 public final class COUNT extends Instruction
29 {
30
31
32
33
34 public static final Instruction instance = new COUNT();
35
36 private static final long serialVersionUID = 3806659275392364719L;
37
38 private COUNT(){};
39
40
41
42
43
44
45 public void execute(ExecutionContext context) throws ZExecutionException
46 {
47 final MatchIterator iterator = new MatchIterator((String) context.popSyncStackVal());
48 context.stack.pop();
49
50 Counter stuff = new Counter();
51 iterator.iterate(stuff, context.memContext);
52
53 context.stack.push(new OperableInteger(stuff.count));
54 context.ip++;
55 }
56
57 private class Counter implements MatchIterator.DoStuff
58 {
59
60 public int count = 0;
61
62 public void execute(Object obj, List context)
63 {
64 count++;
65 }
66 }
67 }