| 528 | public Object getValue(Object a, Object b) { return GetValue(a, b); } |
| 529 | |
| 530 | public static Object GetValue(Object value2, Object key) { |
| 531 | if (value2 == null || key == null) return null; |
| 532 | |
| 533 | // Strings: index access |
| 534 | if (value2 instanceof String) { |
| 535 | String str = (String) value2; |
| 536 | // check if key is int |
| 537 | if (!(key instanceof Long) && !(key instanceof Integer) && !(key instanceof Double)) { |
| 538 | return null; |
| 539 | } |
| 540 | int idx = toInt(key); |
| 541 | if (idx < 0 || idx >= str.length()) return null; |
| 542 | return String.valueOf(str.charAt(idx)); |
| 543 | } |
| 544 | |
| 545 | Object value = value2; |
| 546 | if (value2.getClass().isArray()) { |
| 547 | // Convert to List<Object> |
| 548 | int len = Array.getLength(value2); |
| 549 | List<Object> list = new ArrayList<>(len); |
| 550 | for (int i = 0; i < len; i++) list.add(Array.get(value2, i)); |
| 551 | value = list; |
| 552 | } |
| 553 | |
| 554 | if (value instanceof Map) { |
| 555 | Map<String, Object> m = (Map<String, Object>) value; |
| 556 | if (key instanceof String && m.containsKey(key)) { |
| 557 | return m.get(key); |
| 558 | } |
| 559 | return null; |
| 560 | } else if (value instanceof List) { |
| 561 | int idx = toInt(key); |
| 562 | List<?> list = (List<?>) value; |
| 563 | if (idx < 0 || idx >= list.size()) return null; |
| 564 | return list.get(idx); |
| 565 | } else if (key instanceof String) { |
| 566 | // Try Java field or getter |
| 567 | String name = (String) key; |
| 568 | try { |
| 569 | // Field |
| 570 | Field f = value.getClass().getField(name); |
| 571 | f.setAccessible(true); |
| 572 | return f.get(value2); |
| 573 | } catch (Exception ignored) {} |
| 574 | try { |
| 575 | // Getter |
| 576 | String mName = "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1); |
| 577 | Method m = value.getClass().getMethod(mName); |
| 578 | return m.invoke(value2); |
| 579 | } catch (Exception ignored) {} |
| 580 | return null; |
| 581 | } else { |
| 582 | return null; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | public static CompletableFuture<List<Object>> promiseAll(Object promisesObj) { return PromiseAll(promisesObj); } |
| 587 | |