1 32 33 package com.jeantessier.classreader; 34 35 import java.util.*; 36 37 public class CodeIterator implements Iterator { 38 private byte[] code; 39 private int pc; 40 41 public CodeIterator(byte[] code) { 42 this.code = code; 43 this.pc = 0; 44 } 45 46 public boolean hasNext() { 47 return pc < code.length; 48 } 49 50 public Object next() { 51 Instruction result = null; 52 53 if (hasNext()) { 54 result = new Instruction(code, pc); 55 pc += result.getLength(); 56 } else { 57 throw new NoSuchElementException(); 58 } 59 60 return result; 61 } 62 63 public void remove() { 64 throw new UnsupportedOperationException (); 65 } 66 } 67 | Popular Tags |