* 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;
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;
return oldRow;
}
- public void setOld(Row<E> old) {
+ public void setOld(final Row<E> old) {
this.oldRow = old;
}
}
@SuppressWarnings("checkstyle:HiddenField")
- public void setNew(Row<E> newRow) {
+ public void setNew(final Row<E> newRow) {
this.newRow = newRow;
}
}
}
- 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
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;
@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));
@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;
@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;
* @return Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>
* 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;
}