javap/src/main/java/org/apidesign/javap/TrapDataIterator.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 09 Dec 2012 16:32:29 +0100
branchexceptions
changeset 290 57dff70280c7
parent 289 a2ca83ddc521
child 378 ccb1544a88bc
permissions -rw-r--r--
Using local implementation of Hashtable instead of java.util.HashMap
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 package org.apidesign.javap;
     6 
     7 /**
     8  *
     9  * @author Jaroslav Tulach <jtulach@netbeans.org>
    10  */
    11 public final class TrapDataIterator {
    12     private final Hashtable exStart = new Hashtable();
    13     private final Hashtable exStop = new Hashtable();
    14     private TrapData[] current = new TrapData[10];
    15     private int currentCount;
    16     
    17     TrapDataIterator(Vector exceptionTable) {
    18         for (int i=0 ; i < exceptionTable.size(); i++) {
    19             final TrapData td = (TrapData)exceptionTable.elementAt(i);
    20             exStart.put(td.start_pc, td);
    21             exStop.put(td.end_pc, td);
    22         }
    23     }
    24 
    25     public void advanceTo(int i) {
    26         Short s = Short.valueOf((short)i);
    27         TrapData e = (TrapData) exStart.get(s);
    28         if (e != null) {
    29             add(e);
    30         }
    31         e = (TrapData) exStop.get(s);
    32         if (e != null) {
    33             remove(e);
    34         }
    35     }
    36 
    37     public boolean useTry() {
    38         return currentCount > 0;
    39     }
    40 
    41     public TrapData[] current() {
    42         return current;
    43     }
    44 
    45     private void add(TrapData e) {
    46         if (currentCount == current.length) {
    47             TrapData[] data = new TrapData[currentCount * 2];
    48             for (int i = 0; i < currentCount; i++) {
    49                 data[i] = current[i];
    50             }
    51             current = data;
    52         }
    53         current[currentCount++] = e;
    54     }
    55 
    56     private void remove(TrapData e) {
    57         int from = 0;
    58         while (from < currentCount) {
    59             if (e == current[from++]) {
    60                 break;
    61             }
    62         }
    63         while (from < currentCount) {
    64             current[from - 1] = current[from];
    65             current[from] = null;
    66             from++;
    67         }
    68         currentCount--;
    69     }
    70 }