Implement ImmutableOffsetMap.toString() 57/26757/1
authorRobert Varga <rovarga@cisco.com>
Thu, 10 Sep 2015 07:57:46 +0000 (09:57 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 10 Sep 2015 07:57:46 +0000 (09:57 +0200)
Previous patch inadvertedly removed the Map-specific implementation of
toString() -- as it used to be iunherited from AbstractMap. This patch
introduces it back.

Change-Id: Id186a75b5e4880461375c8031756461db78fee0e
Signed-off-by: Robert Varga <rovarga@cisco.com>
common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java

index f2d34020ca4997342e853072329e33f71eb0d2cc..1366856c773093046c0e4cd8e30ea9436213896e 100644 (file)
@@ -238,6 +238,24 @@ public final class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K, V
         return new MutableOffsetMap<>(this);
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("{");
+        final Iterator<K> it = offsets.keySet().iterator();
+        int i = 0;
+        while (it.hasNext()) {
+            sb.append(it.next());
+            sb.append('=');
+            sb.append(objects[i++]);
+
+            if (it.hasNext()) {
+                sb.append(", ");
+            }
+        }
+
+        return sb.append('}').toString();
+    }
+
     Map<K, Integer> offsets() {
         return offsets;
     }