Android Open Source - TreeFrogEngine Ragged Dictionary






From Project

Back to project page TreeFrogEngine.

License

The source code is released under:

MIT License

If you think the Android project TreeFrogEngine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.discretesoftworks.framework;
//from w  w  w.  j  a  v  a 2s  .c  o m
import java.util.ArrayList;

// A Dictionary where all values are arrays.
public class RaggedDictionary<T extends Comparable<T>,E>{
  
  private ArrayList<Pair<T,ArrayList<E>>> data;
  private ArrayList<E> compiledData;
  
  public static final byte LEFT_TO_RIGHT = 1;
  public static final byte RIGHT_TO_LEFT = 2;
  
  private int sorting;

  
  public RaggedDictionary(byte sorting){
    data = new ArrayList<Pair<T,ArrayList<E>>>();
    compiledData = new ArrayList<E>();
    this.sorting = sorting;
  }
  
  public void clear(){
    data = new ArrayList<Pair<T,ArrayList<E>>>();
    compiledData = new ArrayList<E>();
  }
  
  public void add(T key, E value){
    int k = indexOf(key);
    if (k < 0){
      int i = 0;
      for (i = 0; i < data.size(); i++){
        if (sorting == LEFT_TO_RIGHT)
          if (key.compareTo(data.get(i).a) < 0){
            break;
          }
        else
          if (key.compareTo(data.get(i).a) > 0){
            i++;
            break;
          }
      }
      data.add(i, new Pair<T, ArrayList<E>>(key, new ArrayList<E>()));
      k = i;
    }
    data.get(k).b.add(0,value);
    compileData();
  }
  
  public void move(E value, T key){
    removeAll(value);
    add(key,value);
  }
  
  public boolean removeAll(E value){
    boolean found = false;
    for (int i = 0; i < data.size(); i++){
      boolean f = data.get(i).b.remove(value);
      if (f)
        found = true;
    }
    compiledData.remove(value);
    return found;
  }
  
  public int indexOf(T key){
    for (int i = 0; i < data.size(); i++)
      if (data.get(i).a == key)
        return i;
    return -1;
  }
  
  public Pair<T,ArrayList<E>> find(T key){
    for (int i = 0; i < data.size(); i++)
      if (data.get(i).a == key)
        return data.get(i);
    return null;
  }
  
  public void compileData(){
    compiledData.clear();
    for (int i = 0; i < data.size(); i++){
      for (E e : data.get(i).b)
        compiledData.add(e);
    }
  }
  
  public ArrayList<E> getCompiledData(){
    return compiledData;
  }
  
}




Java Source Code List

com.discretesoftworks.OUYAframework.OuyaGameController.java
com.discretesoftworks.OUYAframework.OuyaGame.java
com.discretesoftworks.TestGame.Floor.java
com.discretesoftworks.TestGame.Player.java
com.discretesoftworks.TestGame.Pointer.java
com.discretesoftworks.TestGame.TestController.java
com.discretesoftworks.TestGame.TestGame.java
com.discretesoftworks.framework.AndroidGame.java
com.discretesoftworks.framework.Assets.java
com.discretesoftworks.framework.Directional.java
com.discretesoftworks.framework.GameController.java
com.discretesoftworks.framework.GameFont.java
com.discretesoftworks.framework.GameObject.java
com.discretesoftworks.framework.GameRenderer.java
com.discretesoftworks.framework.GriddedObject.java
com.discretesoftworks.framework.ModelLoader.java
com.discretesoftworks.framework.MovingObject.java
com.discretesoftworks.framework.MyGLRenderer.java
com.discretesoftworks.framework.MyGLSurfaceView.java
com.discretesoftworks.framework.NumericalMatrix.java
com.discretesoftworks.framework.Pair.java
com.discretesoftworks.framework.Path.java
com.discretesoftworks.framework.Pool.java
com.discretesoftworks.framework.RaggedDictionary.java
com.discretesoftworks.framework.RenderModel.java
com.discretesoftworks.framework.Sprite.java
com.discretesoftworks.framework.Terrain.java
com.discretesoftworks.framework.TextDisplay.java
com.discretesoftworks.framework.TextHolder.java
com.discretesoftworks.framework.View.java
com.discretesoftworks.networking.NetworkGameController.java
com.discretesoftworks.networking.Writer.java