View Javadoc

1   // UnmodifiableList.java, created Wed Mar  5  0:26:32 2003 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Util.Templates;
5   
6   import jwutil.collections.UnmodifiableListIterator;
7   
8   /***
9    * @author John Whaley <jwhaley@alum.mit.edu>
10   * @version $Id: UnmodifiableList.java 1931 2004-09-22 22:17:47Z joewhaley $
11   */
12  public abstract class UnmodifiableList {
13      public static class jq_Class extends java.util.AbstractList implements List.jq_Class {
14          private final joeq.Class.jq_Class[] a;
15          public jq_Class(joeq.Class.jq_Class c) { a = new joeq.Class.jq_Class[] { c }; }
16          public jq_Class(joeq.Class.jq_Class c1, joeq.Class.jq_Class c2) { a = new joeq.Class.jq_Class[] { c1, c2 }; }
17          public jq_Class(joeq.Class.jq_Class c1, joeq.Class.jq_Class c2, joeq.Class.jq_Class c3) { a = new joeq.Class.jq_Class[] { c1, c2, c3 }; }
18          public jq_Class(joeq.Class.jq_Class[] c) { a = c; }
19          public int size() { return a.length; }
20          public Object get(int index) { return getClass(index); }
21          public joeq.Class.jq_Type getType(int index) { return a[index]; }
22          public joeq.Class.jq_Reference getReference(int index) { return a[index]; }
23          public joeq.Class.jq_Class getClass(int index) { return a[index]; }
24          public ListIterator.jq_Type typeIterator() { return new Iterator(); }
25          public ListIterator.jq_Reference referenceIterator() { return new Iterator(); }
26          public ListIterator.jq_Class classIterator() { return new Iterator(); }
27          private class Iterator extends UnmodifiableListIterator implements ListIterator.jq_Class {
28              private int i = -1;
29              public boolean hasNext() { return i+1 < a.length; }
30              public boolean hasPrevious() { return i >= 0; }
31              public int nextIndex() { return i+1; }
32              public int previousIndex() { return i; }
33              public Object next() { return a[++i]; }
34              public joeq.Class.jq_Type nextType() { return a[++i]; }
35              public joeq.Class.jq_Reference nextReference() { return a[++i]; }
36              public joeq.Class.jq_Class nextClass() { return a[++i]; }
37              public Object previous() { return a[i--]; }
38              public joeq.Class.jq_Type previousType() { return a[i--]; }
39              public joeq.Class.jq_Reference previousReference() { return a[i--]; }
40              public joeq.Class.jq_Class previousClass() { return a[i--]; }
41          }
42          public static final jq_Class EMPTY = new jq_Class(new joeq.Class.jq_Class[0]);
43          public static jq_Class getEmptyList() { return EMPTY; }
44      }
45          
46      public static class RegisterOperand extends java.util.AbstractList implements List.RegisterOperand {
47          private final joeq.Compiler.Quad.Operand.RegisterOperand[] a;
48          public RegisterOperand(joeq.Compiler.Quad.Operand.RegisterOperand c) { a = new joeq.Compiler.Quad.Operand.RegisterOperand[] { c }; }
49          public RegisterOperand(joeq.Compiler.Quad.Operand.RegisterOperand c1, joeq.Compiler.Quad.Operand.RegisterOperand c2) { a = new joeq.Compiler.Quad.Operand.RegisterOperand[] { c1, c2 }; }
50          public RegisterOperand(joeq.Compiler.Quad.Operand.RegisterOperand c1, joeq.Compiler.Quad.Operand.RegisterOperand c2, joeq.Compiler.Quad.Operand.RegisterOperand c3) { a = new joeq.Compiler.Quad.Operand.RegisterOperand[] { c1, c2, c3 }; }
51          public RegisterOperand(joeq.Compiler.Quad.Operand.RegisterOperand c1, joeq.Compiler.Quad.Operand.RegisterOperand c2, joeq.Compiler.Quad.Operand.RegisterOperand c3, joeq.Compiler.Quad.Operand.RegisterOperand c4) { a = new joeq.Compiler.Quad.Operand.RegisterOperand[] { c1, c2, c3, c4 }; }
52          public RegisterOperand(joeq.Compiler.Quad.Operand.RegisterOperand[] c) { a = c; }
53          public int size() { return a.length; }
54          public Object get(int index) { return getRegisterOperand(index); }
55          public joeq.Compiler.Quad.Operand getOperand(int index) { return getRegisterOperand(index); }
56          public joeq.Compiler.Quad.Operand.RegisterOperand getRegisterOperand(int index) { return a[index]; }
57          public ListIterator.Operand operandIterator() { return new Iterator(); }
58          public ListIterator.RegisterOperand registerOperandIterator() { return new Iterator(); }
59          private class Iterator extends UnmodifiableListIterator implements ListIterator.RegisterOperand {
60              private int i = -1;
61              public boolean hasNext() { return i+1 < a.length; }
62              public boolean hasPrevious() { return i >= 0; }
63              public int nextIndex() { return i+1; }
64              public int previousIndex() { return i; }
65              public Object next() { return a[++i]; }
66              public joeq.Compiler.Quad.Operand nextOperand() { return a[++i]; }
67              public joeq.Compiler.Quad.Operand.RegisterOperand nextRegisterOperand() { return a[++i]; }
68              public Object previous() { return a[i--]; }
69              public joeq.Compiler.Quad.Operand previousOperand() { return a[i--]; }
70              public joeq.Compiler.Quad.Operand.RegisterOperand previousRegisterOperand() { return a[i--]; }
71          }
72          public static final RegisterOperand EMPTY = new RegisterOperand(new joeq.Compiler.Quad.Operand.RegisterOperand[0]);
73          public static RegisterOperand getEmptyList() { return EMPTY; }
74      }
75          
76      public static class Operand extends java.util.AbstractList implements List.Operand {
77          private final joeq.Compiler.Quad.Operand[] a;
78          public Operand(joeq.Compiler.Quad.Operand c) { a = new joeq.Compiler.Quad.Operand[] { c }; }
79          public Operand(joeq.Compiler.Quad.Operand c1, joeq.Compiler.Quad.Operand c2) { a = new joeq.Compiler.Quad.Operand[] { c1, c2 }; }
80          public Operand(joeq.Compiler.Quad.Operand c1, joeq.Compiler.Quad.Operand c2, joeq.Compiler.Quad.Operand c3) { a = new joeq.Compiler.Quad.Operand[] { c1, c2, c3 }; }
81          public Operand(joeq.Compiler.Quad.Operand c1, joeq.Compiler.Quad.Operand c2, joeq.Compiler.Quad.Operand c3, joeq.Compiler.Quad.Operand c4) { a = new joeq.Compiler.Quad.Operand[] { c1, c2, c3, c4 }; }
82          public Operand(joeq.Compiler.Quad.Operand[] c) { a = c; }
83          public int size() { return a.length; }
84          public Object get(int index) { return getOperand(index); }
85          public joeq.Compiler.Quad.Operand getOperand(int index) { return a[index]; }
86          public ListIterator.Operand operandIterator() { return new Iterator(); }
87          private class Iterator extends UnmodifiableListIterator implements ListIterator.Operand {
88              private int i = -1;
89              public boolean hasNext() { return i+1 < a.length; }
90              public boolean hasPrevious() { return i >= 0; }
91              public int nextIndex() { return i+1; }
92              public int previousIndex() { return i; }
93              public Object next() { return a[++i]; }
94              public joeq.Compiler.Quad.Operand nextOperand() { return a[++i]; }
95              public Object previous() { return a[i--]; }
96              public joeq.Compiler.Quad.Operand previousOperand() { return a[i--]; }
97          }
98          public static final Operand EMPTY = new Operand(new joeq.Compiler.Quad.Operand[0]);
99          public static Operand getEmptyList() { return EMPTY; }
100     }
101    
102     public static class BasicBlock extends java.util.AbstractList implements List.BasicBlock {
103         private final joeq.Compiler.Quad.BasicBlock[] a;
104         public BasicBlock(joeq.Compiler.Quad.BasicBlock[] c) { a = c; }
105         public int size() { return a.length; }
106         public Object get(int index) { return getBasicBlock(index); }
107         public joeq.Compiler.Quad.BasicBlock getBasicBlock(int index) { return a[index]; }
108         public ListIterator.BasicBlock basicBlockIterator() { return new Iterator(); }
109         private class Iterator extends UnmodifiableListIterator implements ListIterator.BasicBlock {
110             private int i = -1;
111             public boolean hasNext() { return i+1 < a.length; }
112             public boolean hasPrevious() { return i >= 0; }
113             public int nextIndex() { return i+1; }
114             public int previousIndex() { return i; }
115             public Object next() { return a[++i]; }
116             public joeq.Compiler.Quad.BasicBlock nextBasicBlock() { return a[++i]; }
117             public Object previous() { return a[i--]; }
118             public joeq.Compiler.Quad.BasicBlock previousBasicBlock() { return a[i--]; }
119         }
120         public static final BasicBlock EMPTY = new BasicBlock(new joeq.Compiler.Quad.BasicBlock[0]);
121         public static BasicBlock getEmptyList() { return EMPTY; }
122     }
123         
124     public static class Quad extends java.util.AbstractList implements List.Quad {
125         private final joeq.Compiler.Quad.Quad[] a;
126         public Quad(joeq.Compiler.Quad.Quad[] c) { a = c; }
127         public Quad(joeq.Compiler.Quad.Quad c) { a = new joeq.Compiler.Quad.Quad[] { c }; }
128         public int size() { return a.length; }
129         public Object get(int index) { return getQuad(index); }
130         public joeq.Compiler.Quad.Quad getQuad(int index) { return a[index]; }
131         public ListIterator.Quad quadIterator() { return new Iterator(); }
132         private class Iterator extends UnmodifiableListIterator implements ListIterator.Quad {
133             private int i = -1;
134             public boolean hasNext() { return i+1 < a.length; }
135             public boolean hasPrevious() { return i >= 0; }
136             public int nextIndex() { return i+1; }
137             public int previousIndex() { return i; }
138             public Object next() { return a[++i]; }
139             public joeq.Compiler.Quad.Quad nextQuad() { return a[++i]; }
140             public Object previous() { return a[i--]; }
141             public joeq.Compiler.Quad.Quad previousQuad() { return a[i--]; }
142         }
143         public static final Quad EMPTY = new Quad(new joeq.Compiler.Quad.Quad[0]);
144         public static Quad getEmptyList() { return EMPTY; }
145     }
146 }