protected void handleAsMap(Map<?, ?> map) { if (map.isEmpty()) { super.setValueInternal(null); return; } double w = getMapValue(map, "width", 0); double h = getMapValue(map, "height", 0); super.setValueInternal(new Dimension2D(w, h)); }
protected void setValueInternal(Object value) { if (null == value) { super.setValueInternal(null); } else if (value instanceof CharSequence) { handleAsString(String.valueOf(value)); } else if (value instanceof List) { handleAsList((List) value); } else if (value instanceof Map) { handleAsMap((Map) value); } else if (value instanceof Number) { handleAsNumber((Number) value); } else if (value instanceof Dimension2D) { super.setValueInternal(value); } else { throw illegalValue(value, Dimension2D.class); } }
protected void handleAsList(List<?> list) { if (list.isEmpty()) { super.setValueInternal(null); return; } switch (list.size()) { case 1: double s = parseValue(list.get(0)); super.setValueInternal(new Dimension2D(s, s)); break; case 2: double w = parseValue(list.get(0)); double h = parseValue(list.get(1)); super.setValueInternal(new Dimension2D(w, h)); break; default: throw illegalValue(list, Dimension2D.class); } }
protected void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return; } String[] parts = str.split(","); switch (parts.length) { case 1: double s = parseValue(parts[0]); super.setValueInternal(new Dimension2D(s, s)); break; case 2: double w = parseValue(parts[0]); double h = parseValue(parts[1]); super.setValueInternal(new Dimension2D(w, h)); break; default: throw illegalValue(str, Dimension2D.class); } }
protected void handleAsNumber(Number value) { double s = parse(value); super.setValueInternal(new Dimension2D(s, s)); }