Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MeasurementSequence.java

Go to the documentation of this file.
00001 /*
00002  * MeasurementSequence.java
00003  *
00004  * Copyright (C) 2005 Project SQUID, http://www.cs.helsinki.fi/group/squid/
00005  *
00006  * This file is part of Ikayaki.
00007  *
00008  * Ikayaki is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Ikayaki is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Ikayaki; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021  */
00022 
00023 package ikayaki;
00024 
00025 import org.w3c.dom.Document;
00026 import org.w3c.dom.Element;
00027 import org.w3c.dom.NodeList;
00028 
00029 import java.util.ArrayList;
00030 import java.util.List;
00031 
00039 public class MeasurementSequence implements Comparable<MeasurementSequence> {
00040 
00044     private String name;
00045 
00049     private final List<MeasurementStep> steps = new ArrayList<MeasurementStep>();
00050 
00054     public MeasurementSequence() {
00055         setName("");
00056     }
00057 
00064     public MeasurementSequence(String name) {
00065         setName(name);
00066     }
00067 
00075     public MeasurementSequence(Element element) {
00076         this(element, null);
00077     }
00078 
00088     public MeasurementSequence(Element element, Project project) {
00089         if (element == null) {
00090             throw new NullPointerException();
00091         }
00092 
00093         // verify tag name
00094         if (!element.getTagName().equals("sequence")) {
00095             throw new IllegalArgumentException("Invalid tag name: " + element.getTagName());
00096         }
00097 
00098         // get name
00099         setName(element.getAttribute("name"));
00100 
00101         // get steps
00102         NodeList steps = element.getElementsByTagName("step");
00103         for (int i = 0; i < steps.getLength(); i++) {
00104             Element step = (Element) steps.item(i);
00105             this.steps.add(new MeasurementStep(step, project));
00106         }
00107     }
00108 
00114     public synchronized Element getElement(Document document) {
00115         Element element = document.createElement("sequence");
00116         element.setAttribute("name", name);
00117         for (MeasurementStep step : steps) {
00118             element.appendChild(step.getElement(document));
00119         }
00120         return element;
00121     }
00122 
00126     public synchronized String getName() {
00127         return name;
00128     }
00129 
00135     public synchronized void setName(String name) {
00136         if (name == null) {
00137             throw new NullPointerException();
00138         }
00139         this.name = name;
00140     }
00141 
00145     public synchronized int getSteps() {
00146         return steps.size();
00147     }
00148 
00156     public synchronized MeasurementStep getStep(int index) {
00157         return steps.get(index);
00158     }
00159 
00166     public synchronized void addStep(MeasurementStep step) {
00167         if (step == null) {
00168             throw new NullPointerException();
00169         }
00170         steps.add(step);
00171     }
00172 
00181     public synchronized void addStep(int index, MeasurementStep step) {
00182         if (step == null) {
00183             throw new NullPointerException();
00184         }
00185         steps.add(index, step);
00186     }
00187 
00194     public synchronized void removeStep(int index) {
00195         steps.remove(index);
00196     }
00197 
00205     public int compareTo(MeasurementSequence other) {
00206         int val = this.getName().compareTo(other.getName());
00207         if (val == 0) {
00208             return this.hashCode() - other.hashCode();
00209         } else {
00210             return val;
00211         }
00212     }
00213 
00214     @Override public String toString() {
00215         return getName();
00216     }
00217 }

Generated on Fri May 6 16:00:32 2005 for Squid by  doxygen 1.4.1