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

fr.lteconsulting.angular2gwt.client.JsArray Maven / Gradle / Ivy

There is a newer version: 1.8
Show newest version
package fr.lteconsulting.angular2gwt.client;

import java.util.Iterator;
import java.util.List;

import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

/**
 * Class to work with Javascript arrays.
 * 
 * 

* Gives to methods to convert between this and Java arrays. * *

* TODOimplement {@link List} */ @JsType( isNative = true, namespace = JsPackage.GLOBAL, name = "Array" ) public class JsArray { @JsOverlay @SafeVarargs public final static JsArray of( T... array ) { JsArray result = new JsArray<>(); for( T item : array ) result.push( item ); return result; } @JsOverlay public final static JsArray empty() { return new JsArray(); } @JsMethod public native void push( T item ); @JsProperty( name = "length" ) public native int length(); @JsMethod public native JsArray slice( int start, int end ); @JsMethod public native String join(); @JsMethod public native String join( String joiner ); @JsMethod public native int indexOf( T item ); @JsMethod public native void splice( int start, int length ); @JsMethod public native JsArray slice( int start ); @JsMethod public native T find( JsPredicate predicate ); @JsMethod public native JsArray filter( JsPredicate predicate ); @JsOverlay public final T get( int index ) { return JsTools.get( this, index ); } @JsOverlay public final void set( int index, T value ) { JsTools.set( this, index, value ); } @JsOverlay public final Iterable iterate() { return new Iterable() { @Override public Iterator iterator() { return new Iterator() { int index = 0; @Override public boolean hasNext() { return index < length(); } @Override public T next() { T result = get( index ); index++; return result; } @Override public void remove() { throw new RuntimeException(); } }; } }; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy