blob: 80c01ff3215fd4d16eca29ff02429c9e0336bb4e [file] [log] [blame]
Sho SHIMIZUe4efe452015-08-26 15:06:55 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUe4efe452015-08-26 15:06:55 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ovsdb.rfc.notation;
17
andreaed976a42015-10-05 14:38:25 -070018import com.google.common.collect.Maps;
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070019
20import java.util.Collection;
21import java.util.Map;
22import java.util.Objects;
23
andreaed976a42015-10-05 14:38:25 -070024import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkNotNull;
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070026
27/**
28 * Row is the basic element of the OpenVswitch's table.
29 */
30public final class Row {
31 private String tableName;
Jonathan Hart51539b82015-10-29 09:53:04 -070032 private Uuid uuid;
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070033 private Map<String, Column> columns;
34
35 /**
36 * Row constructor.
37 */
38 public Row() {
39 this.columns = Maps.newHashMap();
40 }
41
42 /**
43 * Row constructor.
andreaed976a42015-10-05 14:38:25 -070044 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070045 * @param tableName table name
andreaed976a42015-10-05 14:38:25 -070046 * @param columns Map of Column entity
Brian O'Connor52515622015-10-09 17:03:44 -070047 * @param uuid UUID of the row
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070048 */
Jonathan Hart51539b82015-10-29 09:53:04 -070049 public Row(String tableName, Uuid uuid, Map<String, Column> columns) {
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070050 checkNotNull(tableName, "table name cannot be null");
andreaed976a42015-10-05 14:38:25 -070051 checkNotNull(uuid, "uuid cannot be null");
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070052 checkNotNull(columns, "columns cannot be null");
53 this.tableName = tableName;
andreaed976a42015-10-05 14:38:25 -070054 this.uuid = uuid;
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070055 this.columns = columns;
56 }
57
58 /**
59 * Returns tableName.
andreaed976a42015-10-05 14:38:25 -070060 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070061 * @return tableName
62 */
63 public String tableName() {
64 return tableName;
65 }
66
67 /**
68 * Set tableName value.
andreaed976a42015-10-05 14:38:25 -070069 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070070 * @param tableName table name
71 */
72 public void setTableName(String tableName) {
73 this.tableName = tableName;
74 }
75
76 /**
andreaed976a42015-10-05 14:38:25 -070077 * Returns uuid.
78 *
79 * @return uuid
80 */
Jonathan Hart51539b82015-10-29 09:53:04 -070081 public Uuid uuid() {
andreaed976a42015-10-05 14:38:25 -070082 return uuid;
83 }
84
85 /**
86 * Sets uuid value.
87 *
88 * @param uuid new uuid
89 */
Jonathan Hart51539b82015-10-29 09:53:04 -070090 public void setUuid(Uuid uuid) {
andreaed976a42015-10-05 14:38:25 -070091 this.uuid = uuid;
92 }
93
94 /**
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070095 * Returns Column by ColumnSchema.
andreaed976a42015-10-05 14:38:25 -070096 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070097 * @param columnName column name
98 * @return Column
99 */
100 public Column getColumn(String columnName) {
101 return columns.get(columnName);
102 }
103
104 /**
105 * Returns Collection of Column.
andreaed976a42015-10-05 14:38:25 -0700106 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700107 * @return Collection of Column
108 */
109 public Collection<Column> getColumns() {
110 return columns.values();
111 }
112
113 /**
114 * add Column.
andreaed976a42015-10-05 14:38:25 -0700115 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700116 * @param columnName column name
andreaed976a42015-10-05 14:38:25 -0700117 * @param data Column entity
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700118 */
119 public void addColumn(String columnName, Column data) {
120 this.columns.put(columnName, data);
121 }
122
123 @Override
124 public int hashCode() {
125 return Objects.hash(tableName, columns);
126 }
127
128 @Override
129 public boolean equals(Object obj) {
130 if (this == obj) {
131 return true;
132 }
133 if (obj instanceof Row) {
134 final Row other = (Row) obj;
135 return Objects.equals(this.tableName, other.tableName)
136 && Objects.equals(this.columns, other.columns);
137 }
138 return false;
139 }
140
141 @Override
142 public String toString() {
143 return toStringHelper(this).add("tableName", tableName)
144 .add("columns", columns).toString();
145 }
146}