View Javadoc
1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: ListVar.java,v 1.3 2003/03/05 04:31:57 michaelh Exp $ 20 */ 21 22 package juju.reattore.perfcap.var.impl; 23 24 import java.util.*; 25 26 import org.apache.commons.logging.*; 27 28 import juju.reattore.perfcap.var.Variable; 29 30 /*** Variable that combines the output from many sub variables. 31 32 @tag list 33 @group Variable 34 @children Variable 35 */ 36 public class ListVar 37 implements Variable { 38 39 private static Log log = LogFactory.getLog(ListVar.class); 40 41 private String name = "X"; 42 43 private List children = new ArrayList(); 44 private Iterator it; 45 private Variable current; 46 47 /*** Adds a new child to this list. 48 49 @param var The new child. 50 */ 51 public void addVariable(Variable var) { 52 children.add(var); 53 } 54 55 /*** The name to identify this variable. 56 57 @param name The name. 58 @default X 59 */ 60 public void setName(String name) { 61 this.name = name; 62 } 63 64 /*** @see Variable */ 65 public String getName() { 66 return name; 67 } 68 69 /*** @see Variable */ 70 public Object getValue() { 71 return current.getValue(); 72 } 73 74 /*** @see Variable */ 75 public boolean hasNext() 76 throws Exception { 77 78 while (current == null 79 || current.hasNext() == false) { 80 81 if (current != null) { 82 current.end(); 83 current = null; 84 } 85 86 if (it.hasNext() == false) { 87 return false; 88 } 89 90 current = (Variable)it.next(); 91 current.begin(); 92 } 93 94 return true; 95 } 96 97 /*** @see Variable */ 98 public void next() 99 throws Exception { 100 101 if (hasNext()) { 102 current.next(); 103 } 104 } 105 106 /*** @see Variable */ 107 public void begin() 108 throws Exception { 109 110 end(); 111 112 it = children.iterator(); 113 } 114 115 /*** @see Variable */ 116 public void end() 117 throws Exception { 118 119 if (current != null) { 120 current.end(); 121 current = null; 122 } 123 124 it = null; 125 } 126 }

This page was automatically generated by Maven