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

xapi.gwt.collect.JsFifo Maven / Gradle / Ivy

Go to download

This module exists solely to package all other gwt modules into a single uber jar. This makes deploying to non-mavenized targets much easier. Of course, you would be wise to inherit your dependencies individually; the uber jar is intended for projects like collide, which have complex configuration, and adding many jars would be a pain.

The newest version!
package xapi.gwt.collect;

import java.util.Iterator;

import xapi.collect.api.Fifo;

import com.google.gwt.core.client.JavaScriptObject;

public class JsFifo extends JavaScriptObject implements Fifo {

  protected JsFifo() {
  }

  public native static  Fifo newFifo()
  /*-{
    return [];
  }-*/;

  @Override
  public final native void clear()
  /*-{
    this.length = 0;
  }-*/;

  @Override
  public final boolean contains(E item) {
    for (E e : forEach()) {
      if (e.equals(item))
        return true;
    }
    return false;
  }

  @Override
  public final native Fifo give(E item)
  /*-{
    if (item !== null)
      this.push(item);
    return this;
  }-*/;
  
  @Override
  @SuppressWarnings("unchecked")
  public final native Fifo giveAll(E... elements)
  /*-{
    this.splice(this.length, elements);
    return this;
  }-*/;

  @Override
  public final Fifo giveAll(Iterable elements) {
    return null;
  }

  @Override
  public final native boolean isEmpty()
  /*-{
    return this.length==0;
  }-*/;

  @Override
  public final Iterator iterator() {
    return new JsArrayIterator(this);
  }

  @Override
  public final Iterable forEach() {
    class Itr implements Iterable {
      @Override
      public Iterator iterator() {
        return JsFifo.this.iterator();
      }
    }
    return new Itr();
  }

  @Override
  public final boolean remove(E item) {
    boolean removed = false;
    for (int i = size(); i-- > 0;) {
      if (equal(item, i)) {
        remove(i);
        removed = true;
      }
    }
    return removed;
  }

  @Override
  public final native int size()
  /*-{
    return this.length;
  }-*/;

  @Override
  public final native E take()
  /*-{
    return this.length==0?null:this.shift();
  }-*/;

  private final native void remove(int i)
  /*-{
    this.splice(i, 1);
  }-*/;

  private final native boolean equal(E item, int i)
  /*-{
    return this[i] === item;
  }-*/;

  public final native String join(String delim)
  /*-{
    return this.join(delim);
  }-*/;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy