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 |
Sho SHIMIZU | 3895cc3 | 2015-10-13 10:52:22 -0700 | [diff] [blame] | 46 | * @deprecated in Emu Release |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 47 | */ |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 48 | @Deprecated |
| 49 | private Row(String tableName) { |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 50 | checkNotNull(tableName, "tableName cannot be null"); |
| 51 | this.tableName = tableName; |
| 52 | this.columns = Maps.newHashMap(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Row constructor. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 57 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 58 | * @param tableName table name |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 59 | * @param columns Map of Column entity |
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 60 | * @param uuid UUID of the row |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 61 | */ |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 62 | public Row(String tableName, UUID uuid, Map<String, Column> columns) { |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 63 | checkNotNull(tableName, "table name cannot be null"); |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 64 | checkNotNull(uuid, "uuid cannot be null"); |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 65 | checkNotNull(columns, "columns cannot be null"); |
| 66 | this.tableName = tableName; |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 67 | this.uuid = uuid; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 68 | this.columns = columns; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns tableName. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 73 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 74 | * @return tableName |
| 75 | */ |
| 76 | public String tableName() { |
| 77 | return tableName; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set tableName value. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 82 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 83 | * @param tableName table name |
| 84 | */ |
| 85 | public void setTableName(String tableName) { |
| 86 | this.tableName = tableName; |
| 87 | } |
| 88 | |
| 89 | /** |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 90 | * Returns uuid. |
| 91 | * |
| 92 | * @return uuid |
| 93 | */ |
| 94 | public UUID uuid() { |
| 95 | return uuid; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Sets uuid value. |
| 100 | * |
| 101 | * @param uuid new uuid |
| 102 | */ |
| 103 | public void setUuid(UUID uuid) { |
| 104 | this.uuid = uuid; |
| 105 | } |
| 106 | |
| 107 | /** |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 108 | * Returns Column by ColumnSchema. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 109 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 110 | * @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. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 119 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 120 | * @return Collection of Column |
| 121 | */ |
| 122 | public Collection<Column> getColumns() { |
| 123 | return columns.values(); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * add Column. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 128 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 129 | * @param columnName column name |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 130 | * @param data Column entity |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 131 | */ |
| 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 | } |