blob: eee0ee889fbe97f16bd86b08ab54b088e9edb3f9 [file] [log] [blame]
Sho SHIMIZUe4efe452015-08-26 15:06:55 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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
Sho SHIMIZU3895cc32015-10-13 10:52:22 -070046 * @deprecated in Emu Release
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070047 */
andreaed976a42015-10-05 14:38:25 -070048 @Deprecated
49 private Row(String tableName) {
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070050 checkNotNull(tableName, "tableName cannot be null");
51 this.tableName = tableName;
52 this.columns = Maps.newHashMap();
53 }
54
55 /**
56 * Row constructor.
andreaed976a42015-10-05 14:38:25 -070057 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070058 * @param tableName table name
andreaed976a42015-10-05 14:38:25 -070059 * @param columns Map of Column entity
Brian O'Connor52515622015-10-09 17:03:44 -070060 * @param uuid UUID of the row
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070061 */
Jonathan Hart51539b82015-10-29 09:53:04 -070062 public Row(String tableName, Uuid uuid, Map<String, Column> columns) {
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070063 checkNotNull(tableName, "table name cannot be null");
andreaed976a42015-10-05 14:38:25 -070064 checkNotNull(uuid, "uuid cannot be null");
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070065 checkNotNull(columns, "columns cannot be null");
66 this.tableName = tableName;
andreaed976a42015-10-05 14:38:25 -070067 this.uuid = uuid;
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070068 this.columns = columns;
69 }
70
71 /**
72 * Returns tableName.
andreaed976a42015-10-05 14:38:25 -070073 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070074 * @return tableName
75 */
76 public String tableName() {
77 return tableName;
78 }
79
80 /**
81 * Set tableName value.
andreaed976a42015-10-05 14:38:25 -070082 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -070083 * @param tableName table name
84 */
85 public void setTableName(String tableName) {
86 this.tableName = tableName;
87 }
88
89 /**
andreaed976a42015-10-05 14:38:25 -070090 * Returns uuid.
91 *
92 * @return uuid
93 */
Jonathan Hart51539b82015-10-29 09:53:04 -070094 public Uuid uuid() {
andreaed976a42015-10-05 14:38:25 -070095 return uuid;
96 }
97
98 /**
99 * Sets uuid value.
100 *
101 * @param uuid new uuid
102 */
Jonathan Hart51539b82015-10-29 09:53:04 -0700103 public void setUuid(Uuid uuid) {
andreaed976a42015-10-05 14:38:25 -0700104 this.uuid = uuid;
105 }
106
107 /**
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700108 * Returns Column by ColumnSchema.
andreaed976a42015-10-05 14:38:25 -0700109 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700110 * @param columnName column name
111 * @return Column
112 */
113 public Column getColumn(String columnName) {
114 return columns.get(columnName);
115 }
116
117 /**
118 * Returns Collection of Column.
andreaed976a42015-10-05 14:38:25 -0700119 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700120 * @return Collection of Column
121 */
122 public Collection<Column> getColumns() {
123 return columns.values();
124 }
125
126 /**
127 * add Column.
andreaed976a42015-10-05 14:38:25 -0700128 *
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700129 * @param columnName column name
andreaed976a42015-10-05 14:38:25 -0700130 * @param data Column entity
Sho SHIMIZUe4efe452015-08-26 15:06:55 -0700131 */
132 public void addColumn(String columnName, Column data) {
133 this.columns.put(columnName, data);
134 }
135
136 @Override
137 public int hashCode() {
138 return Objects.hash(tableName, columns);
139 }
140
141 @Override
142 public boolean equals(Object obj) {
143 if (this == obj) {
144 return true;
145 }
146 if (obj instanceof Row) {
147 final Row other = (Row) obj;
148 return Objects.equals(this.tableName, other.tableName)
149 && Objects.equals(this.columns, other.columns);
150 }
151 return false;
152 }
153
154 @Override
155 public String toString() {
156 return toStringHelper(this).add("tableName", tableName)
157 .add("columns", columns).toString();
158 }
159}