diff gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java @ 9227:84397da33d17

Allow to control specific behaviour in TwinDatacagePanel Implemented client logic of 'intelligent datacage filtering' for SINFO
author gernotbelger
date Wed, 04 Jul 2018 18:28:08 +0200
parents 4b29bb2c785f
children
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java	Wed Jul 04 17:14:16 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java	Wed Jul 04 18:28:08 2018 +0200
@@ -8,47 +8,64 @@
 
 package org.dive4elements.river.client.shared.model;
 
-import java.util.List;
+import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.List;
 
-import java.io.Serializable;
-
+// FIXME: who implements a thing like this?? this is a HashMap!!
 public class AttrList implements Serializable
 {
-    protected List<String> keyValues;
+    private static final long serialVersionUID = 1L;
+
+    private List<String> keyValues;
 
     public AttrList() {
         this(5);
     }
 
-    public AttrList(int size) {
-        keyValues = new ArrayList<String>(size*2);
+    public AttrList(final int size) {
+        this.keyValues = new ArrayList<String>(size*2);
     }
 
     public int size() {
-        return keyValues != null ? keyValues.size()/2 : null;
-    }
-
-    public String getKey(int index) {
-        return keyValues.get(index*2);
+        return this.keyValues.size() / 2;
     }
 
-    public String getValue(int index) {
-        return keyValues.get(index*2 + 1);
+    /**
+     * IMPORTANT: necessary for serialization
+     */
+    public void setKeyValues(final List<String> keyValues) {
+        this.keyValues = keyValues;
     }
 
-    public void add(String key, String value) {
-        keyValues.add(key);
-        keyValues.add(value);
+    public String getKey(final int index) {
+        return this.keyValues.get(index*2);
     }
 
-    public boolean hasAttribute(String key) {
-        for (int i = 0, N = keyValues.size(); i < N; i += 2) {
-            if (keyValues.get(i).equals(key)) {
+    public String getValue(final int index) {
+        return this.keyValues.get(index*2 + 1);
+    }
+
+    public String getValue(final String key) {
+        for (int i = 0, N = this.keyValues.size(); i < N; i += 2) {
+            if (this.keyValues.get(i).equals(key)) {
+                return this.keyValues.get(i + 1);
+            }
+        }
+        return null;
+    }
+
+    public void add(final String key, final String value) {
+        this.keyValues.add(key);
+        this.keyValues.add(value);
+    }
+
+    public boolean hasAttribute(final String key) {
+        for (int i = 0, N = this.keyValues.size(); i < N; i += 2) {
+            if (this.keyValues.get(i).equals(key)) {
                 return true;
             }
         }
         return false;
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org