001: /*
002: * <copyright>
003: *
004: * Copyright 2000-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.csmart.experiment;
028:
029: import org.cougaar.tools.csmart.core.property.ModifiableConfigurableComponent;
030: import org.cougaar.tools.csmart.ui.viewer.CSMART;
031: import org.cougaar.util.log.Logger;
032:
033: import java.io.Serializable;
034: import java.util.ArrayList;
035:
036: /**
037: * A trial represents a run of an Experiment. In future it
038: * may represent a particular configuration variation.
039: * Currently it is a holder for TrialResults.
040: **/
041: public class Trial extends ModifiableConfigurableComponent implements
042: Serializable {
043: private static final String DESCRIPTION_PROPERTY = "description";
044: private static final String RESULTS_PROPERTY = "results";
045: private ArrayList trialResults; // array of TrialResult
046:
047: private boolean editable = false;
048:
049: private transient Logger log;
050:
051: /**
052: * Construct a trial with the given name.
053: * @param name
054: */
055: public Trial(String name) {
056: super (name);
057: trialResults = new ArrayList();
058: createLogger();
059: }
060:
061: private void createLogger() {
062: log = CSMART.createLogger(this .getClass().getName());
063: }
064:
065: public void initProperties() {
066: addProperty(DESCRIPTION_PROPERTY, "");
067: addProperty(RESULTS_PROPERTY, trialResults);
068: }
069:
070: /**
071: * Note that name is inherited from ConfigurableComponent,
072: * so there is no need for get name methods here.
073: */
074:
075: /**
076: * Set a text description for this trial.
077: * @param description description of the trial
078: */
079: public void setTextDescription(String description) {
080: getProperty(DESCRIPTION_PROPERTY).setValue(description);
081: }
082:
083: /**
084: * Get the text description of this trial.
085: * @return description of the trial
086: */
087: public String getTextDescription() {
088: return (String) getProperty(DESCRIPTION_PROPERTY).getValue();
089: }
090:
091: /**
092: * Get results of all runs of this trial.
093: * @return array of trial results (timestamp and results location)
094: */
095: public TrialResult[] getTrialResults() {
096: return (TrialResult[]) trialResults
097: .toArray(new TrialResult[trialResults.size()]);
098: }
099:
100: /**
101: * Add result of one run of this trial.
102: * @param result timestamp (when trial was run) and results location
103: */
104: public void addTrialResult(TrialResult result) {
105: trialResults.add(result);
106: getProperty(RESULTS_PROPERTY).setValue(trialResults);
107: }
108:
109: public void removeTrialResult(TrialResult result) {
110: trialResults.remove(result);
111: getProperty(RESULTS_PROPERTY).setValue(trialResults);
112: }
113:
114: public boolean isEditable() {
115: return this .editable;
116: }
117:
118: public void setEditable(boolean editable) {
119: this.editable = editable;
120: }
121: }
|