RowUpdate should be a static class 05/86105/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 23:51:41 +0000 (00:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 23:51:41 +0000 (00:51 +0100)
RowUpdate does not reference any TableUpdate state, hence it should
be static. This allows users to shorten their references, as they
do not need to qualify TableUpdate specialization.

Change-Id: I0be3a88623a43df4eaa8abd74ff2ca6732a88e57
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
library/impl/src/main/java/org/opendaylight/ovsdb/lib/message/TableUpdate.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedDatabaseSchemaImpl.java

index 4d10478d153433c0a3d5d08626543926ea1d5ce3..9d83eec33d3cd322e5312c8960e3e0d38d0f1048 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.ovsdb.lib.message;
 
 import java.util.HashMap;
@@ -15,18 +14,18 @@ import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 
 public class TableUpdate<E extends TableSchema<E>> {
-    private Map<UUID, RowUpdate<E>> rows;
+    private final Map<UUID, RowUpdate<E>> rows = new HashMap<>();
 
     public Map<UUID, RowUpdate<E>> getRows() {
         return rows;
     }
 
-    public class RowUpdate<E extends TableSchema<E>> {
-        private UUID uuid;
+    public static class RowUpdate<E extends TableSchema<E>> {
+        private final UUID uuid;
         private Row<E> oldRow;
         private Row<E> newRow;
 
-        public RowUpdate(UUID uuid, Row<E> oldRow, Row<E> newRow) {
+        public RowUpdate(final UUID uuid, final Row<E> oldRow, final Row<E> newRow) {
             this.uuid = uuid;
             this.oldRow = oldRow;
             this.newRow = newRow;
@@ -40,7 +39,7 @@ public class TableUpdate<E extends TableSchema<E>> {
             return oldRow;
         }
 
-        public void setOld(Row<E> old) {
+        public void setOld(final Row<E> old) {
             this.oldRow = old;
         }
 
@@ -49,7 +48,7 @@ public class TableUpdate<E extends TableSchema<E>> {
         }
 
         @SuppressWarnings("checkstyle:HiddenField")
-        public void setNew(Row<E> newRow) {
+        public void setNew(final Row<E> newRow) {
             this.newRow = newRow;
         }
 
@@ -60,28 +59,18 @@ public class TableUpdate<E extends TableSchema<E>> {
         }
     }
 
-    public TableUpdate() {
-        rows = new HashMap<>();
-    }
-
-    public void addRow(UUID uuid, Row<E> oldRow, Row<E> newRow) {
+    public void addRow(final UUID uuid, final Row<E> oldRow, final Row<E> newRow) {
         rows.put(uuid, new RowUpdate<>(uuid, oldRow, newRow));
     }
 
-    public Row<E> getOld(UUID uuid) {
+    public Row<E> getOld(final UUID uuid) {
         RowUpdate<E> rowUpdate = rows.get(uuid);
-        if (rowUpdate == null) {
-            return null;
-        }
-        return rowUpdate.getOld();
+        return rowUpdate != null ? rowUpdate.getOld() : null;
     }
 
-    public Row<E> getNew(UUID uuid) {
+    public Row<E> getNew(final UUID uuid) {
         RowUpdate<E> rowUpdate = rows.get(uuid);
-        if (rowUpdate == null) {
-            return null;
-        }
-        return rowUpdate.getNew();
+        return rowUpdate != null ? rowUpdate.getNew() : null;
     }
 
     @Override
index cdf099dcc1341c548f8256ba87f92e80041cd689..686d074373fab18d086c27c5fa10e3f59d2fcf97 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.reflect.Reflection;
 import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.ovsdb.lib.message.TableUpdate;
+import org.opendaylight.ovsdb.lib.message.TableUpdate.RowUpdate;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.notation.Row;
 import org.opendaylight.ovsdb.lib.notation.UUID;
@@ -79,10 +80,8 @@ final class TypedDatabaseSchemaImpl extends ForwardingDatabaseSchema implements
 
     @Override
     public <T> Map<UUID, T> extractRowsOld(final Class<T> klazz, final TableUpdates updates) {
-        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(
-            requireNonNull(klazz), requireNonNull(updates));
         Map<UUID,T> result = new HashMap<>();
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+        for (RowUpdate<GenericTableSchema> rowUpdate : extractRowUpdates(klazz, updates).values()) {
             if (rowUpdate != null && rowUpdate.getOld() != null) {
                 Row<GenericTableSchema> row = rowUpdate.getOld();
                 result.put(rowUpdate.getUuid(), getTypedRowWrapper(klazz, row));
@@ -93,13 +92,10 @@ final class TypedDatabaseSchemaImpl extends ForwardingDatabaseSchema implements
 
     @Override
     public <T> Map<UUID, T> extractRowsUpdated(final Class<T> klazz, final TableUpdates updates) {
-        final Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
-                extractRowUpdates(klazz, updates);
-        final Map<UUID,T> result = new HashMap<>();
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+        final Map<UUID, T> result = new HashMap<>();
+        for (RowUpdate<GenericTableSchema> rowUpdate : extractRowUpdates(klazz, updates).values()) {
             if (rowUpdate != null && rowUpdate.getNew() != null) {
-                Row<GenericTableSchema> row = rowUpdate.getNew();
-                result.put(rowUpdate.getUuid(), getTypedRowWrapper(klazz, row));
+                result.put(rowUpdate.getUuid(), getTypedRowWrapper(klazz, rowUpdate.getNew()));
             }
         }
         return result;
@@ -107,13 +103,10 @@ final class TypedDatabaseSchemaImpl extends ForwardingDatabaseSchema implements
 
     @Override
     public <T> Map<UUID, T> extractRowsRemoved(final Class<T> klazz, final TableUpdates updates) {
-        final Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
-                extractRowUpdates(klazz, updates);
         final Map<UUID, T> result = new HashMap<>();
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+        for (RowUpdate<GenericTableSchema> rowUpdate : extractRowUpdates(klazz, updates).values()) {
             if (rowUpdate != null && rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
-                Row<GenericTableSchema> row = rowUpdate.getOld();
-                result.put(rowUpdate.getUuid(), getTypedRowWrapper(klazz, row));
+                result.put(rowUpdate.getUuid(), getTypedRowWrapper(klazz, rowUpdate.getOld()));
             }
         }
         return result;
@@ -132,13 +125,13 @@ final class TypedDatabaseSchemaImpl extends ForwardingDatabaseSchema implements
      * @return Map&lt;UUID,TableUpdate&lt;GenericTableSchema&gt;.RowUpdate&lt;GenericTableSchema&gt;&gt;
      *     for the type of things being sought
      */
-    private Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(
-            final Class<?> klazz, final TableUpdates updates) {
+    private Map<UUID, RowUpdate<GenericTableSchema>> extractRowUpdates(final Class<?> klazz,
+            final TableUpdates updates) {
         TableUpdate<GenericTableSchema> update = updates.getUpdate(table(TypedReflections.getTableName(klazz),
             GenericTableSchema.class));
-        Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result = new HashMap<>();
+        Map<UUID, RowUpdate<GenericTableSchema>> result = new HashMap<>();
         if (update != null) {
-            Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
+            Map<UUID, RowUpdate<GenericTableSchema>> rows = update.getRows();
             if (rows != null) {
                 result = rows;
             }