Browse Source

jltl2ba.APSet: source format, tidy up comments

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@11275 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Joachim Klein 10 years ago
parent
commit
c32cf2c94c
  1. 56
      prism/src/jltl2ba/APSet.java

56
prism/src/jltl2ba/APSet.java

@ -30,14 +30,16 @@ import java.io.PrintStream;
* Class representing a set of atomic propositions (AP). * Class representing a set of atomic propositions (AP).
* The APs are ordered, in insertion order. * The APs are ordered, in insertion order.
*/ */
public class APSet implements Iterable<String> {
public class APSet implements Iterable<String>
{
private Vector<String> vector; private Vector<String> vector;
/** /**
* Constructor. * Constructor.
*/ */
public APSet() {
public APSet()
{
vector = new Vector<String>(); vector = new Vector<String>();
} }
@ -46,14 +48,15 @@ public class APSet implements Iterable<String> {
* @param name the name of the AP * @param name the name of the AP
* @return the index of the added AP * @return the index of the added AP
*/ */
public int addAP(String name) {
public int addAP(String name)
{
int i = vector.indexOf(name); int i = vector.indexOf(name);
if (i == -1) { if (i == -1) {
vector.add(name); vector.add(name);
return vector.size() - 1; return vector.size() - 1;
}
else return i;
} else
return i;
} }
/** /**
@ -61,7 +64,8 @@ public class APSet implements Iterable<String> {
* @param index index of the AP * @param index index of the AP
* @return string-ref with the name * @return string-ref with the name
*/ */
public String getAP(int index) {
public String getAP(int index)
{
return vector.elementAt(index); return vector.elementAt(index);
} }
@ -69,11 +73,13 @@ public class APSet implements Iterable<String> {
* Searches for an existing AP in the APSet and returns the index. * Searches for an existing AP in the APSet and returns the index.
* @return the index of the AP, or -1 if not found. * @return the index of the AP, or -1 if not found.
*/ */
public int indexOf(String s) {
public int indexOf(String s)
{
return vector.indexOf(s); return vector.indexOf(s);
} }
public boolean hasAP(String s) {
public boolean hasAP(String s)
{
return vector.contains(s); return vector.contains(s);
} }
@ -81,7 +87,8 @@ public class APSet implements Iterable<String> {
* Get the size of this set * Get the size of this set
* @return the number of APs in this set. * @return the number of APs in this set.
*/ */
public int size() {
public int size()
{
return vector.size(); return vector.size();
} }
@ -89,8 +96,9 @@ public class APSet implements Iterable<String> {
* Get the size of the powerset 2^APSet * Get the size of the powerset 2^APSet
* @return the size of 2^AP * @return the size of 2^AP
*/ */
public int powersetSize() {
return (1<<size());
public int powersetSize()
{
return (1 << size());
} }
/** /**
@ -111,12 +119,12 @@ public class APSet implements Iterable<String> {
/** /**
* Create a new APSet with the same number of * Create a new APSet with the same number of
* atomic propositions, but named 'p0', 'p1', 'p2', ... * atomic propositions, but named 'p0', 'p1', 'p2', ...
* The caller takes ownership of the memory of the created APSet.
* @return APSet* to newly created APSet
* @return the newly created APSet
*/ */
public APSet createCanonical() {
public APSet createCanonical()
{
APSet canonical = new APSet(); APSet canonical = new APSet();
for (int i=0; i < size(); i++)
for (int i = 0; i < size(); i++)
canonical.addAP("p" + i); canonical.addAP("p" + i);
return canonical; return canonical;
} }
@ -142,7 +150,8 @@ public class APSet implements Iterable<String> {
*/ */
public Iterable<APElement> elements() public Iterable<APElement> elements()
{ {
return new Iterable<APElement>() {
return new Iterable<APElement>()
{
@Override @Override
public Iterator<APElement> iterator() public Iterator<APElement> iterator()
{ {
@ -152,26 +161,31 @@ public class APSet implements Iterable<String> {
}; };
} }
public void print(PrintStream out) {
/** Print this AP set */
public void print(PrintStream out)
{
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
out.println(i + ": " + getAP(i)); out.println(i + ": " + getAP(i));
} }
} }
/** Print this APSet as a HOA AP: header */ /** Print this APSet as a HOA AP: header */
public void print_hoa(PrintStream out) {
public void print_hoa(PrintStream out)
{
out.print("AP: "); out.print("AP: ");
out.print(size()); out.print(size());
for (String ap : this) { for (String ap : this) {
// TODO(JK): proper quoting // TODO(JK): proper quoting
out.print(" \""+ap+"\"");
out.print(" \"" + ap + "\"");
} }
out.println(); out.println();
} }
public String toString() {
@Override
public String toString()
{
String rv = "{"; String rv = "{";
for (Iterator<String> it = this.iterator(); it.hasNext(); ) {
for (Iterator<String> it = this.iterator(); it.hasNext();) {
rv = rv + it.next(); rv = rv + it.next();
if (it.hasNext()) { if (it.hasNext()) {
rv = rv + ","; rv = rv + ",";

Loading…
Cancel
Save