2 * Copyright (c) 2014, 2015 EBay Software Foundation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.ovsdb.lib.notation;
11 import com.fasterxml.jackson.annotation.JsonIgnore;
12 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
13 import com.google.common.collect.Maps;
14 import java.util.Collection;
15 import java.util.List;
17 import org.opendaylight.ovsdb.lib.notation.json.RowSerializer;
18 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
19 import org.opendaylight.ovsdb.lib.schema.TableSchema;
21 @JsonSerialize(using = RowSerializer.class)
22 public class Row<E extends TableSchema<E>> {
24 private TableSchema<E> tableSchema;
25 protected Map<String, Column<E, ?>> columns;
28 this.columns = Maps.newHashMap();
31 public Row(TableSchema<E> tableSchema) {
32 this.tableSchema = tableSchema;
33 this.columns = Maps.newHashMap();
36 public Row(TableSchema<E> tableSchema, List<Column<E, ?>> columns) {
37 this.tableSchema = tableSchema;
38 this.columns = Maps.newHashMap();
39 for (Column<E, ?> column : columns) {
40 this.columns.put(column.getSchema().getName(), column);
44 public <D> Column<E, D> getColumn(ColumnSchema<E, D> schema) {
45 return (Column<E, D>) columns.get(schema.getName());
48 public Collection<Column<E, ?>> getColumns() {
49 return columns.values();
52 public void addColumn(String columnName, Column<E, ?> data) {
53 this.columns.put(columnName, data);
56 public TableSchema<E> getTableSchema() {
60 public void setTableSchema(TableSchema<E> tableSchema) {
61 this.tableSchema = tableSchema;
65 public String toString() {
66 return "Row [columns=" + columns + "]";
70 * The hashCode method for Row object should be used with caution.
71 * This method will use all the columns in the row to calculate the hashKey.
72 * Hence using this method on a partial Row will return a different hashKey
73 * and will not work in most of the use-cases this method might be used.
76 public int hashCode() {
79 result = prime * result + ((columns == null) ? 0 : columns.hashCode());
84 * The equals method for Row object should be used with caution.
85 * This method will compare all the columns in the row being compared.
86 * Hence using this method to compare a partial Row will return false
87 * and will not work in most of the use-cases this method might be used.
90 public boolean equals(Object obj) {
97 if (getClass() != obj.getClass()) {
100 Row other = (Row) obj;
101 if (columns == null) {
102 if (other.columns != null) {
105 } else if (!columns.equals(other.columns)) {