aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/UncertainProperty.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/utils/UncertainProperty.java')
-rw-r--r--main/src/cgeo/geocaching/utils/UncertainProperty.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/UncertainProperty.java b/main/src/cgeo/geocaching/utils/UncertainProperty.java
new file mode 100644
index 0000000..e8686e3
--- /dev/null
+++ b/main/src/cgeo/geocaching/utils/UncertainProperty.java
@@ -0,0 +1,53 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.connector.gc.Tile;
+
+/**
+ * Property with certainty. When merging properties, the one with higher certainty wins.
+ *
+ * @param <T>
+ */
+public class UncertainProperty<T> {
+
+ private final T value;
+ private final int certaintyLevel;
+
+ public UncertainProperty(T value) {
+ this(value, Tile.ZOOMLEVEL_MAX + 1);
+ }
+
+ public UncertainProperty(T value, int certaintyLevel) {
+ this.value = value;
+ this.certaintyLevel = certaintyLevel;
+ }
+
+ public T getValue() {
+ return value;
+ }
+
+ public int getCertaintyLevel() {
+ return certaintyLevel;
+ }
+
+ public UncertainProperty<T> getMergedProperty(final UncertainProperty<T> other) {
+ if (null == other || null == other.value) {
+ return this;
+ }
+ if (null == this.value) {
+ return other;
+ }
+ if (other.certaintyLevel > certaintyLevel) {
+ return other;
+ }
+
+ return this;
+ }
+
+ public static <T> UncertainProperty<T> getMergedProperty(UncertainProperty<T> property, UncertainProperty<T> otherProperty) {
+ if (null == property) {
+ return otherProperty;
+ }
+ return property.getMergedProperty(otherProperty);
+ }
+
+}