com.sap.cloud.security.ams.dcl.client.el.ELInternalTools Maven / Gradle / Ivy
The newest version!
/************************************************************************
* © 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
************************************************************************/
package com.sap.cloud.security.ams.dcl.client.el;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
final class ELInternalTools {
static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
private ELInternalTools() {
}
//
//
static Object[] copyArguments(Object[] args) {
return args == null || args.length == 0 ? EMPTY_OBJECT_ARRAY : args.clone();
}
static Object[] copyArguments(Collection> args) {
return args == null || args.isEmpty() ? EMPTY_OBJECT_ARRAY : args.toArray();
}
static Object[] copyArguments(Object[] args, int start, int end) {
int size = end - start;
switch (size) {
case 0:
return EMPTY_OBJECT_ARRAY;
case 1:
return new Object[] { args[start] };
default:
return Arrays.copyOfRange(args, start, end, Object[].class);
}
}
//
//
//
static List createListWithOwnership(U[] list) {
if (list == null) {
return Collections.emptyList();
}
switch (list.length) {
case 0:
return Collections.emptyList();
case 1:
return Collections.singletonList(list[0]);
default:
return new UnmodifiableArrayList<>(list);
}
}
static List createFrom(U[] array, Collection list) {
if (list == null) {
return Collections.emptyList();
}
switch (list.size()) {
case 0:
return Collections.emptyList();
case 1:
return Collections.singletonList(list instanceof List ? ((List) list).get(0) : list.iterator().next());
default:
return new UnmodifiableArrayList<>(list.toArray(array));
}
}
}