00001 package edu.ksu.cis.bandera.smv;
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 java.io.*;
00036 import java.util.*;
00037
00038 public class SmvList {
00039
00040 String operator;
00041 String identity;
00042 boolean skip;
00043 Vector elements;
00044
00045 public SmvList(String operator, String identity, boolean skip) {
00046 this.operator = operator;
00047 this.identity = identity;
00048 this.skip = skip;
00049 elements = new Vector();
00050 }
00051 public void add(Object o) {
00052 elements.addElement(o);
00053 }
00054 void indent(PrintWriter out, int level) {
00055 out.println();
00056 for (int i = 0; i < level; i++)
00057 out.print(" ");
00058 }
00059 public void print(PrintWriter out) {
00060 out.print(" ");
00061 print(out, 1);
00062 }
00063 void print(PrintWriter out, int level) {
00064 if (elements.size() == 0)
00065 out.print(identity);
00066 else if (elements.size() == 1)
00067 printElement(out, level, elements.elementAt(0));
00068 else {
00069 out.print("( ");
00070 printElement(out, level, elements.elementAt(0));
00071 for (int i = 1; i < elements.size(); i++) {
00072 indent(out, level);
00073 out.print(operator + " ");
00074 if (skip) indent(out, level + 1);
00075 printElement(out, level, elements.elementAt(i));
00076 }
00077 out.print(" )");
00078 }
00079 }
00080 void printElement(PrintWriter out, int level, Object element) {
00081 if (element instanceof SmvList)
00082 ((SmvList)element).print(out, level + 1);
00083 else
00084 out.print(element);
00085 }
00086 }