use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class JsonLoader method to3DoubleArray.
public Pair<Object, Class> to3DoubleArray(JsonValue attribute) {
JsonValue json = attribute.child;
int size = attribute.size;
double[][][] result = new double[size][][];
int i = 0;
do {
double[][] l1 = new double[json.size][];
// Fill in last level
JsonValue child = json.child;
int j = 0;
do {
double[] l2 = child.asDoubleArray();
l1[j] = l2;
child = child.next();
j++;
} while (child != null);
result[i] = l1;
json = json.next();
i++;
} while (json != null);
return new Pair<>(result, double[][][].class);
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class JsonLoader method convertJsonToMap.
public Map<String, Object> convertJsonToMap(JsonValue json) {
Map<String, Object> map = new TreeMap<>();
JsonValue child = json.child;
while (child != null) {
Object val = getValue(child);
if (val != null) {
map.put(child.name, val);
}
child = child.next;
}
return map;
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class JsonLoader method to2DoubleArray.
public Pair<Object, Class> to2DoubleArray(JsonValue attribute) {
JsonValue json = attribute.child;
int size = attribute.size;
double[][] result = new double[size][];
int i = 0;
do {
result[i] = json.asDoubleArray();
json = json.next();
i++;
} while (json != null);
return new Pair<>(result, double[][].class);
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class JsonLoader method loadData.
@Override
public Array<? extends SceneGraphNode> loadData() {
Array<T> bodies = new Array<>();
Array<String> filePaths = new Array<>(this.filePaths);
// Actually load the files.
JsonReader json = new JsonReader();
for (String filePath : filePaths) {
try {
FileHandle file = Settings.settings.data.dataFileHandle(filePath);
JsonValue model = json.parse(file.read());
// Must have an 'objects' element.
if (model.has("objects")) {
JsonValue child = model.get("objects").child;
final int count = model.get("objects").size;
int current = 0;
while (child != null) {
current++;
String clazzName = child.getString("impl").replace("gaia.cu9.ari.gaiaorbit", "gaiasky");
@SuppressWarnings("unchecked") Class<Object> clazz = (Class<Object>) ClassReflection.forName(clazzName);
// Convert to object and add to list.
@SuppressWarnings("unchecked") T object = (T) convertJsonToObject(child, clazz);
bodies.add(object);
child = child.next;
EventManager.publish(Event.UPDATE_LOAD_PROGRESS, this, file.name(), (float) current / (float) count);
}
EventManager.publish(Event.UPDATE_LOAD_PROGRESS, this, file.name(), 2f);
logger.info(I18n.txt("notif.nodeloader", current, filePath));
}
} catch (Exception e) {
logger.error(e);
}
}
return bodies;
}
use of com.badlogic.gdx.utils.JsonValue in project gaiasky by langurmonkey.
the class ArchiveViewWindow method isToArray.
private String[][] isToArray(InputStream is, String format) {
String data = slurp(is, 2046);
if (format.equalsIgnoreCase("csv")) {
/**
* PARSE CSV *
*/
String[] rows = data.split(separator);
if (rows.length <= 1) {
return null;
}
String[][] matrix = new String[rows.length][];
int r = 0;
for (String row : rows) {
String[] tokens = row.split(",");
int i = 0;
for (String token : tokens) {
token = token.trim();
tokens[i] = trim(token, "\"");
i++;
}
matrix[r] = tokens;
r++;
}
return matrix;
} else if (format.equalsIgnoreCase("json")) {
/**
* PARSE JSON *
*/
JsonReader json = new JsonReader();
JsonValue root = json.parse(data);
JsonValue metadata = root.child;
int size = metadata.size;
JsonValue column = metadata.child;
String[] colnames = new String[size];
String[] descriptions = new String[size];
String[] values = new String[size];
int i = 0;
do {
colnames[i] = column.getString("name");
descriptions[i] = column.getString("description") + (column.has("unit") ? " [" + column.getString("unit") + "]" : "");
i++;
column = column.next;
} while (column != null);
JsonValue datacol = metadata.next.child.child;
i = 0;
do {
values[i] = datacol.asString();
i++;
datacol = datacol.next;
} while (datacol != null);
String[][] matrix = new String[3][];
matrix[0] = colnames;
matrix[1] = values;
matrix[2] = descriptions;
return matrix;
}
return null;
}
Aggregations