teichmann@5831: package org.dive4elements.river.artifacts.model.fixings; bjoern@4442: 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: */ bjoern@4442: public class FixingsFacet extends DataFacet { bjoern@4442: bjoern@4442: public static final Double INVALID_KM = Double.valueOf(-1d); bjoern@4442: public static final String CURRENT_KM = "currentKm"; bjoern@4442: bjoern@4442: public FixingsFacet() { bjoern@4442: } bjoern@4442: bjoern@4442: public FixingsFacet(String name, String description) { bjoern@4442: super(0, name, description, ComputeType.ADVANCE, null, null); bjoern@4442: } bjoern@4442: bjoern@4442: public FixingsFacet( bjoern@4442: int index, bjoern@4442: String name, bjoern@4442: String description, bjoern@4442: ComputeType type, bjoern@4442: String hash, bjoern@4442: String stateId bjoern@4442: ) { bjoern@4442: super(index, name, description, type, hash, stateId); bjoern@4442: } bjoern@4442: bjoern@4442: /** bjoern@4442: * Returns the current km from the context. bjoern@4442: * If the context is null or doesn't contain a currentKm then a double value of -1 will bjoern@4442: * be returned. bjoern@4442: * @param context The CallContext instance bjoern@4442: * @return the current km as double bjoern@4442: */ bjoern@4442: protected double getCurrentKm(CallContext context) { bjoern@4442: if (context == null) { bjoern@4442: return INVALID_KM; bjoern@4442: } bjoern@4442: 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: } bjoern@4442: }