Android Open Source - ingress-key-counter Abstract Encapsuled List






From Project

Back to project page ingress-key-counter.

License

The source code is released under:

MIT License

If you think the Android project ingress-key-counter 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 de.lehrbaum.keycounter;
/*from w w w .  j a  va  2s .  c  om*/
import java.util.AbstractList;
import java.util.List;

/**
 * A list class encapsulating a list and enabling subclasses to react to remove or add operations.
 */
public abstract class AbstractEncapsuledList<E> extends
  AbstractList<E> {
  protected List<E> internalList;
  
  protected DatabaseHandler dh;
  
  protected AbstractEncapsuledList(DatabaseHandler dh,
    List<E> elements) {
    this.dh = dh;
    internalList = elements;
  }
  
  @Override
  public void add(int location, E object) {
    internalList.add(location, object);
    onAdd(object);
  }
  
  @Override
  public E remove(int location) {
    E e = internalList.remove(location);
    onRemove(e);
    return e;
  }
  
  @Override
  public E set(int location, E object) {
    E e = internalList.set(location, object);
    onRemove(e);
    onAdd(object);
    return e;
  }
  
  @Override
  public boolean remove(Object object) {
    boolean b = false;
    try {
      //can't check because is generic
      @SuppressWarnings("unchecked")
      E e = (E) object;
      b = internalList.remove(e);
      onRemove(e);
    } catch (ClassCastException e) {}
    return b;
  }
  
  /**
   * Called if an item is added to the list.
   * 
   * @param item The item added to the List.
   */
  protected abstract void onAdd(E item);
  
  /**
   * Called if an item is removed from the list.
   * 
   * @param item The item removed from the list.
   */
  protected abstract void onRemove(E item);
  
  @Override
  public E get(int location) {
    return internalList.get(location);
  }
  
  @Override
  public int size() {
    return internalList.size();
  }
}




Java Source Code List

de.lehrbaum.keycounter.AbstractEncapsuledList.java
de.lehrbaum.keycounter.CategoriesFragment.java
de.lehrbaum.keycounter.Category.java
de.lehrbaum.keycounter.CounterListAdapter.java
de.lehrbaum.keycounter.DatabaseHandler.java
de.lehrbaum.keycounter.MainActivity.java
de.lehrbaum.keycounter.MainFragment.java
de.lehrbaum.keycounter.PortalList.java
de.lehrbaum.keycounter.PortalView.java
de.lehrbaum.keycounter.Portal.java