All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elemental2.core.JsArray Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2018 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 elemental2.core;

import javaemul.internal.ArrayStamper;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
import jsinterop.base.Js;
import jsinterop.base.JsArrayLike;

@JsType(isNative = true, name = "Array", namespace = JsPackage.GLOBAL)
public class JsArray implements JsIterable, ReadonlyArray, JsArrayLike {
  @JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
  public interface FromArrayLikeUnionType {
    @JsOverlay
    static JsArray.FromArrayLikeUnionType of(Object o) {
      return Js.cast(o);
    }

    @JsOverlay
    default JsArrayLike asJsArrayLike() {
      return Js.cast(this);
    }

    @JsOverlay
    default JsIterable asJsIterable() {
      return Js.cast(this);
    }

    @JsOverlay
    default String asString() {
      return Js.asString(this);
    }

    @JsOverlay
    default boolean isString() {
      return (Object) this instanceof String;
    }
  }

  @JsFunction
  public interface FromMapFn {
    @JsType(isNative = true, name = "?", namespace = JsPackage.GLOBAL)
    public interface P0UnionType {
      @JsOverlay
      static JsArray.FromMapFn.P0UnionType of(Object o) {
        return Js.cast(o);
      }

      @JsOverlay
      default String asString() {
        return Js.asString(this);
      }

      @JsOverlay
      default T asT() {
        return Js.cast(this);
      }

      @JsOverlay
      default boolean isString() {
        return (Object) this instanceof String;
      }
    }

    R onInvoke(JsArray.FromMapFn.P0UnionType p0, int p1);

    @JsOverlay
    default R onInvoke(String p0, int p1) {
      return onInvoke(Js.>uncheckedCast(p0), p1);
    }

    @JsOverlay
    default R onInvoke(T p0, int p1) {
      return onInvoke(Js.>uncheckedCast(p0), p1);
    }
  }

  @JsFunction
  public interface SortCompareFn {
    double onInvoke(T p0, T p1);
  }

  @JsOverlay
  public static final  JsArray asJsArray(T[] array) {
    return Js.uncheckedCast(array);
  }

  public static native  JsArray from(
      JsArray.FromArrayLikeUnionType arrayLike,
      JsArray.FromMapFn mapFn,
      S this_);

  public static native  JsArray from(
      JsArray.FromArrayLikeUnionType arrayLike, JsArray.FromMapFn mapFn);

  public static native  JsArray from(JsArray.FromArrayLikeUnionType arrayLike);

  @JsOverlay
  public static final  JsArray from(
      JsArrayLike arrayLike, JsArray.FromMapFn mapFn, S this_) {
    return from(Js.>uncheckedCast(arrayLike), mapFn, this_);
  }

  @JsOverlay
  public static final  JsArray from(
      JsArrayLike arrayLike, JsArray.FromMapFn mapFn) {
    return from(Js.>uncheckedCast(arrayLike), mapFn);
  }

  @JsOverlay
  public static final  JsArray from(JsArrayLike arrayLike) {
    return from(Js.>uncheckedCast(arrayLike));
  }

  @JsOverlay
  public static final  JsArray from(
      JsIterable arrayLike, JsArray.FromMapFn mapFn, S this_) {
    return from(Js.>uncheckedCast(arrayLike), mapFn, this_);
  }

  @JsOverlay
  public static final  JsArray from(
      JsIterable arrayLike, JsArray.FromMapFn mapFn) {
    return from(Js.>uncheckedCast(arrayLike), mapFn);
  }

  @JsOverlay
  public static final  JsArray from(JsIterable arrayLike) {
    return from(Js.>uncheckedCast(arrayLike));
  }

  @JsOverlay
  public static final  JsArray from(
      String arrayLike, JsArray.FromMapFn mapFn, S this_) {
    return from(Js.>uncheckedCast(arrayLike), mapFn, this_);
  }

  @JsOverlay
  public static final  JsArray from(
      String arrayLike, JsArray.FromMapFn mapFn) {
    return from(Js.>uncheckedCast(arrayLike), mapFn);
  }

  @JsOverlay
  public static final  JsArray from(String arrayLike) {
    return from(Js.>uncheckedCast(arrayLike));
  }

  @JsOverlay
  public static final  JsArray from(
      T[] arrayLike, JsArray.FromMapFn mapFn, S this_) {
    return from(Js.>uncheckedCast(arrayLike), mapFn, this_);
  }

  @JsOverlay
  public static final  JsArray from(
      T[] arrayLike, JsArray.FromMapFn mapFn) {
    return from(Js.>uncheckedCast(arrayLike), mapFn);
  }

  @JsOverlay
  public static final  JsArray from(T[] arrayLike) {
    return from(Js.>uncheckedCast(arrayLike));
  }

  public static native boolean isArray(Object arr);

  public static native  JsArray of(T... var_args);

  public int index;
  public String input;
  public int length;

  public JsArray(T... items) {}

  @JsOverlay
  public final T[] asArray(T[] reference) {
    return ArrayStamper.stampJavaTypeInfo(this, reference);
  }

  public native T at(int index);

  public native JsArray concat(T... items);

  public native JsArray copyWithin(int target, int start, int end);

  public native JsArray copyWithin(int target, int start);

  public native JsIteratorIterable<
          JsArray>>
      entries();

  public native  boolean every(ReadonlyArray.EveryCallbackFn callback, S thisobj);

  public native boolean every(ReadonlyArray.EveryCallbackFn callback);

  public native JsArray fill(T value, int begin, int end);

  public native JsArray fill(T value, int begin);

  public native JsArray fill(T value);

  public native  JsArray filter(
      ReadonlyArray.FilterCallbackFn callback, S thisobj);

  public native JsArray filter(ReadonlyArray.FilterCallbackFn callback);

  public native  T find(ReadonlyArray.FindPredicateFn predicateFn, S this_);

  public native T find(ReadonlyArray.FindPredicateFn predicateFn);

  public native  int findIndex(ReadonlyArray.FindIndexPredicateFn predicateFn, S this_);

  public native int findIndex(ReadonlyArray.FindIndexPredicateFn predicateFn);

  public native  T findLast(ReadonlyArray.FindLastPredicateFn predicateFn, S this_);

  public native T findLast(ReadonlyArray.FindLastPredicateFn predicateFn);

  public native  int findLastIndex(
      ReadonlyArray.FindLastIndexPredicateFn predicateFn, S this_);

  public native int findLastIndex(ReadonlyArray.FindLastIndexPredicateFn predicateFn);

  public native  JsArray flat();

  public native  JsArray flat(int depth);

  public native  JsArray flatMap(
      ReadonlyArray.FlatMapCallbackFn callback, THIS thisArg);

  public native  JsArray flatMap(ReadonlyArray.FlatMapCallbackFn callback);

  public native  void forEach(ReadonlyArray.ForEachCallbackFn callback, S thisobj);

  public native void forEach(ReadonlyArray.ForEachCallbackFn callback);

  public native boolean includes(T searchElement, int fromIndex);

  public native boolean includes(T searchElement);

  public native int indexOf(T obj, int fromIndex);

  public native int indexOf(T obj);

  public native String join();

  public native String join(Object separator);

  public native JsIteratorIterable keys();

  public native int lastIndexOf(T obj, int fromIndex);

  public native int lastIndexOf(T obj);

  public native  JsArray map(
      ReadonlyArray.MapCallbackFn callback, S thisobj);

  public native  JsArray map(ReadonlyArray.MapCallbackFn callback);

  public native T pop();

  public native int push(T... var_args);

  public native  R reduce(
      ReadonlyArray.ReduceCallbackFn callback, Object initialValue);

  public native  R reduce(ReadonlyArray.ReduceCallbackFn callback);

  public native  R reduceRight(
      ReadonlyArray.ReduceRightCallbackFn callback, Object initialValue);

  public native  R reduceRight(
      ReadonlyArray.ReduceRightCallbackFn callback);

  public native T[] reverse();

  public native T shift();

  public native JsArray slice();

  public native JsArray slice(int begin, int end);

  public native JsArray slice(int begin);

  public native  boolean some(ReadonlyArray.SomeCallbackFn callback, S thisobj);

  public native boolean some(ReadonlyArray.SomeCallbackFn callback);

  public native JsArray sort();

  public native JsArray sort(JsArray.SortCompareFn compareFn);

  public native JsArray splice();

  public native JsArray splice(int index, int howMany, T... var_args);

  public native JsArray splice(int index);

  public native String toSource();

  @JsMethod(name = "toString")
  public native String toString_();

  public native int unshift(T... items);

  public native JsIteratorIterable values();
}