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; |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -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 |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 46 | * @param columns Map of Column entity |
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 47 | * @param uuid UUID of the row |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 48 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 49 | public Row(String tableName, Uuid uuid, Map<String, Column> columns) { |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 50 | checkNotNull(tableName, "table name cannot be null"); |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 51 | checkNotNull(uuid, "uuid cannot be null"); |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 52 | checkNotNull(columns, "columns cannot be null"); |
| 53 | this.tableName = tableName; |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 54 | this.uuid = uuid; |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 55 | this.columns = columns; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns tableName. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 60 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 61 | * @return tableName |
| 62 | */ |
| 63 | public String tableName() { |
| 64 | return tableName; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Set tableName value. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 69 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 70 | * @param tableName table name |
| 71 | */ |
| 72 | public void setTableName(String tableName) { |
| 73 | this.tableName = tableName; |
| 74 | } |
| 75 | |
| 76 | /** |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 77 | * Returns uuid. |
| 78 | * |
| 79 | * @return uuid |
| 80 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 81 | public Uuid uuid() { |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 82 | return uuid; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Sets uuid value. |
| 87 | * |
| 88 | * @param uuid new uuid |
| 89 | */ |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 90 | public void setUuid(Uuid uuid) { |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 91 | this.uuid = uuid; |
| 92 | } |
| 93 | |
| 94 | /** |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 95 | * Returns Column by ColumnSchema. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 96 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 97 | * @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. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 106 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 107 | * @return Collection of Column |
| 108 | */ |
| 109 | public Collection<Column> getColumns() { |
| 110 | return columns.values(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * add Column. |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 115 | * |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 116 | * @param columnName column name |
andrea | ed976a4 | 2015-10-05 14:38:25 -0700 | [diff] [blame] | 117 | * @param data Column entity |
Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [diff] [blame] | 118 | */ |
| 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 | } |