diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/StaticWQKmsCacheKey.java @ 8876:23264d1a528f

Allow access to staticwqkms data; also allow to acces by km range
author gernotbelger
date Thu, 08 Feb 2018 18:47:36 +0100
parents 26c7aa469bfc
children
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/StaticWQKmsCacheKey.java	Thu Feb 08 18:46:34 2018 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/StaticWQKmsCacheKey.java	Thu Feb 08 18:47:36 2018 +0100
@@ -10,6 +10,9 @@
 
 import java.io.Serializable;
 
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
 /**
  * Caching-Key object for 'static' wst- data.
  */
@@ -18,24 +21,48 @@
 {
     public static final String CACHE_NAME = "wst-wq-value-table-static";
 
-    private int column;
-    private int wst_id;
+    private final int column;
+    
+    private final int wst_id;
 
-    public StaticWQKmsCacheKey(int column, int wst_id) {
+    private double from;
+
+    private double to;
+
+    private int hash;
+
+    public StaticWQKmsCacheKey(final int column, final int wst_id, final double from, final double to) {
         this.wst_id  = wst_id;
         this.column  = column;
+        this.from = from;
+        this.to = to;
+        this.hash = new HashCodeBuilder().append(column).append(wst_id).append(false).append(to).toHashCode();
     }
 
+    @Override
     public int hashCode() {
-        return (wst_id << 8) | column;
+        return this.hash;
     }
 
-    public boolean equals(Object other) {
-        if (!(other instanceof StaticWQKmsCacheKey)) {
+    @Override
+    public boolean equals(final Object other) {
+        
+        if (other == null) 
             return false;
+        if( other == this) 
+            return true;
+        if (other.getClass() != getClass()) {
+          return false;
         }
-        StaticWQKmsCacheKey o = (StaticWQKmsCacheKey) other;
-        return this.wst_id == o.wst_id && this.column == o.column;
+        
+        final StaticWQKmsCacheKey rhs = (StaticWQKmsCacheKey) other;
+        
+        return new EqualsBuilder(). //
+                append(column, rhs.column). //
+                append(wst_id, rhs.wst_id). //
+                append(from, rhs.from). //
+                append(to, rhs.to). //
+                isEquals();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org