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

xapi.collect.impl.IntToAbstract Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.collect.impl;

import java.util.Collection;
import java.util.Comparator;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import xapi.collect.api.CollectionOptions;
import xapi.collect.api.IntTo;
import xapi.collect.api.ObjectTo;
import xapi.collect.proxy.CollectionProxy;

public class IntToAbstract  implements IntTo {

  private final CollectionProxy store;
  private final CollectionOptions opts;
  private final Comparator comparator;

  public IntToAbstract(CollectionProxy store, CollectionOptions opts
    , Comparator comparator) {
    this.store = store;
    this.opts = opts;
    this.comparator = comparator;
  }

  @Override
  public Iterable forEach() {
    return new Iterable() {
      @Override
      public Iterator iterator() {
        return new IntToIterator(IntToAbstract.this);
      }
    };
  }
  @Override
  public int size() {
    return store.size();
  }

  @Override
  public V[] toArray() {
    return null;
  }

  @Override
  public boolean add(V item) {
    return store.put(newEntry(size(), item)) == null;
  }
  
  @Override
  public boolean insert(int pos, V item) {
    for (int i = store.size(); i --> 0; ) {
      V v = store.get(i);
      store.put(newEntry(i+1, v));
    }
    store.put(newEntry(pos, item));
    return true;
  }

  protected Entry newEntry(int size, V item) {
    return null;
  }

  public void push(V item) {
    store.put(newEntry(size(), item));
  }

  public V pop() {
    int size = size();
    if (size > 0) {
      try {
        return get(--size);
      }finally {
        remove(size);
      }
    }
    return null;
  }

  @Override
  public Collection toCollection(Collection into) {
    if (into == null) {

    }
    return null;
  }

  @Override
  public Map toMap(Map into) {
    if (into == null) {

    }
    return null;
  }

  @Override
  public ObjectTo clone(CollectionOptions options) {
    ObjectTo clone = null;
    return clone;
  }

  @Override
  public boolean contains(V value) {
    for (V val : forEach()) {
      if (comparator.compare(val, value)==0)
        return true;
    }
    return false;
  }

  @Override
  public V at(int index) {
    return store.get(index);
  }

  @Override
  public int indexOf(V value) {
    for (int i = 0, s = store.size(); i < s; i++) {
      if (comparator.compare(store.get(i), value)==0)
        return i;
    }
    return -1;
  }

  @Override
  public boolean remove(int index) {
    return store.remove(index) != null;
  }

  @Override
  public boolean findRemove(V value, boolean all) {
    boolean success = false;
    for (int i = 0, s = store.size(); i < s; i++) {
      if (comparator.compare(store.get(i), value)==0) {
        store.remove(i);
        s = store.size();
        i--;
        if (all)
          success=true;
        else
          return true;
      }
    }
    return success;
  }

  @Override
  public void set(int index, V value) {
    store.entryFor(index).setValue(value);
  }

  @Override
  public List asList() {
    return null;
  }

  @Override
  public Set asSet() {
    return null;
  }

  @Override
  public Deque asDeque() {
    return null;
  }

  @Override
  public V get(Object key) {
    return store.get(key);
  }

  public V put(int key, V value) {
    Entry entry = store.entryFor(key);
    V current = entry.getValue();
    entry.setValue(value);
    return current;
  }

  @Override
  public V put(Entry value) {
    return store.put(value);
  }

  @Override
  public V remove(Object key) {
    return store.remove(key);
  }

  @Override
  public boolean isEmpty() {
    return store.isEmpty();
  }

  @Override
  public void clear() {
    store.clear();
  }

  @Override
  public Entry entryFor(Object key) {
    return store.entryFor(key);
  }

  @SuppressWarnings("unchecked")
  @Override
  public void setValue(Object key, Object value) {
    if (key instanceof Number) {
      set(((Number)key).intValue(), (V)value);
    }
  }
  
  @Override
  public boolean addAll(Iterable items) {
    for (V item : items) {
      add(item);
    }
    return true;
  }
  
  @Override
  @SuppressWarnings("unchecked")
  public boolean addAll(V ... items) {
    for (V item : items) {
      add(item);
    }
    return true;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy