|
1 | 1 | package org.jlibsedml; |
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
| 4 | +import java.util.List; |
4 | 5 | import java.util.Collections; |
5 | 6 | import java.util.List; |
6 | 7 | import java.util.Set; |
7 | 8 | import java.util.TreeSet; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Encapsulates the Plot2d Sed-ML element. |
| 12 | + * |
11 | 13 | * @author anu/radams |
12 | 14 | * |
13 | 15 | */ |
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 | + |
140 | 148 | } |
0 commit comments