teichmann@5835: package org.dive4elements.river.client.shared.model; ingo@12: ingo@1279: import java.util.List; ingo@1279: teichmann@5835: import org.dive4elements.river.client.shared.DoubleUtils; ingo@1279: ingo@12: ingo@12: /** ingo@12: * The default implementation of an {@link ArtifactDescription}. This class just ingo@12: * implements constructors to create new instances and the necessary methods of ingo@12: * the interface. ingo@12: * ingo@12: * @author Ingo Weinzierl ingo@12: */ ingo@12: public class DefaultArtifactDescription implements ArtifactDescription { ingo@12: ingo@12: /** Data that have been inserted in former states.*/ ingo@51: protected DataList[] oldData; ingo@12: ingo@12: /** The Data that is allowed to be inserted in the current state.*/ ingo@51: protected DataList currentData; ingo@12: ingo@12: /** The current state name.*/ ingo@12: protected String currentState; ingo@12: ingo@12: /** The names of reachable states.*/ ingo@12: protected String[] reachableStates; ingo@12: ingo@64: /** The output modes of this state.*/ ingo@64: protected OutputMode[] outputModes; ingo@64: ingo@807: /** A list of recommendations suggested by the server.*/ ingo@807: protected Recommendation[] recommendations; ingo@803: ingo@12: ingo@12: public DefaultArtifactDescription() { ingo@12: } ingo@12: ingo@12: ingo@12: /** ingo@12: * The default constructor. ingo@12: * ingo@12: * @param old The data that have been inserted in former states. ingo@12: * @param current The data that might be inserted in the current state. ingo@12: * @param state The name of the current state. ingo@12: * @param reachableStates The names of the reachable states. ingo@12: */ ingo@12: public DefaultArtifactDescription( ingo@64: DataList[] old, ingo@64: DataList current, ingo@64: String state, ingo@64: String[] reachableStates) ingo@12: { ingo@12: this.oldData = old; ingo@12: this.currentData = current; ingo@12: this.currentState = state; ingo@12: this.reachableStates = reachableStates; ingo@12: } ingo@12: ingo@12: ingo@64: /** ingo@64: * The default constructor. ingo@64: * ingo@64: * @param old The data that have been inserted in former states. ingo@64: * @param current The data that might be inserted in the current state. ingo@64: * @param state The name of the current state. ingo@64: * @param reachableStates The names of the reachable states. ingo@64: * @param outputModes The available output modes of this artifact. ingo@64: */ ingo@64: public DefaultArtifactDescription( ingo@807: DataList[] old, ingo@807: DataList current, ingo@807: String state, ingo@807: String[] reachableStates, ingo@807: OutputMode[] outputModes, ingo@807: Recommendation[] recommendations) ingo@64: { ingo@64: this(old, current, state, reachableStates); ingo@807: this.outputModes = outputModes; ingo@807: this.recommendations = recommendations; ingo@64: } ingo@64: ingo@64: ingo@51: public DataList[] getOldData() { ingo@12: return oldData; ingo@12: } ingo@12: ingo@12: ingo@51: public DataList getCurrentData() { ingo@12: return currentData; ingo@12: } ingo@12: ingo@12: ingo@12: public String getCurrentState() { ingo@12: return currentState; ingo@12: } ingo@12: ingo@12: ingo@12: public String[] getReachableStates() { ingo@12: return reachableStates; ingo@12: } ingo@64: ingo@64: ingo@64: public OutputMode[] getOutputModes() { ingo@64: return outputModes; ingo@64: } ingo@803: ingo@803: ingo@807: public Recommendation[] getRecommendations() { ingo@807: return recommendations; ingo@803: } ingo@1279: ingo@1279: ingo@1279: public String getRiver() { ingo@2467: return getDataValueAsString("river"); ingo@1279: } ingo@1279: ingo@1279: felix@3383: /** Get [min,max] of data items. */ ingo@1279: public double[] getKMRange() { ingo@1279: Double[] mm = new Double[2]; ingo@1279: ingo@1279: for (DataList list: oldData) { ingo@1279: List dataList = list.getAll(); ingo@1279: ingo@1279: for (Data data: dataList) { ingo@1279: String dataName = data.getLabel(); ingo@1279: DataItem item = data.getItems()[0]; ingo@1279: felix@3383: if (dataName.equals("ld_from") || dataName.equals("from")) { ingo@1279: Double d = DoubleUtils.getDouble(item.getStringValue()); ingo@1279: ingo@1279: if (d != null) { ingo@1279: mm[0] = d; ingo@1279: } ingo@1279: } felix@3383: else if (dataName.equals("ld_to") || dataName.equals("to")) { ingo@1279: Double d = DoubleUtils.getDouble(item.getStringValue()); ingo@1279: ingo@1279: if (d != null) { ingo@1279: mm[1] = d; ingo@1279: } ingo@1279: } ingo@1279: else if (dataName.equals("ld_locations")) { ingo@1279: return DoubleUtils.getMinMax(item.getStringValue()); ingo@1279: } ingo@1279: } ingo@1279: ingo@1279: if (mm[0] != null && mm[1] != null) { ingo@1279: return new double[] { mm[0], mm[1] }; ingo@1279: } ingo@1279: } ingo@1279: ingo@1279: return null; ingo@1279: } ingo@2467: ingo@2467: ingo@2467: public String getReferenceGauge() { ingo@2467: return getDataValueAsString("reference_gauge"); ingo@2467: } ingo@2467: ingo@2467: ingo@2467: public String getDataValueAsString(String name) { ingo@3719: if (oldData == null) { ingo@3719: return null; ingo@3719: } ingo@2467: for (DataList list: oldData) { ingo@2467: List dataList = list.getAll(); ingo@2467: ingo@2467: for (Data d: dataList) { ingo@2467: String dataName = d.getLabel(); ingo@2467: DataItem item = d.getItems()[0]; ingo@2467: ingo@2467: if (dataName.equals(name)) { ingo@2467: return item.getStringValue(); ingo@2467: } ingo@2467: } ingo@2467: } ingo@2467: ingo@2467: return null; ingo@2467: } ingo@12: } ingo@12: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :