-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Tests are parameterized so that we test both the old and new parser code * Fix infinite while-loop issue in the old parser's `getWord`; `Reader#ready` indicates that `read` would be non-blocking, not that read would return new data. To find the end of the reader's data we have to watch for `-1` returned by `read`. * Get rid of deprecated `new Float(num)` call * Add getters for high/low in the range vertex classes for testing. We can test the string representation if we write tests for the individual classes, but for testing parsing checking the field values is more appropriate. We have to disable one test currently because the new parsing code fails it.
- Loading branch information
1 parent
68a1ca2
commit ebe1724
Showing
8 changed files
with
747 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
226 changes: 117 additions & 109 deletions
226
src/main/java/edu/umich/soar/visualsoar/graph/FloatRangeVertex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,117 @@ | ||
package edu.umich.soar.visualsoar.graph; | ||
|
||
import edu.umich.soar.visualsoar.dialogs.EditNumberDialog; | ||
|
||
public class FloatRangeVertex extends SoarVertex { | ||
private static final long serialVersionUID = 20221225L; | ||
|
||
////////////////////////////////////////// | ||
// Data Members | ||
////////////////////////////////////////// | ||
private double low, high; | ||
String rep; | ||
|
||
////////////////////////////////////////// | ||
// Constructors | ||
////////////////////////////////////////// | ||
public FloatRangeVertex(int id, double _low, double _high) { | ||
super(id); | ||
if (low > high) { | ||
throw new IllegalArgumentException("Low cannot be greater than high"); | ||
} | ||
low = _low; | ||
high = _high; | ||
rep = ": float" + getRangeString(); | ||
} | ||
|
||
////////////////////////////////////////// | ||
// Accessors | ||
////////////////////////////////////////// | ||
@Override | ||
public boolean allowsEmanatingEdges() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEditable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String s) { | ||
try { | ||
float f = Float.parseFloat(s); | ||
return f >= low && f <= high; | ||
} catch (NumberFormatException nfe) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public SoarVertex copy(int newId) { | ||
return new FloatRangeVertex(newId, low, high); | ||
} | ||
|
||
@Override | ||
public String typeName() { return "float"; } | ||
|
||
@Override | ||
public String toString() { | ||
return rep; | ||
} | ||
|
||
////////////////////////////////////////// | ||
// Manipulators | ||
////////////////////////////////////////// | ||
public boolean edit(java.awt.Frame owner) { | ||
EditNumberDialog theDialog = new EditNumberDialog(owner, "Float"); | ||
theDialog.setLow(new Float(low)); | ||
theDialog.setHigh(new Float(high)); | ||
theDialog.setVisible(true); | ||
|
||
if (theDialog.wasApproved()) { | ||
low = theDialog.getLow().floatValue(); | ||
high = theDialog.getHigh().floatValue(); | ||
rep = ": float" + getRangeString(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void write(java.io.Writer w) throws java.io.IOException { | ||
w.write("FLOAT_RANGE " + number + " " + low + " " + high + '\n'); | ||
} | ||
|
||
/** creates a string representing this integer's range. | ||
* If there is no limit then an empty string is returned */ | ||
public String getRangeString() { | ||
String result = ""; | ||
if (low != Float.NEGATIVE_INFINITY || high != Float.POSITIVE_INFINITY) { | ||
result += " [ "; | ||
if (low == Float.NEGATIVE_INFINITY) { | ||
result += "... "; | ||
} else { | ||
result += low + " "; | ||
} | ||
result += "- "; | ||
if (high == Float.POSITIVE_INFINITY) { | ||
result += "... "; | ||
} else { | ||
result += high + " "; | ||
} | ||
result += " ]"; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
} | ||
package edu.umich.soar.visualsoar.graph; | ||
|
||
import edu.umich.soar.visualsoar.dialogs.EditNumberDialog; | ||
|
||
public class FloatRangeVertex extends SoarVertex { | ||
private static final long serialVersionUID = 20221225L; | ||
|
||
////////////////////////////////////////// | ||
// Data Members | ||
////////////////////////////////////////// | ||
private double low, high; | ||
String rep; | ||
|
||
////////////////////////////////////////// | ||
// Constructors | ||
////////////////////////////////////////// | ||
public FloatRangeVertex(int id, double low, double high) { | ||
super(id); | ||
if (low > high) { | ||
throw new IllegalArgumentException("Low cannot be greater than high"); | ||
} | ||
this.low = low; | ||
this.high = high; | ||
rep = ": float" + getRangeString(); | ||
} | ||
|
||
////////////////////////////////////////// | ||
// Accessors | ||
////////////////////////////////////////// | ||
@Override | ||
public boolean allowsEmanatingEdges() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isEditable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String s) { | ||
try { | ||
float f = Float.parseFloat(s); | ||
return f >= low && f <= high; | ||
} catch (NumberFormatException nfe) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public SoarVertex copy(int newId) { | ||
return new FloatRangeVertex(newId, low, high); | ||
} | ||
|
||
@Override | ||
public String typeName() { return "float"; } | ||
|
||
@Override | ||
public String toString() { | ||
return rep; | ||
} | ||
|
||
////////////////////////////////////////// | ||
// Manipulators | ||
////////////////////////////////////////// | ||
public boolean edit(java.awt.Frame owner) { | ||
EditNumberDialog theDialog = new EditNumberDialog(owner, "Float"); | ||
theDialog.setLow((float) low); | ||
theDialog.setHigh((float) high); | ||
theDialog.setVisible(true); | ||
|
||
if (theDialog.wasApproved()) { | ||
low = theDialog.getLow().floatValue(); | ||
high = theDialog.getHigh().floatValue(); | ||
rep = ": float" + getRangeString(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void write(java.io.Writer w) throws java.io.IOException { | ||
w.write("FLOAT_RANGE " + number + " " + low + " " + high + '\n'); | ||
} | ||
|
||
public double getLow() { | ||
return low; | ||
} | ||
|
||
public double getHigh() { | ||
return high; | ||
} | ||
|
||
/** creates a string representing this integer's range. | ||
* If there is no limit then an empty string is returned */ | ||
public String getRangeString() { | ||
String result = ""; | ||
if (low != Float.NEGATIVE_INFINITY || high != Float.POSITIVE_INFINITY) { | ||
result += " [ "; | ||
if (low == Float.NEGATIVE_INFINITY) { | ||
result += "... "; | ||
} else { | ||
result += low + " "; | ||
} | ||
result += "- "; | ||
if (high == Float.POSITIVE_INFINITY) { | ||
result += "... "; | ||
} else { | ||
result += high + " "; | ||
} | ||
result += " ]"; | ||
} | ||
return result; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.