teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.fixings; bjoern@4442: gernotbelger@9415: import static org.dive4elements.river.exports.injector.InjectorConstants.CURRENT_KM; gernotbelger@9415: teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.river.artifacts.model.DataFacet; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; bjoern@4442: bjoern@4442: /** bjoern@4442: * Facet to access the current Km from the context safely teichmann@4736: * bjoern@4442: * @author Björn Ricks bjoern@4442: */ gernotbelger@9415: public abstract class FixingsFacet extends DataFacet { gernotbelger@9415: gernotbelger@9415: private static final long serialVersionUID = 1L; bjoern@4442: bjoern@4442: public static final Double INVALID_KM = Double.valueOf(-1d); bjoern@4442: bjoern@4442: public FixingsFacet() { bjoern@4442: } bjoern@4442: gernotbelger@9415: public FixingsFacet(final int index, final String name, final String description, final ComputeType type, final String hash, final String stateId) { bjoern@4442: super(index, name, description, type, hash, stateId); bjoern@4442: } bjoern@4442: bjoern@4442: /** bjoern@4442: * Returns the current km from the context. tom@8856: * If the context is null or doesn't contain a currentKm tom@8856: * then a double value of -1 will be returned. gernotbelger@9415: * gernotbelger@9415: * @param context gernotbelger@9415: * The CallContext instance bjoern@4442: * @return the current km as double bjoern@4442: */ gernotbelger@9415: protected final double getCurrentKm(final CallContext context) { bjoern@4442: if (context == null) { bjoern@4442: return INVALID_KM; bjoern@4442: } gernotbelger@9415: final Double dkm = (Double) context.getContextValue(CURRENT_KM); bjoern@4442: if (dkm == null) { bjoern@4442: return INVALID_KM; bjoern@4442: } bjoern@4442: return dkm.doubleValue(); bjoern@4442: } gernotbelger@9415: }