00001 package edu.ksu.cis.bandera.bir;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import ca.mcgill.sable.util.*;
00036
00037 public class StateVarVector {
00038
00039 int size = 0;
00040 StateVar [] data;
00041
00042 public StateVarVector() { this(10); }
00043 public StateVarVector(int capacity) {
00044 data = new StateVar[capacity];
00045 }
00046 public StateVarVector(StateVar x) {
00047 this(10);
00048 addElement(x);
00049 }
00050 public void addElement(StateVar x) {
00051 if (x == null)
00052 throw new RuntimeException("Element cannot be null");
00053 if (size == data.length)
00054 expand();
00055 data[size++] = x;
00056 }
00057 public boolean contains(StateVar x) {
00058 for (int i = 0; i < size; i++)
00059 if (data[i].equals(x))
00060 return true;
00061 return false;
00062 }
00063 public StateVar elementAt(int pos) {
00064 if (pos < 0 || pos >= size)
00065 throw new RuntimeException("Position invalid: " + pos);
00066 return data[pos];
00067 }
00068 void expand() {
00069 StateVar [] newData = new StateVar[data.length * 2];
00070 for (int i = 0; i < data.length; i++)
00071 newData[i] = data[i];
00072 data = newData;
00073 }
00074 public StateVar firstElement() { return elementAt(0); }
00075 public int indexOf(StateVar x) {
00076 for (int i = 0; i < size; i++)
00077 if (data[i] == x)
00078 return i;
00079 return -1;
00080 }
00081 public void insertElementAt(StateVar x, int pos) {
00082 if (x == null)
00083 throw new RuntimeException("Element cannot be null");
00084 if (size == data.length)
00085 expand();
00086 if (pos > size || pos < 0)
00087 throw new RuntimeException("Position invalid: " + pos);
00088 for (int i = size; i > pos; i--)
00089 data[i] = data[i-1];
00090 data[pos] = x;
00091 size++;
00092 }
00093 public int size() { return size; }
00094 }