Skip to content

Commit 2c60d0f

Browse files
First pass at upgrade; mostly clean-up; also abstract "Plot" class
1 parent 5678ce1 commit 2c60d0f

File tree

11 files changed

+745
-895
lines changed

11 files changed

+745
-895
lines changed

vcell-cli/src/main/java/org/vcell/cli/run/plotting/PlottingDataExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public Map<Results2DLinePlot, Pair<String, String>> extractPlotRelevantData(Map<
4747
Results2DLinePlot plot = new Results2DLinePlot();
4848
plot.setTitle(requestedPlot.getName());
4949

50+
5051
for (Curve curve : requestedPlot.getListOfCurves()){
5152
ValueHolder<LazySBMLNonSpatialDataAccessor> xResults, yResults;
5253
BiosimulationLog.instance().updateCurveStatusYml(this.sedmlName, requestedPlot.getId(), curve.getId(), BiosimulationLog.Status.RUNNING);
@@ -68,8 +69,8 @@ public Map<Results2DLinePlot, Pair<String, String>> extractPlotRelevantData(Map<
6869
throw this.logBeforeThrowing(exception, requestedPlot.getId(), curve.getId());
6970
}
7071

71-
boolean hasBadXName = requestedXGenerator.getName() == null || "".equals(requestedXGenerator.getName());
72-
boolean hasBadYName = requestedYGenerator.getName() == null || "".equals(requestedYGenerator.getName());
72+
boolean hasBadXName = requestedXGenerator.getName() == null || requestedXGenerator.getName().isEmpty();
73+
boolean hasBadYName = requestedYGenerator.getName() == null || requestedYGenerator.getName().isEmpty();
7374
String xLabel = hasBadXName ? requestedXGenerator.getId() : requestedXGenerator.getName();
7475
String yLabel = hasBadYName ? requestedYGenerator.getId() : requestedYGenerator.getName();
7576
xAxisNames.add(xLabel);

vcell-cli/src/main/java/org/vcell/cli/run/plotting/Results2DLinePlot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ public int getLargestSeriesSize(){
8484
* @throws IllegalArgumentException if the length of data on each axis doesn't match
8585
*/
8686
public void addXYData(SingleAxisSeries xData, SingleAxisSeries yData){
87+
// input validation
8788
if (xData == null) throw new IllegalArgumentException("Parameter `xData` can not be null!");
8889
if (yData == null) throw new IllegalArgumentException("Parameter `yData` can not be null!");
8990
if (xData.data().size() != yData.data().size()) throw new IllegalArgumentException("Data lengths do not match!");
9091
if (this.xLabels.contains(xData.label()) && !this.dataSetMappings.containsKey(xData))
9192
throw new IllegalArgumentException("plot already has data for x-axis with the label`" + xData.label() + "` (but it has different values) ");
9293
if (this.yLabels.contains(yData.label())) throw new IllegalArgumentException("plot already has data for y-axis `" + yData.label() + "`");
94+
//
9395
if (!this.dataSetMappings.containsKey(xData)) this.dataSetMappings.put(xData, new LinkedHashSet<>());
9496
this.dataSetMappings.get(xData).add(yData);
9597
this.xLabels.add(xData.label());

vcell-core/src/main/java/org/jlibsedml/DataGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public String getMathAsString(){
154154

155155
@Override
156156
public String getElementName() {
157-
return SEDMLTags.DATAGENERATOR_TAG;
157+
return SEDMLTags.DATA_GENERATOR_TAG;
158158
}
159159

160160
public boolean accept(SEDMLVisitor visitor){

vcell-core/src/main/java/org/jlibsedml/OneStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String getSimulationKind() {
3131

3232
@Override
3333
public String getElementName() {
34-
return SEDMLTags.SIM_OS;
34+
return SEDMLTags.SIM_ONE_STEP;
3535
}
3636
/**
3737
* Sets the step.

vcell-core/src/main/java/org/jlibsedml/Output.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ public abstract class Output extends AbstractIdentifiableElement{
1111

1212
public boolean accept(SEDMLVisitor visitor){
1313
if(visitor.visit(this)){
14-
if(isPlot2d()){
14+
if(this.isPlot2d()){
1515
for (Curve c: ((Plot2D)this).getListOfCurves()) {
1616
if(! c.accept(visitor)){
1717
return false;
1818
}
1919
}
2020
return true;
2121
}
22-
else if(isPlot3d()){
22+
else if(this.isPlot3d()){
2323
for (Surface sf: ((Plot3D)this).getListOfSurfaces()) {
2424
if(! sf.accept(visitor)){
2525
return false;
2626
}
2727
}
2828
return true;
2929
}
30-
else if(isReport()){
30+
else if(this.isReport()){
3131
for (DataSet sds: ((Report)this).getListOfDataSets()) {
3232
if(! sds.accept(visitor)){
3333
return false;
@@ -64,15 +64,15 @@ public Output(String id, String name) {
6464
* @return <code>true</code> if this is a Plot2d description, <code>false</code> otherwise.
6565
*/
6666
public boolean isPlot2d(){
67-
return getKind().equals(SEDMLTags.PLOT2D_KIND);
67+
return this.getKind().equals(SEDMLTags.PLOT2D_KIND);
6868
}
6969

7070
/**
7171
* Boolean test for whether this output is a Plot3d description.
7272
* @return <code>true</code> if this is a Plot3d description, <code>false</code> otherwise.
7373
*/
7474
public boolean isPlot3d(){
75-
return getKind().equals(SEDMLTags.PLOT3D_KIND);
75+
return this.getKind().equals(SEDMLTags.PLOT3D_KIND);
7676
}
7777

7878

@@ -81,7 +81,7 @@ public boolean isPlot3d(){
8181
* @return <code>true</code> if this is a report description, <code>false</code> otherwise.
8282
*/
8383
public boolean isReport(){
84-
return getKind().equals(SEDMLTags.REPORT_KIND);
84+
return this.getKind().equals(SEDMLTags.REPORT_KIND);
8585
}
8686

8787
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.jlibsedml;
2+
3+
public abstract class Plot extends Output {
4+
/**
5+
*
6+
* @param id A unique id for this element in the document.
7+
* @param name An optional name for this element.
8+
*/
9+
public Plot(String id, String name) {
10+
super(id, name);
11+
}
12+
}
Lines changed: 134 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,148 @@
11
package org.jlibsedml;
22

33
import java.util.ArrayList;
4+
import java.util.List;
45
import java.util.Collections;
56
import java.util.List;
67
import java.util.Set;
78
import java.util.TreeSet;
89

910
/**
1011
* Encapsulates the Plot2d Sed-ML element.
12+
*
1113
* @author anu/radams
1214
*
1315
*/
14-
public class Plot2D extends Output {
15-
16-
@Override
17-
public String toString() {
18-
return "Plot2D [listOfCurves=" + listOfCurves + ", name=" + getName() + "]";
19-
}
20-
21-
private ArrayList<Curve> listOfCurves= new ArrayList<Curve>();
22-
23-
24-
/**
25-
*
26-
* @param id A unique id for this element in the document.
27-
* @param name An optional name for this element.
28-
*/
29-
public Plot2D(String id, String name) {
30-
super(id, name);
31-
}
32-
33-
/**
34-
* Gets a read-only list of Curves contained in this element.
35-
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
36-
*/
37-
public List<Curve> getListOfCurves() {
38-
return Collections.unmodifiableList(listOfCurves);
39-
}
40-
41-
/**
42-
* Gets the type of this output.
43-
* @return SEDMLTags.PLOT2D_KIND
44-
*/
45-
public String getKind() {
46-
return SEDMLTags.PLOT2D_KIND;
47-
}
48-
49-
/**
50-
* Adds a {@link Curve} to this object's list of Curves, if not already present.
51-
* @param curve A non-null {@link Curve} element
52-
* @return <code>true</code> if curve added, <code>false </code> otherwise.
53-
*/
54-
public boolean addCurve(Curve curve ){
55-
if(!listOfCurves.contains(curve)) {
56-
return listOfCurves.add(curve);
57-
} else {
58-
// TODO: add to error list
59-
}
60-
return false;
61-
}
62-
63-
/**
64-
* Removes a {@link Curve} from this object's list of Curves, if not already present.
65-
* @param curve A non-null {@link Curve} element
66-
* @return <code>true</code> if curve added, <code>false </code> otherwise.
67-
*/
68-
public boolean removeCurve(Curve curve ){
69-
70-
return listOfCurves.remove(curve);
71-
72-
}
73-
74-
/**
75-
* Returns a sublist of the {@link List} of Curves for this plot, that use the output of the specified {@link DataGenerator}
76-
* for the X-axis.
77-
* @param dg A non-null {@link DataGenerator}
78-
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
79-
*/
80-
public List<Curve> getCurvesUsingDataGeneratorAsXAxis(DataGenerator dg){
81-
List<Curve> rc = new ArrayList<Curve>();
82-
for (Curve cv: listOfCurves){
83-
if(cv.getXDataReference().equals(dg.getId())){
84-
rc.add(cv);
85-
}
86-
}
87-
return rc;
88-
}
89-
90-
91-
/**
92-
* Returns a sublist of the {@link List} of Curves for this plot, that use the output of the specified {@link DataGenerator}
93-
* for the Y-axis.
94-
* @param dg A non-null {@link DataGenerator}
95-
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
96-
*/
97-
public List<Curve> getCurvesUsingDataGeneratorAsYAxis(DataGenerator dg){
98-
List<Curve> rc = new ArrayList<Curve>();
99-
for (Curve cv: listOfCurves){
100-
if(cv.getYDataReference().equals(dg.getId())){
101-
rc.add(cv);
102-
}
103-
}
104-
return rc;
105-
}
106-
107-
@Override
108-
public List<String> getAllDataGeneratorReferences() {
109-
Set<String> rc = new TreeSet<String>();
110-
for (Curve c: listOfCurves){
111-
rc.add(c.getXDataReference());
112-
rc.add(c.getYDataReference());
113-
}
114-
List<String> rc2 = new ArrayList<String>();
115-
for (String id:rc){
116-
rc2.add(id);
117-
}
118-
return rc2;
119-
120-
}
121-
122-
@Override
123-
public List<String> getAllIndependentDataGeneratorReferences() {
124-
Set<String> rc = new TreeSet<String>();
125-
for (Curve c: listOfCurves){
126-
rc.add(c.getXDataReference());
127-
}
128-
List<String> rc2 = new ArrayList<String>();
129-
for (String id:rc){
130-
rc2.add(id);
131-
}
132-
return rc2;
133-
}
134-
135-
@Override
136-
public String getElementName() {
137-
return SEDMLTags.OUTPUT_P2D;
138-
}
139-
16+
public class Plot2D extends Plot {
17+
18+
@Override
19+
public String toString() {
20+
return "Plot2D [listOfCurves=" + this.listOfCurves + ", name=" + this.getName() + "]";
21+
}
22+
23+
private final List<Curve> listOfCurves = new ArrayList<>();
24+
25+
26+
/**
27+
*
28+
* @param id A unique id for this element in the document.
29+
* @param name An optional name for this element.
30+
*/
31+
public Plot2D(String id, String name) {
32+
super(id, name);
33+
}
34+
35+
/**
36+
* Gets a read-only list of Curves contained in this element.
37+
*
38+
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
39+
*/
40+
public List<Curve> getListOfCurves() {
41+
return Collections.unmodifiableList(this.listOfCurves);
42+
}
43+
44+
/**
45+
* Gets the type of this output.
46+
*
47+
* @return SEDMLTags.PLOT2D_KIND
48+
*/
49+
public String getKind() {
50+
return SEDMLTags.PLOT2D_KIND;
51+
}
52+
53+
/**
54+
* Adds a {@link Curve} to this object's list of Curves, if not already present.
55+
*
56+
* @param curve A non-null {@link Curve} element
57+
* @return <code>true</code> if curve added, <code>false </code> otherwise.
58+
*/
59+
public boolean addCurve(Curve curve) {
60+
if (!this.listOfCurves.contains(curve)) {
61+
return this.listOfCurves.add(curve);
62+
} else {
63+
// TODO: add to error list
64+
}
65+
return false;
66+
}
67+
68+
/**
69+
* Removes a {@link Curve} from this object's list of Curves, if not already present.
70+
*
71+
* @param curve A non-null {@link Curve} element
72+
* @return <code>true</code> if curve added, <code>false </code> otherwise.
73+
*/
74+
public boolean removeCurve(Curve curve) {
75+
76+
return this.listOfCurves.remove(curve);
77+
78+
}
79+
80+
/**
81+
* Returns a sublist of the {@link List} of Curves for this plot, that use the output of the specified {@link DataGenerator}
82+
* for the X-axis.
83+
*
84+
* @param dg A non-null {@link DataGenerator}
85+
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
86+
*/
87+
public List<Curve> getCurvesUsingDataGeneratorAsXAxis(DataGenerator dg) {
88+
List<Curve> rc = new ArrayList<Curve>();
89+
for (Curve cv : this.listOfCurves) {
90+
if (cv.getXDataReference().equals(dg.getId())) {
91+
rc.add(cv);
92+
}
93+
}
94+
return rc;
95+
}
96+
97+
98+
/**
99+
* Returns a sublist of the {@link List} of Curves for this plot, that use the output of the specified {@link DataGenerator}
100+
* for the Y-axis.
101+
*
102+
* @param dg A non-null {@link DataGenerator}
103+
* @return A possibly empty but non-null {@link List} of {@link Curve} elements.
104+
*/
105+
public List<Curve> getCurvesUsingDataGeneratorAsYAxis(DataGenerator dg) {
106+
List<Curve> rc = new ArrayList<Curve>();
107+
for (Curve cv : this.listOfCurves) {
108+
if (cv.getYDataReference().equals(dg.getId())) {
109+
rc.add(cv);
110+
}
111+
}
112+
return rc;
113+
}
114+
115+
@Override
116+
public List<String> getAllDataGeneratorReferences() {
117+
Set<String> rc = new TreeSet<String>();
118+
for (Curve c : this.listOfCurves) {
119+
rc.add(c.getXDataReference());
120+
rc.add(c.getYDataReference());
121+
}
122+
List<String> rc2 = new ArrayList<String>();
123+
for (String id : rc) {
124+
rc2.add(id);
125+
}
126+
return rc2;
127+
128+
}
129+
130+
@Override
131+
public List<String> getAllIndependentDataGeneratorReferences() {
132+
Set<String> rc = new TreeSet<String>();
133+
for (Curve c : this.listOfCurves) {
134+
rc.add(c.getXDataReference());
135+
}
136+
List<String> rc2 = new ArrayList<String>();
137+
for (String id : rc) {
138+
rc2.add(id);
139+
}
140+
return rc2;
141+
}
142+
143+
@Override
144+
public String getElementName() {
145+
return SEDMLTags.OUTPUT_P2D;
146+
}
147+
140148
}

0 commit comments

Comments
 (0)