Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package javaemul.internal;
import static javaemul.internal.InternalPreconditions.checkCriticalArrayBounds;
import java.util.Comparator;
import javaemul.internal.annotations.DoNotAutobox;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
/** Provides utilities to perform operations on Arrays. */
public final class ArrayHelper {
public static final int ARRAY_PROCESS_BATCH_SIZE = 10000;
public static T clone(T array) {
Object result = asNativeArray(array).slice();
return ArrayStamper.stampJavaTypeInfo(JsUtils.uncheckedCast(result), array);
}
public static T clone(T array, int fromIndex, int toIndex) {
Object[] result = unsafeClone(array, fromIndex, toIndex);
// array.slice doesn't expand if toIndex > array.length
int length = result.length;
int requestedLength = toIndex - fromIndex;
if (requestedLength > length) {
Object initialValue = getElementInitialValue(array);
if (initialValue == null) {
setLength(result, requestedLength);
} else {
for (int i = length; i < requestedLength; ++i) {
result[i] = initialValue;
}
}
}
return ArrayStamper.stampJavaTypeInfo(JsUtils.uncheckedCast(result), array);
}
/**
* Unlike clone, this method returns a copy of the array that is not type marked, nor size
* guaranteed. This is only safe for temp arrays as returned array will not do any type checks.
*/
public static Object[] unsafeClone(Object array, int fromIndex, int toIndex) {
return asNativeArray(array).slice(fromIndex, toIndex);
}
public static T[] createFrom(T[] array, int length) {
return ArrayStamper.stampJavaTypeInfo(new NativeArray(length), array);
}
@JsMethod(name = "Array.isArray", namespace = JsPackage.GLOBAL)
public static native boolean isArray(Object o);
public static int getLength(Object array) {
return asNativeArray(array).length;
}
/** Sets the length of an array to particular size. */
public static T setLength(T array, int length) {
asNativeArray(array).length = length;
return array;
}
/**
* Resize the array to accommodate requested length. For JavaScript this is same as setting the
* length.
*/
public static T grow(T array, int length) {
return setLength(array, length);
}
public static void push(Object[] array, Object o) {
asNativeArray(array).push(o);
}
public static void fill(Object array, @DoNotAutobox Object value, int fromIndex, int toIndex) {
checkCriticalArrayBounds(fromIndex, toIndex, getLength(array));
asNativeArray(array).fill(value, fromIndex, toIndex);
}
public static void fill(Object array, @DoNotAutobox Object value) {
asNativeArray(array).fill(value);
}
public static void removeFrom(Object[] array, int index, int deleteCount) {
asNativeArray(array).splice(index, deleteCount);
}
public static void insertTo(Object[] array, int index, Object value) {
asNativeArray(array).splice(index, 0, value);
}
public static void copy(Object array, int srcOfs, Object dest, int destOfs, int len) {
copy(
JsUtils.