Browse Source

Values, getXYValue(): support for BigRational

master
Joachim Klein 8 years ago
committed by Dave Parker
parent
commit
9294070eb1
  1. 24
      prism/src/parser/Values.java

24
prism/src/parser/Values.java

@ -241,16 +241,19 @@ public class Values implements Cloneable //implements Comparable
public int getIntValue(int i) throws PrismLangException public int getIntValue(int i) throws PrismLangException
{ {
Object o; Object o;
o = values.get(i); o = values.get(i);
if (o instanceof Boolean) { if (o instanceof Boolean) {
return ((Boolean)o).booleanValue() ? 1 : 0; return ((Boolean)o).booleanValue() ? 1 : 0;
} }
if (o instanceof Integer) { if (o instanceof Integer) {
return ((Integer)o).intValue(); return ((Integer)o).intValue();
} }
if (o instanceof BigRational) {
return ((BigRational)o).toInt();
}
throw new PrismLangException("Cannot get integer value for \"" + getName(i) + "\""); throw new PrismLangException("Cannot get integer value for \"" + getName(i) + "\"");
} }
@ -273,6 +276,9 @@ public class Values implements Cloneable //implements Comparable
if (o instanceof Double) { if (o instanceof Double) {
return ((Double)o).doubleValue(); return ((Double)o).doubleValue();
} }
if (o instanceof BigRational) {
return ((BigRational)o).doubleValue();
}
throw new PrismLangException("Cannot get double value for \"" + getName(i) + "\""); throw new PrismLangException("Cannot get double value for \"" + getName(i) + "\"");
} }
@ -283,14 +289,16 @@ public class Values implements Cloneable //implements Comparable
public boolean getBooleanValue(int i) throws PrismLangException public boolean getBooleanValue(int i) throws PrismLangException
{ {
Object o; Object o;
o = values.get(i); o = values.get(i);
if (!(o instanceof Boolean)) {
if (o instanceof Boolean) {
return ((Boolean)o).booleanValue();
} else if (o instanceof BigRational) {
return ((BigRational)o).toBoolean();
} else {
throw new PrismLangException("Cannot get boolean value for \"" + getName(i) + "\""); throw new PrismLangException("Cannot get boolean value for \"" + getName(i) + "\"");
} }
return ((Boolean)o).booleanValue();
} }
/** /**

Loading…
Cancel
Save