1 7 8 package org.gjt.jclasslib.bytecode; 9 10 import org.gjt.jclasslib.io.ByteCodeInput; 11 import org.gjt.jclasslib.io.ByteCodeOutput; 12 13 import java.io.IOException ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 23 public class LookupSwitchInstruction extends PaddedInstruction { 24 25 private int defaultOffset; 26 private List matchOffsetPairs = new ArrayList (); 27 28 32 public LookupSwitchInstruction(int opcode) { 33 super(opcode); 34 } 35 36 public int getSize() { 37 return super.getSize() + 8 + 8 * matchOffsetPairs.size(); 38 } 39 40 44 public int getDefaultOffset() { 45 return defaultOffset; 46 } 47 48 52 public void setDefaultOffset(int defaultOffset) { 53 this.defaultOffset = defaultOffset; 54 } 55 56 62 public List getMatchOffsetPairs() { 63 return matchOffsetPairs; 64 } 65 66 72 public void setMatchOffsetPairs(List matchOffsetPairs) { 73 this.matchOffsetPairs = matchOffsetPairs; 74 } 75 76 public void read(ByteCodeInput in) throws IOException { 77 super.read(in); 78 79 matchOffsetPairs.clear(); 80 81 defaultOffset = in.readInt(); 82 int numberOfPairs = in.readInt(); 83 84 int match, offset; 85 for (int i = 0; i < numberOfPairs; i++) { 86 match = in.readInt(); 87 offset = in.readInt(); 88 89 matchOffsetPairs.add(new MatchOffsetPair(match, offset)); 90 } 91 92 } 93 94 public void write(ByteCodeOutput out) throws IOException { 95 super.write(out); 96 97 out.writeInt(defaultOffset); 98 99 int numberOfPairs = matchOffsetPairs.size(); 100 out.writeInt(numberOfPairs); 101 102 MatchOffsetPair currentMatchOffsetPair; 103 for (int i = 0; i < numberOfPairs; i++) { 104 currentMatchOffsetPair = (MatchOffsetPair)matchOffsetPairs.get(i); 105 out.writeInt(currentMatchOffsetPair.getMatch()); 106 out.writeInt(currentMatchOffsetPair.getOffset()); 107 } 108 } 109 110 111 } 112 | Popular Tags |