blob: 5fa56c2c6347a7b36cfc7ac8666afa679cecd7b8 [file] [log] [blame]
Yuta HIGUCHI66ca1bf2014-03-12 18:34:09 -07001package net.onrc.onos.datastore.ramcloud;
2
3import java.util.Objects;
4
5import net.onrc.onos.datastore.IKVTableID;
6
7public class RCTableID implements IKVTableID {
8 private final String tableName;
9 private long tableID;
10
11 public RCTableID(String tableName) {
12 this.tableName = tableName;
13 this.tableID = 0;
14 }
15
16 @Override
17 public String getTableName() {
18 return tableName;
19 }
20
21 // following is RAMCloud specific
22
23 public long getTableID() {
24 if ( tableID != 0) {
25 return tableID;
26 }
27 tableID = RCClient.getJRamCloudClient().createTable(tableName);
28 return tableID;
29 }
30
31 void resetTableID() {
32 this.tableID = 0;
33 }
34
35 @Override
36 public String toString() {
37 return "["+tableName + "]@" + getTableID();
38 }
39
40 @Override
41 public int hashCode() {
42 return Objects.hash(tableName, getTableID());
43 }
44
45 @Override
46 public boolean equals(Object obj) {
47 if (this == obj)
48 return true;
49 if (obj == null)
50 return false;
51 if (getClass() != obj.getClass())
52 return false;
53 RCTableID other = (RCTableID) obj;
54 return Objects.equals(tableName, other.tableName)
55 && Objects.equals(getTableID(), other.getTableID());
56 }
57}