Skip to content

Commit

Permalink
Merge pull request #37 from relinc/sample-loading-issues
Browse files Browse the repository at this point in the history
fixes issue #36
  • Loading branch information
bhalonen authored Nov 20, 2018
2 parents a153fe9 + 219c0ef commit a7f99cf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Libraries/src/net/relinc/libraries/application/StrikerBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.json.simple.JSONObject;

public class StrikerBar {
private double length;
private double diameter;
private double density;
private double speed;
public StrikerBar(){
length = 0;
diameter = 0;
density = 0;
speed = 0;
}
public StrikerBar(JSONObject jsonObject){
JsonReader json = new JsonReader(jsonObject);

json.get("length").ifPresent(ob -> setLength((Double)ob));
json.get("diameter").ifPresent(ob -> setDiameter((Double)ob));
json.get("density").ifPresent(ob -> setDensity((Double)ob));
json.get("speed").ifPresent(ob -> setSpeed((Double)ob));

}
public double getLength() {
return length;
}
Expand Down
12 changes: 10 additions & 2 deletions Libraries/src/net/relinc/libraries/sample/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,19 @@ private void setCommonParametersJSON(JSONObject jsonObject) {
json.get("Density").ifPresent(ob -> setDensity((Double)ob));
json.get("Young's Modulus").ifPresent(ob -> setYoungsModulus((Double)ob));
json.get("Heat Capacity").ifPresent(ob -> setHeatCapacity((Double)ob));
json.get("StrikerBar").ifPresent(ob -> strikerBar = (StrikerBar)ob );
json.get("StrikerBar").ifPresent(ob -> setStrikerBar((String)ob) );

setSpecificParametersJSON(jsonObject);
}

private void setStrikerBar(String input){
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(input);
strikerBar = new StrikerBar(jsonObject);
} catch (org.json.simple.parser.ParseException e) {
e.printStackTrace();
}
}
public void setParametersFromJSONString(String input) {
JSONParser jsonParser = new JSONParser();

Expand Down

0 comments on commit a7f99cf

Please sign in to comment.