Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ovsdb.rfc.notation; |
| 17 | |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 18 | import com.google.common.collect.Maps; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.Collection; |
| 21 | import java.util.Map; |
| 22 | import java.util.Objects; |
| 23 | |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Row is the basic element of the OpenVswitch's table. |
| 29 | */ |
| 30 | public final class Row { |
| 31 | private String tableName; |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 32 | private UUID uuid; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 33 | 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. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 44 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 45 | * @param tableName table name |
| 46 | */ |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 47 | @Deprecated |
| 48 | private Row(String tableName) { |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 49 | checkNotNull(tableName, "tableName cannot be null"); |
| 50 | this.tableName = tableName; |
| 51 | this.columns = Maps.newHashMap(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Row constructor. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 56 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 57 | * @param tableName table name |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 58 | * @param columns Map of Column entity |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 59 | */ |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 60 | public Row(String tableName, UUID uuid, Map<String, Column> columns) { |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 61 | checkNotNull(tableName, "table name cannot be null"); |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 62 | checkNotNull(uuid, "uuid cannot be null"); |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 63 | checkNotNull(columns, "columns cannot be null"); |
| 64 | this.tableName = tableName; |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 65 | this.uuid = uuid; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 66 | this.columns = columns; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns tableName. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 71 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 72 | * @return tableName |
| 73 | */ |
| 74 | public String tableName() { |
| 75 | return tableName; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Set tableName value. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 80 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 81 | * @param tableName table name |
| 82 | */ |
| 83 | public void setTableName(String tableName) { |
| 84 | this.tableName = tableName; |
| 85 | } |
| 86 | |
| 87 | /** |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 88 | * Returns uuid. |
| 89 | * |
| 90 | * @return uuid |
| 91 | */ |
| 92 | public UUID uuid() { |
| 93 | return uuid; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sets uuid value. |
| 98 | * |
| 99 | * @param uuid new uuid |
| 100 | */ |
| 101 | public void setUuid(UUID uuid) { |
| 102 | this.uuid = uuid; |
| 103 | } |
| 104 | |
| 105 | /** |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 106 | * Returns Column by ColumnSchema. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 107 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 108 | * @param columnName column name |
| 109 | * @return Column |
| 110 | */ |
| 111 | public Column getColumn(String columnName) { |
| 112 | return columns.get(columnName); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Returns Collection of Column. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 117 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 118 | * @return Collection of Column |
| 119 | */ |
| 120 | public Collection<Column> getColumns() { |
| 121 | return columns.values(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * add Column. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 126 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 127 | * @param columnName column name |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame^] | 128 | * @param data Column entity |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 129 | */ |
| 130 | public void addColumn(String columnName, Column data) { |
| 131 | this.columns.put(columnName, data); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public int hashCode() { |
| 136 | return Objects.hash(tableName, columns); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public boolean equals(Object obj) { |
| 141 | if (this == obj) { |
| 142 | return true; |
| 143 | } |
| 144 | if (obj instanceof Row) { |
| 145 | final Row other = (Row) obj; |
| 146 | return Objects.equals(this.tableName, other.tableName) |
| 147 | && Objects.equals(this.columns, other.columns); |
| 148 | } |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public String toString() { |
| 154 | return toStringHelper(this).add("tableName", tableName) |
| 155 | .add("columns", columns).toString(); |
| 156 | } |
| 157 | } |