MCPcopy
hub / github.com/ccxt/ccxt / arraySlice

Method arraySlice

java/lib/src/main/java/io/github/ccxt/Exchange.java:1257–1329  ·  view source on GitHub ↗
(Object array, Object first, Object second)

Source from the content-addressed store, hash-verified

1255 }
1256
1257 public Object arraySlice(Object array, Object first, Object second) {
1258 int firstInt = toInt(first);
1259
1260 // ----- byte[] case -----
1261 if (array instanceof byte[]) {
1262 byte[] byteArray = (byte[]) array;
1263
1264 if (second == null) {
1265 // handle negative first
1266 int index = firstInt;
1267 if (firstInt < 0) {
1268 index = byteArray.length + firstInt;
1269 if (index < 0) {
1270 index = 0;
1271 }
1272 }
1273 // slice [index..end) and return as List<Byte>
1274 List<Byte> result = new ArrayList<>(byteArray.length - index);
1275 for (int i = index; i < byteArray.length; i++) {
1276 result.add(byteArray[i]);
1277 }
1278 return result;
1279 } else {
1280 int secondInt = toInt(second);
1281 // slice [firstInt..secondInt) and return as List<Byte>
1282 int from = firstInt;
1283 int to = secondInt;
1284 if (from < 0 || to < from || to > byteArray.length) {
1285 throw new IndexOutOfBoundsException(
1286 "Invalid slice range: " + from + ".." + to + " for length " + byteArray.length
1287 );
1288 }
1289 List<Byte> result = new ArrayList<>(to - from);
1290 for (int i = from; i < to; i++) {
1291 result.add(byteArray[i]);
1292 }
1293 return result;
1294 }
1295 }
1296
1297 // ----- List<?> case -----
1298 if (!(array instanceof List<?>)) {
1299 throw new IllegalArgumentException("array must be byte[] or List, got: " + array.getClass());
1300 }
1301
1302 // ArrayCache mutates from the WS thread. subList captures modCount
1303 // non-atomically — under JMM that read can be stale, so the wrapping
1304 // `new ArrayList<>(view)` silently null-pads or skips CME. Materialize
1305 // a stable copy under the cache monitor first.
1306 if (array instanceof io.github.ccxt.ws.ArrayCache cache) {
1307 array = cache.snapshot();
1308 }
1309
1310 List<?> parsedArray = (List<?>) array;
1311
1312 if (second == null) {
1313 if (firstInt < 0) {
1314 int index = parsedArray.size() + firstInt;

Callers 10

filterByLimitMethod · 0.95
filterBySinceLimitMethod · 0.95
fetchOrderBookMethod · 0.45
signMethod · 0.45
parseCurrencyMethod · 0.45
parseTransactionMethod · 0.45
createAuthTokenMethod · 0.45
signMessageMethod · 0.45
watchPrivateMethod · 0.45

Calls 3

toIntMethod · 0.95
addMethod · 0.45
snapshotMethod · 0.45

Tested by

no test coverage detected