comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixingsFacet.java @ 4442:26774405c884

Introduce a new FixingsFacet to add save access to the current Km Values which are accessed by a String like a map must be checked for null. The new FixingsFacet adds a getCurrentKm method that abstracts the direct access to the CallContext and always returns a valid double value.
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 07 Nov 2012 14:06:03 +0100
parents
children b195fede1c3b
comparison
equal deleted inserted replaced
4441:093f9333f66b 4442:26774405c884
1 package de.intevation.flys.artifacts.model.fixings;
2
3 import de.intevation.artifacts.CallContext;
4 import de.intevation.flys.artifacts.model.DataFacet;
5 import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
6
7 /**
8 * Facet to access the current Km from the context safely
9 *
10 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
11 */
12 public class FixingsFacet extends DataFacet {
13
14 public static final Double INVALID_KM = Double.valueOf(-1d);
15 public static final String CURRENT_KM = "currentKm";
16
17 public FixingsFacet() {
18 }
19
20 public FixingsFacet(String name, String description) {
21 super(0, name, description, ComputeType.ADVANCE, null, null);
22 }
23
24 public FixingsFacet(
25 int index,
26 String name,
27 String description,
28 ComputeType type,
29 String hash,
30 String stateId
31 ) {
32 super(index, name, description, type, hash, stateId);
33 }
34
35 /**
36 * Returns the current km from the context.
37 * If the context is null or doesn't contain a currentKm then a double value of -1 will
38 * be returned.
39 * @param context The CallContext instance
40 * @return the current km as double
41 */
42 protected double getCurrentKm(CallContext context) {
43 if (context == null) {
44 return INVALID_KM;
45 }
46 Double dkm = (Double)context.getContextValue(CURRENT_KM);
47 if (dkm == null) {
48 return INVALID_KM;
49 }
50 return dkm.doubleValue();
51 }
52 }

http://dive4elements.wald.intevation.org