MCPcopy Index your code
hub / github.com/ccxt/ccxt / GetValue

Method GetValue

java/lib/src/main/java/io/github/ccxt/Helpers.java:530–584  ·  view source on GitHub ↗
(Object value2, Object key)

Source from the content-addressed store, hash-verified

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

Callers 15

loadOrderBookMethod · 0.95
setLastRequestMethod · 0.95
handleDeltasMethod · 0.95
handleDeltasWithKeysMethod · 0.95
arraysConcatMethod · 0.95
findTimeframeMethod · 0.95
findMessageHashesMethod · 0.95
filterByLimitMethod · 0.95
filterBySinceLimitMethod · 0.95
setSandboxModeMethod · 0.95
enableDemoTradingMethod · 0.95

Calls 6

toIntMethod · 0.95
lengthMethod · 0.45
isArrayMethod · 0.45
addMethod · 0.45
getMethod · 0.45
getMethodMethod · 0.45

Tested by 15

getValueMethod · 0.76
testFetchWithdrawalsMethod · 0.76
testFetchOrderBooksMethod · 0.76
testSignInMethod · 0.76
testLoadMarketsMethod · 0.76
testFetchLedgerMethod · 0.76
testTickerMethod · 0.76
testFetchOHLCVMethod · 0.76
testLedgerEntryMethod · 0.76
testCurrencyMethod · 0.76
testFetchLedgerEntryMethod · 0.76