Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$URL: https://source.sakaiproject.org/svn/jsf/tags/sakai-10.0/jsf-widgets/src/java/org/sakaiproject/jsf/model/TreeLevel.java $ $Id: TreeLevel.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $ Copyright (c) 2003, 2004, 2005, 2006, 2008 The Sakai Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.sakaiproject.jsf.model;
 
 import java.util.List;
 import java.util.*;
 
 public class TreeLevel
 {
   private TreeLevel parent = null;
   private ArrayList childList;
   private int index;
   boolean child;


  
"Parent" constructor. This is a top level and is its own parent and is a child of none.
 
   public TreeLevel(int index)
   {
     this. = new ArrayList();
     this. = this;
     this. = index;
     this. = false;
   }

  
No-arg constructor. "Parent" constructor equivalent, with index set to 0.
 
   public TreeLevel()
    {
      this. = new ArrayList();
      this. = this;
      this. = 0;
      this. = false;
    }

   
"Child" constructor. Create a child of "parent".

Parameters:
parent TreeLevel
 
    public TreeLevel(TreeLevel parent)
   {
     this. = new ArrayList();
     this. = parent;
     this. = parent.addChild(this);
     this. = true;
   }

  
Get parent, or self if no parent.

Returns:
TreeLevel
 
   public TreeLevel getParent()
   {
     return ;
   }

  
Get list of all child TreeLevels

Returns:
List
 
   public List getChildren()
   {
     return ;
   }

  
True if this has a parent.

Returns:
boolean
 
   public boolean isChild()
   {
     return ;
   }

  
String representing 0-indexed parent-child relationships. Example: 18_9_4 is the fourth child of the nineth child of 18

Returns:
String
  public String toString()
  {
    // recurse for children, done if parent
    if (this.isChild())
    {
      return this.getParent().toString() + "_" + ;
    }
    else
    {
      return "" + ;
    }
  }

  
Utility reciprocal method to add a child when it chooses this as its parent.

Parameters:
child TreeLevel
Returns:
int
  protected int addChild(TreeLevel child)
  {
    .add(child);
    return .size();
  }

  
test code, demonstrates usage.

Parameters:
args String[]
  public static void main(String[] args) {
    ..println("testing flat");
    ArrayList treeList = new ArrayList();
    for (int i = 0; i < 10; i++)
    {
      treeList.add(new TreeLevel(i));
    }
    for (Iterator iter = treeList.iterator(); iter.hasNext(); ) {
      Object item = (Object)iter.next();
      ..println("LEVEL: " + item);
    }
      ..println("testing hierarchy");
      treeList = new ArrayList();
      TreeLevel t0 = new TreeLevel(0);
      treeList.add(t0);
      for (int i = 0; i < 10; i++)
      {
        TreeLevel t1 = new TreeLevel(t0);
        treeList.add(t1);
        for (int j = 0; j < 5; j++) {
          TreeLevel t2 = new TreeLevel(t1);
          treeList.add(t2);
        }
      }
      for (Iterator iter = treeList.iterator(); iter.hasNext(); )
      {
        Object item = (Objectiter.next();
        ..println("LEVEL: " + item);
      }
    }
New to GrepCode? Check out our FAQ X