Android Open Source - Gui2Go In Memory Tree Node






From Project

Back to project page Gui2Go.

License

The source code is released under:

MIT License

If you think the Android project Gui2Go 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.ami.gui2go.tree;
//ww w  .  j av  a 2 s  . com
import java.util.LinkedList;
import java.util.List;

/**
 * Node. It is package protected so that it cannot be used outside.
 * 
 * @param <T>
 *            type of the identifier used by the tree
 */
class InMemoryTreeNode<T>
{
  private final T id;
  private final T parent;
  private final int level;
  private boolean visible = true;
  private final List<InMemoryTreeNode<T>> children = new LinkedList<InMemoryTreeNode<T>>();
  private List<T> childIdListCache = null;

  public InMemoryTreeNode(final T id, final T parent, final int level,
      final boolean visible)
  {
    super();
    this.id = id;
    this.parent = parent;
    this.level = level;
    this.visible = visible;
  }

  public int indexOf(final T id)
  {
    return getChildIdList().indexOf(id);
  }

  /**
   * Cache is built lasily only if needed. The cache is cleaned on any
   * structure change for that node!).
   * 
   * @return list of ids of children
   */
  public synchronized List<T> getChildIdList()
  {
    if (childIdListCache == null)
    {
      childIdListCache = new LinkedList<T>();
      for (final InMemoryTreeNode<T> n : children)
      {
        childIdListCache.add(n.getId());
      }
    }
    return childIdListCache;
  }

  public boolean isVisible()
  {
    return visible;
  }

  public void setVisible(final boolean visible)
  {
    this.visible = visible;
  }

  public int getChildrenListSize()
  {
    return children.size();
  }

  public synchronized InMemoryTreeNode<T> add(final int index, final T child,
      final boolean visible)
  {
    childIdListCache = null;
    // Note! top levell children are always visible (!)
    final InMemoryTreeNode<T> newNode = new InMemoryTreeNode<T>(child,
        getId(), getLevel() + 1, getId() == null ? true : visible);
    children.add(index, newNode);
    return newNode;
  }

  /**
   * Note. This method should technically return unmodifiable collection, but
   * for performance reason on small devices we do not do it.
   * 
   * @return children list
   */
  public List<InMemoryTreeNode<T>> getChildren()
  {
    return children;
  }

  public void clearChildren()
  {
    children.clear();
    childIdListCache = null;
  }

  public synchronized void removeChild(final T child)
  {
    final int childIndex = indexOf(child);
    if (childIndex != -1)
    {
      children.remove(childIndex);
      childIdListCache = null;
    }
  }

  @Override
  public String toString()
  {
    return "InMemoryTreeNode [id=" + getId() + ", parent=" + getParent()
        + ", level=" + getLevel() + ", visible=" + visible
        + ", children=" + children + ", childIdListCache="
        + childIdListCache + "]";
  }

  T getId()
  {
    return id;
  }

  T getParent()
  {
    return parent;
  }

  int getLevel()
  {
    return level;
  }

}




Java Source Code List

com.ami.gui2go.ActivityManager.java
com.ami.gui2go.EditorActivity.java
com.ami.gui2go.FileDialogFragment.java
com.ami.gui2go.GridViewItemClickListener.java
com.ami.gui2go.HomeActivity.java
com.ami.gui2go.LongClickListener.java
com.ami.gui2go.ProjectManagerActivity.java
com.ami.gui2go.ResourceManagerActivity.java
com.ami.gui2go.UserGuideActivity.java
com.ami.gui2go.models.ActivityInfo.java
com.ami.gui2go.models.ProjectInfo.java
com.ami.gui2go.models.WidgetAttribute.java
com.ami.gui2go.models.WidgetTypes.java
com.ami.gui2go.models.WidgetWrapper.java
com.ami.gui2go.models.Widget.java
com.ami.gui2go.tree.AbstractTreeViewAdapter.java
com.ami.gui2go.tree.InMemoryTreeNode.java
com.ami.gui2go.tree.InMemoryTreeStateManager.java
com.ami.gui2go.tree.NodeAlreadyInTreeException.java
com.ami.gui2go.tree.NodeNotInTreeException.java
com.ami.gui2go.tree.SimpleStandardAdapter.java
com.ami.gui2go.tree.TreeBuilder.java
com.ami.gui2go.tree.TreeConfigurationException.java
com.ami.gui2go.tree.TreeNodeInfo.java
com.ami.gui2go.tree.TreeStateManager.java
com.ami.gui2go.tree.TreeViewList.java
com.ami.gui2go.utils.FileHelper.java
com.ami.gui2go.utils.LayoutXMLCreator.java
com.ami.gui2go.utils.ProjectXMLParser.java
com.ami.gui2go.utils.TextValidator.java
com.ami.gui2go.views.ColorPickerDialog.java