(Object a, Object key2)
| 308 | } |
| 309 | |
| 310 | public static Map<String, Object> indexBy(Object a, Object key2) { |
| 311 | Map<String, Object> out = new LinkedHashMap<>(); |
| 312 | List<Object> targetX; |
| 313 | |
| 314 | if (a instanceof List<?>) { |
| 315 | targetX = (List<Object>) a; |
| 316 | } else { |
| 317 | targetX = new ArrayList<>(((Map<String, Object>) a).values()); |
| 318 | } |
| 319 | |
| 320 | for (Object elem : targetX) { |
| 321 | if (elem instanceof Map<?, ?>) { |
| 322 | Map<String, Object> m = (Map<String, Object>) elem; |
| 323 | Object val = m.get((String) key2); |
| 324 | if (val == null) continue; |
| 325 | out.put(val.toString(), m); |
| 326 | } else if (elem instanceof List<?>) { |
| 327 | int index = Integer.parseInt(String.valueOf(key2)); |
| 328 | List<?> l = (List<?>) elem; |
| 329 | if (l.isEmpty()) continue; |
| 330 | if (index < 0 || index >= l.size()) continue; |
| 331 | Object val = l.get(index); |
| 332 | if (val == null) continue; |
| 333 | out.put(val.toString(), elem); |
| 334 | } |
| 335 | } |
| 336 | return out; |
| 337 | } |
| 338 | |
| 339 | // ---------- groupBy ---------- |
| 340 |
no test coverage detected