Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java @ 2715:250a370c377d
Added chart generator for middle bed height charts.
flys-artifacts/trunk@4441 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 18 May 2012 11:58:38 +0000 |
parents | ae0742f92cd5 |
children | a441be7f1589 |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import gnu.trove.TDoubleArrayList; import java.util.Map; import java.io.Serializable; public class Parameters implements Serializable { public static class Parameter implements Serializable { public String name; public double value; public Parameter() { } public Parameter(String name, double value) { this.name = name; this.value = value; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } } // Parameter protected String [] columnNames; protected TDoubleArrayList [] columns; public Parameters() { } public Parameters(String [] columnNames) { if (columnNames == null || columnNames.length < 1) { throw new IllegalArgumentException("columnNames too short."); } this.columnNames = columnNames; columns = new TDoubleArrayList[columnNames.length]; for (int i = 0; i < columns.length; ++i) { columns[i] = new TDoubleArrayList(); } } public int columnIndex(String name) { for (int i = 0; i < columnNames.length; ++i) { if (name.equals(name)) { return i; } } return -1; } public void add(Parameter [] parameters) { int N = columns[0].size(); for (int i = 0; i < columns.length; ++i) { columns[i].add(Double.NaN); } for (Parameter parameter: parameters) { int index = columnIndex(parameter.getName()); if (index >= 0) { columns[index].setQuick(N, parameter.getValue()); } } } public void add(Map<String, Double> parameters) { int N = columns[0].size(); for (int i = 0; i < columns.length; ++i) { columns[i].add(Double.NaN); } for (Map.Entry<String, Double> entry: parameters.entrySet()) { int index = columnIndex(entry.getKey()); Double v = entry.getValue(); if (index >= 0 && v != null) { columns[index].setQuick(N, v); } } } public Parameter [] get(int i) { Parameter [] parameters = new Parameter[columns.length]; for (int j = 0; i < parameters.length; ++j) { parameters[j] = new Parameter(columnNames[j], Double.NaN); } return get(i, parameters); } public Parameter [] get(int i, Parameter [] parameters) { for (Parameter parameter: parameters) { int index = columnIndex(parameter.getName()); if (index >= 0) { parameter.setValue(columns[index].getQuick(i)); } } return parameters; } public double get(int i, int index) { return columns[index].getQuick(i); } public double get(int i, String columnName) { int index = columnIndex(columnName); return index >= 0 ? columns[index].getQuick(i) : Double.NaN; } public int size() { return columns[0].size(); } public int getNumberColumns() { return columnNames.length; } public String [] getColumnNames() { return columnNames; } public void removeNaNs() { W.removeNaNs(columns); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :