Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 1 | package org.onosproject.store.service; |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 2 | |
Yuta HIGUCHI | cea3ba1 | 2014-11-05 18:18:08 -0800 | [diff] [blame] | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
| 4 | |
Yuta HIGUCHI | 4ee9ddb | 2014-11-05 18:28:57 -0800 | [diff] [blame] | 5 | import java.util.Objects; |
| 6 | |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 7 | import com.google.common.base.MoreObjects; |
| 8 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 9 | /** |
| 10 | * Database read request. |
| 11 | */ |
| 12 | public class ReadRequest { |
| 13 | |
| 14 | private final String tableName; |
| 15 | private final String key; |
| 16 | |
Yuta HIGUCHI | cea3ba1 | 2014-11-05 18:18:08 -0800 | [diff] [blame] | 17 | /** |
| 18 | * Creates a read request, |
| 19 | * which will retrieve the specified key from the table. |
| 20 | * |
| 21 | * @param tableName name of the table |
| 22 | * @param key key in the table |
| 23 | * @return ReadRequest |
| 24 | */ |
| 25 | public static ReadRequest get(String tableName, String key) { |
| 26 | return new ReadRequest(tableName, key); |
| 27 | } |
| 28 | |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 29 | public ReadRequest(String tableName, String key) { |
Yuta HIGUCHI | cea3ba1 | 2014-11-05 18:18:08 -0800 | [diff] [blame] | 30 | this.tableName = checkNotNull(tableName); |
| 31 | this.key = checkNotNull(key); |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Return the name of the table. |
| 36 | * @return table name. |
| 37 | */ |
| 38 | public String tableName() { |
| 39 | return tableName; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns the key. |
| 44 | * @return key. |
| 45 | */ |
| 46 | public String key() { |
| 47 | return key; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
Yuta HIGUCHI | 5e1cfe0 | 2014-11-04 21:22:45 -0800 | [diff] [blame] | 52 | return MoreObjects.toStringHelper(getClass()) |
| 53 | .add("tableName", tableName) |
| 54 | .add("key", key) |
| 55 | .toString(); |
Madan Jampani | 08822c4 | 2014-11-04 17:17:46 -0800 | [diff] [blame] | 56 | } |
Yuta HIGUCHI | 4ee9ddb | 2014-11-05 18:28:57 -0800 | [diff] [blame] | 57 | |
| 58 | @Override |
| 59 | public int hashCode() { |
| 60 | return Objects.hash(key, tableName); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj == null) { |
| 69 | return false; |
| 70 | } |
| 71 | if (getClass() != obj.getClass()) { |
| 72 | return false; |
| 73 | } |
| 74 | ReadRequest other = (ReadRequest) obj; |
| 75 | return Objects.equals(this.key, other.key) && |
| 76 | Objects.equals(this.tableName, other.tableName); |
| 77 | } |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 78 | } |