List of usage examples for javafx.util.converter LocalDateStringConverter LocalDateStringConverter
public LocalDateStringConverter()
From source file:iristk.util.Record.java
public synchronized void put(String field, Object value) { if (field != null) { //if (field.contains(".")) { // System.err.println("Warning: use of dots when accessing record fields is deprecated: " + field); // field = field.replace(".", ":"); //}/*from ww w . java 2 s .c o m*/ if (field.contains(":")) { int i = field.indexOf(":"); String fn = field.substring(0, i); String rest = field.substring(i + 1); String[] subFields; if (fn.equals("*")) { subFields = dynamicFields.keySet().toArray(new String[0]); } else { subFields = new String[] { fn }; } for (String f : subFields) { Record subRec = getRecord(f); if (subRec != null) { subRec.put(rest, value); } else { Record record = new Record(); dynamicFields.put(f, record); record.put(rest, value); } } } else if (field.equals("*")) { for (String f : dynamicFields.keySet()) { dynamicFields.put(f, value); } } else { RecordInfo info = getRecordInfo(); Method setMethod = info.setMethodFields.get(field); if (setMethod != null) { try { setMethod.invoke(this, asType(value, setMethod.getParameterTypes()[0])); return; } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } Field setField = info.classFields.get(field); if (setField != null) { try { if (setField.getType().equals(java.time.LocalDate.class)) { setField.set(this, new LocalDateStringConverter().fromString((String) value)); } else if (setField.getType().equals(java.time.LocalDateTime.class)) { setField.set(this, new LocalDateTimeStringConverter().fromString((String) value)); } else { setField.set(this, asType(value, setField.getType())); } return; } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } } dynamicFields.put(field, value); } } }
From source file:iristk.util.Record.java
/** * Converts the Record to a JSONObject//from www. j a va2s .c o m * @return JSONObject */ public JsonObject toJSON() { JsonObject json = new JsonObject(); if (this.getClass() != Record.class) { json.add("class", this.getClass().getName()); } for (String key : getPersistentFields()) { Object val = get(key); if (val != null) { if (key.equals("class")) { System.err.println("Warning: fields with the name 'class' are not allowed"); } else if (val instanceof Float) { json.add(key, (Float) val); } else if (val instanceof Double) { json.add(key, (Double) val); } else if (val instanceof Integer) { json.add(key, (Integer) val); } else if (val instanceof Long) { json.add(key, (Long) val); } else if (val instanceof Boolean) { json.add(key, (Boolean) val); } else if (val instanceof String) { json.add(key, (String) val); } else if (val instanceof Record) { json.add(key, ((Record) val).toJSON()); } else if (val instanceof List) { json.add(key, toJsonArray((List) val)); } else if (val instanceof LocalDateTime) { json.add(key, new LocalDateTimeStringConverter().toString((LocalDateTime) val)); } else if (val instanceof LocalDate) { json.add(key, new LocalDateStringConverter().toString((LocalDate) val)); } else { System.err.println("Warning: could not convert " + val.getClass() + " to JSON"); } } } return json; }
From source file:iristk.util.Record.java
private static JsonArray toJsonArray(List list) { JsonArray arr = new JsonArray(); for (Object val : list) { if (val instanceof Float) { arr.add((Float) val); } else if (val instanceof Double) { arr.add((Double) val); } else if (val instanceof Integer) { arr.add((Integer) val); } else if (val instanceof Long) { arr.add((Long) val); } else if (val instanceof Boolean) { arr.add((Boolean) val); } else if (val instanceof String) { arr.add((String) val); } else if (val instanceof Record) { arr.add(((Record) val).toJSON()); } else if (val instanceof List) { arr.add(toJsonArray((List) val)); } else if (val instanceof LocalDateTime) { arr.add(new LocalDateTimeStringConverter().toString((LocalDateTime) val)); } else if (val instanceof LocalDate) { arr.add(new LocalDateStringConverter().toString((LocalDate) val)); } else {// ww w. j a v a2s . c om System.err.println("Warning: could not convert " + val.getClass() + " to JSON"); } } return arr; }