@Test void processNumberParam(){ Map<String, Object> actual = new HashMap<>(); Map<String, Object> expected = new HashMap<String, Object>(){{ put("a", 10.0); put("b", 20L); }}; List<Map<String, Object>> params = Arrays.asList( value(10), value(20) ); SemanticUtils.processNumberParam(actual, "a", _N_DOUBLE(0), params); SemanticUtils.processNumberParam(actual, "b", _N_LONG(1), params); assertEquals(expected, actual); }
static boolean processNumberParam(Map<String, Object> map, String key, String value, List<Map<String, Object>> params){ Matcher m = PATTERN_PARAM.matcher(value); if(m.matches()){ int index = Integer.valueOf(m.group(1)); String numberType = m.group(2); Map<String, Object> param = params.get(index); if(numberType == null) subsume(map, params.get(index), key); else if(param.containsKey(KEY_UNNAMED) && param.get(KEY_UNNAMED) instanceof Number){ Number num = (Number)(param.get(KEY_UNNAMED)); if(numberType.equals("L")) map.put(key, num.longValue()); else if(numberType.equals("F")) map.put(key, num.doubleValue()); } return true; } return false; }
SemanticUtils { static boolean processNumberParam(Map<String, Object> map, String key, String value, List<Map<String, Object>> params){ Matcher m = PATTERN_PARAM.matcher(value); if(m.matches()){ int index = Integer.valueOf(m.group(1)); String numberType = m.group(2); Map<String, Object> param = params.get(index); if(numberType == null) subsume(map, params.get(index), key); else if(param.containsKey(KEY_UNNAMED) && param.get(KEY_UNNAMED) instanceof Number){ Number num = (Number)(param.get(KEY_UNNAMED)); if(numberType.equals("L")) map.put(key, num.longValue()); else if(numberType.equals("F")) map.put(key, num.doubleValue()); } return true; } return false; } }
SemanticUtils { static boolean processNumberParam(Map<String, Object> map, String key, String value, List<Map<String, Object>> params){ Matcher m = PATTERN_PARAM.matcher(value); if(m.matches()){ int index = Integer.valueOf(m.group(1)); String numberType = m.group(2); Map<String, Object> param = params.get(index); if(numberType == null) subsume(map, params.get(index), key); else if(param.containsKey(KEY_UNNAMED) && param.get(KEY_UNNAMED) instanceof Number){ Number num = (Number)(param.get(KEY_UNNAMED)); if(numberType.equals("L")) map.put(key, num.longValue()); else if(numberType.equals("F")) map.put(key, num.doubleValue()); } return true; } return false; }  }
SemanticUtils { static boolean processNumberParam(Map<String, Object> map, String key, String value, List<Map<String, Object>> params){ Matcher m = PATTERN_PARAM.matcher(value); if(m.matches()){ int index = Integer.valueOf(m.group(1)); String numberType = m.group(2); Map<String, Object> param = params.get(index); if(numberType == null) subsume(map, params.get(index), key); else if(param.containsKey(KEY_UNNAMED) && param.get(KEY_UNNAMED) instanceof Number){ Number num = (Number)(param.get(KEY_UNNAMED)); if(numberType.equals("L")) map.put(key, num.longValue()); else if(numberType.equals("F")) map.put(key, num.doubleValue()); } return true; } return false; }  static String _N(int item); static String _N_LONG(int item); static String _N_DOUBLE(int item); static ChainMap<String, Object> named(String name, Object value); static ChainMap<String, Object> value(Object value); static SemanticFunction valueFn(Object value); static List<Map<String, Object>> identity(List<Map<String, Object>> params); static List<Map<String, Object>> merge(List<Map<String, Object>> params); static List<Map<String, Object>> first(List<Map<String, Object>> params); static List<Map<String, Object>> last(List<Map<String, Object>> params); static SemanticFunction parseSemantics(String semantics); static SemanticFunction parseTemplate(Map<String, Object> template); }
SemanticUtils { static boolean processNumberParam(Map<String, Object> map, String key, String value, List<Map<String, Object>> params){ Matcher m = PATTERN_PARAM.matcher(value); if(m.matches()){ int index = Integer.valueOf(m.group(1)); String numberType = m.group(2); Map<String, Object> param = params.get(index); if(numberType == null) subsume(map, params.get(index), key); else if(param.containsKey(KEY_UNNAMED) && param.get(KEY_UNNAMED) instanceof Number){ Number num = (Number)(param.get(KEY_UNNAMED)); if(numberType.equals("L")) map.put(key, num.longValue()); else if(numberType.equals("F")) map.put(key, num.doubleValue()); } return true; } return false; }  static String _N(int item); static String _N_LONG(int item); static String _N_DOUBLE(int item); static ChainMap<String, Object> named(String name, Object value); static ChainMap<String, Object> value(Object value); static SemanticFunction valueFn(Object value); static List<Map<String, Object>> identity(List<Map<String, Object>> params); static List<Map<String, Object>> merge(List<Map<String, Object>> params); static List<Map<String, Object>> first(List<Map<String, Object>> params); static List<Map<String, Object>> last(List<Map<String, Object>> params); static SemanticFunction parseSemantics(String semantics); static SemanticFunction parseTemplate(Map<String, Object> template); final static String _IDENTITY; final static String _FIRST; final static String _LAST; final static String _MERGE; final static String _APPEND; final static String KEY_UNNAMED; }