view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/SInfoResultRow.java @ 8980:b194fa64506a

SINFO - show results themes according to spec, either raw data or floating mean values. Some improvements to error handling and handling of empty results.
author gernotbelger
date Thu, 05 Apr 2018 18:30:34 +0200
parents a4f1ac81f26d
children
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.artifacts.sinfo.common;

import java.io.Serializable;
import java.util.EnumMap;
import java.util.Map;

import org.dive4elements.artifacts.CallContext;

/**
 * Generic container for results that come in rows.
 *
 * @author Gernot Belger
 */
public final class SInfoResultRow implements Serializable {
    private static final long serialVersionUID = 1L;

    private final Map<SInfoResultType, Object> values = new EnumMap<>(SInfoResultType.class);

    public static SInfoResultRow create() {
        return new SInfoResultRow();
    }

    private SInfoResultRow() {
    }

    public SInfoResultRow putValue(final SInfoResultType type, final Object value) {

        this.values.put(type, value);

        /* chain me */
        return this;
    }

    public String exportValue(final CallContext context, final SInfoResultType type) {
        final Object value = this.values.get(type);
        return type.exportValue(context, value);
    }

    public double getDoubleValue(final SInfoResultType type) {
        final Object value = this.values.get(type);
        return type.asDouble(value);
    }

    public Object getValue(final SInfoResultType type) {
        return this.values.get(type);
    }
}

http://dive4elements.wald.intevation.org