sascha@2725: package de.intevation.flys.artifacts; sascha@2725: sascha@2725: import java.util.Arrays; sascha@2725: sascha@2725: import de.intevation.artifactdatabase.data.StateData; sascha@2725: sascha@2725: import gnu.trove.TDoubleArrayList; sascha@2725: sascha@2725: import de.intevation.flys.utils.FLYSUtils; sascha@2725: sascha@2725: import org.apache.log4j.Logger; sascha@2725: sascha@2725: public class FixationArtifactAccess sascha@2725: { sascha@2725: private static Logger log = Logger.getLogger(FixationArtifactAccess.class); sascha@2725: sascha@2725: protected FLYSArtifact artifact; sascha@2725: sascha@2725: protected String river; sascha@2725: sascha@2725: protected String calculationMode; sascha@2725: sascha@2725: protected Double from; sascha@2725: protected Double to; sascha@2725: protected Double step; sascha@2725: sascha@2725: protected Long start; sascha@2725: protected Long end; sascha@2725: sascha@2725: protected Integer qSectorStart; sascha@2725: protected Integer qSectorEnd; sascha@2725: sascha@2725: protected Long referenceStart; sascha@2725: protected Long referenceEnd; sascha@2725: sascha@2725: protected long [][] analysisPeriods; sascha@2725: sascha@2725: protected int [] events; sascha@2725: sascha@2725: protected Boolean preprocessing; sascha@2725: sascha@2725: protected String function; sascha@2725: sascha@2725: protected double [] qs; sascha@2725: sascha@2725: public FixationArtifactAccess() { sascha@2725: } sascha@2725: sascha@2725: public FixationArtifactAccess(FLYSArtifact artifact) { sascha@2725: this.artifact = artifact; sascha@2725: } sascha@2725: sascha@2725: public FLYSArtifact getArtifact() { sascha@2725: return artifact; sascha@2725: } sascha@2725: sascha@2725: public String getRiver() { sascha@2725: if (river == null) { sascha@2725: StateData sd = artifact.getData("river"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'river' value"); sascha@2725: return null; sascha@2725: } sascha@2725: river = (String)sd.getValue(); sascha@2725: } sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("river: '" + river + "'"); sascha@2725: } sascha@2725: return river; sascha@2725: } sascha@2725: sascha@2725: public String getCalculationMode() { sascha@2725: if (calculationMode == null) { sascha@2725: StateData sd = artifact.getData("calculation.mode"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'calculation.mode' value"); sascha@2725: return null; sascha@2725: } sascha@2725: calculationMode = (String)sd.getValue(); sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("calculationMode: '" + calculationMode + "'"); sascha@2725: } sascha@2725: return calculationMode; sascha@2725: } sascha@2725: sascha@2725: public Double getFrom() { sascha@2725: sascha@2725: if (from == null) { sascha@2725: StateData sd = artifact.getData("from"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'from' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: from = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("from '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("from: '" + from + "'"); sascha@2725: } sascha@2725: sascha@2725: return from; sascha@2725: } sascha@2725: sascha@2725: public Double getTo() { sascha@2725: sascha@2725: if (to == null) { sascha@2725: StateData sd = artifact.getData("to"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'to' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: to = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("to '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("to: '" + to + "'"); sascha@2725: } sascha@2725: sascha@2725: return to; sascha@2725: } sascha@2725: sascha@2725: public Double getStep() { sascha@2725: sascha@2725: if (step == null) { sascha@2725: StateData sd = artifact.getData("step"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'step' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: step = Double.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("step '" + sd.getValue() + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("step: '" + step + "'"); sascha@2725: } sascha@2725: sascha@2725: return step; sascha@2725: } sascha@2725: sascha@2725: public Long getStart() { sascha@2725: sascha@2725: if (start == null) { sascha@2725: StateData sd = artifact.getData("start"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'start' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: start = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("start '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("start: '" + start + "'"); sascha@2725: } sascha@2725: sascha@2725: return start; sascha@2725: } sascha@2725: sascha@2725: public Long getEnd() { sascha@2725: sascha@2725: if (end == null) { sascha@2725: StateData sd = artifact.getData("end"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'end' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: end = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("end '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("end: '" + end + "'"); sascha@2725: } sascha@2725: sascha@2725: return end; sascha@2725: } sascha@2725: sascha@2725: public Integer getQSectorStart() { sascha@2725: sascha@2725: if (qSectorStart == null) { sascha@2725: StateData sd = artifact.getData("q1"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'q1' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: qSectorStart = Integer.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("q1 '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return qSectorStart; sascha@2725: } sascha@2725: sascha@2725: public Integer getQSectorEnd() { sascha@2725: sascha@2725: if (qSectorEnd == null) { sascha@2725: StateData sd = artifact.getData("q2"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'q2' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: qSectorEnd = Integer.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("q2 '" + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return qSectorEnd; sascha@2725: } sascha@2725: sascha@2725: public int [] getEvents() { sascha@2725: if (events == null) { sascha@2725: StateData sd = artifact.getData("events"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'events' value"); sascha@2725: return null; sascha@2725: } sascha@2725: events = FLYSUtils.intArrayFromString((String)sd.getValue()); sascha@2725: } sascha@2725: return events; sascha@2725: } sascha@2725: sascha@2725: public Long getReferenceStart() { sascha@2725: if (referenceStart == null) { sascha@2725: StateData sd = artifact.getData("ref_start"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'ref_start' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: referenceStart = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("ref_start '" sascha@2725: + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("referenceStart: '" + referenceStart + "'"); sascha@2725: } sascha@2725: sascha@2725: return referenceStart; sascha@2725: } sascha@2725: sascha@2725: public Long getReferenceEnd() { sascha@2725: if (referenceEnd == null) { sascha@2725: StateData sd = artifact.getData("ref_end"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'ref_end' value"); sascha@2725: return null; sascha@2725: } sascha@2725: try { sascha@2725: referenceEnd = Long.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("ref_end '" sascha@2725: + sd.getValue() + "' is not an integer."); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("referenceEnd: '" + referenceEnd + "'"); sascha@2725: } sascha@2725: sascha@2725: return referenceEnd; sascha@2725: } sascha@2725: sascha@2725: public long [][] getAnalysisPeriods() { sascha@2725: if (analysisPeriods == null) { sascha@2725: /** TODO: Use real arrays here! */ sascha@2725: StateData sdStart = artifact.getData("ana_start"); sascha@2725: StateData sdEnd = artifact.getData("ana_end"); sascha@2725: sascha@2725: if (sdStart == null || sdEnd == null) { sascha@2725: log.warn("missing 'ana_start' or 'ana_end'"); sascha@2725: return null; sascha@2725: } sascha@2725: sascha@2725: try { sascha@2725: analysisPeriods = new long [][] { sascha@2725: { Long.parseLong((String)sdStart.getValue()), sascha@2725: Long.parseLong((String)sdEnd.getValue()) } sascha@2725: }; sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("'ana_start' or 'ana_end' is not an integer."); sascha@2725: return null; sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: if (log.isDebugEnabled()) { sascha@2725: for (int i = 0; i < analysisPeriods.length; ++i) { sascha@2725: long [] ap = analysisPeriods[i]; sascha@2725: log.debug("analysis period " + ap[0] + " - " + ap[1]); sascha@2725: } sascha@2725: } sascha@2725: sascha@2725: return analysisPeriods; sascha@2725: } sascha@2725: sascha@2725: public Boolean getPreprocessing() { sascha@2725: if (preprocessing == null) { sascha@2725: StateData sd = artifact.getData("preprocessing"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'preprocessing'"); sascha@2725: return null; sascha@2725: } sascha@2725: preprocessing = Boolean.valueOf((String)sd.getValue()); sascha@2725: } sascha@2725: return preprocessing; sascha@2725: } sascha@2725: sascha@2725: public String getFunction() { sascha@2725: if (function == null) { sascha@2725: StateData sd = artifact.getData("function"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'function'"); sascha@2725: return null; sascha@2725: } sascha@2725: function = (String)sd.getValue(); sascha@2725: } sascha@2726: if (log.isDebugEnabled()) { sascha@2726: log.debug("function: " + function); sascha@2726: } sascha@2725: return function; sascha@2725: } sascha@2725: sascha@2725: public double [] getQs() { sascha@2725: if (qs == null) { sascha@2725: StateData sd = artifact.getData("qs"); sascha@2725: if (sd == null) { sascha@2725: log.warn("missing 'qs'"); sascha@2725: return null; sascha@2725: } sascha@2725: String [] parts = ((String)sd.getValue()).split("[\\s;]"); sascha@2725: TDoubleArrayList list = new TDoubleArrayList(parts.length); sascha@2725: for (String part: parts) { sascha@2725: try { sascha@2725: list.add(Double.parseDouble(part)); sascha@2725: } sascha@2725: catch (NumberFormatException nfe) { sascha@2725: log.warn("'" + part + "' is not numeric."); sascha@2725: } sascha@2725: } sascha@2725: qs = list.toNativeArray(); sascha@2725: } sascha@2725: if (log.isDebugEnabled()) { sascha@2725: log.debug("qs: " + Arrays.toString(qs)); sascha@2725: } sascha@2725: return qs; sascha@2725: } sascha@2725: } sascha@2725: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :