blob: 6986f13017575d5a8b9cd8309fb755ec68cbc6f0 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08004
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08005/**
6 * The class representing a Caller ID for an ONOS component.
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -07007 * This class is immutable.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008 */
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -07009public final class CallerId {
10 private final String value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011
12 /**
13 * Default constructor.
14 */
Ray Milkey269ffb92014-04-03 14:43:30 -070015 public CallerId() {
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -070016 this.value = null;
Ray Milkey269ffb92014-04-03 14:43:30 -070017 }
18
Jonathan Hart0444d932014-01-22 15:06:17 -080019 /**
20 * Copy constructor
Ray Milkey269ffb92014-04-03 14:43:30 -070021 *
Jonathan Hart0444d932014-01-22 15:06:17 -080022 * @param otherCallerId
23 */
24 public CallerId(CallerId otherCallerId) {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 // Note: make a full copy if we change value to a mutable type
26 value = otherCallerId.value;
Jonathan Hart0444d932014-01-22 15:06:17 -080027 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080028
29 /**
30 * Constructor from a string value.
31 *
32 * @param value the value to use.
33 */
34 public CallerId(String value) {
Ray Milkey269ffb92014-04-03 14:43:30 -070035 this.value = value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080036 }
37
38 /**
39 * Get the value of the Caller ID.
40 *
41 * @return the value of the Caller ID.
42 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080043 @JsonProperty("value")
Ray Milkey269ffb92014-04-03 14:43:30 -070044 public String value() {
45 return value;
46 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080047
48 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080049 * Convert the Caller ID value to a string.
50 *
51 * @return the Caller ID value to a string.
52 */
53 @Override
54 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070055 return value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080056 }
Ray Milkey269ffb92014-04-03 14:43:30 -070057
Jonathan Hart0444d932014-01-22 15:06:17 -080058 @Override
59 public boolean equals(Object other) {
Ray Milkey269ffb92014-04-03 14:43:30 -070060 if (!(other instanceof CallerId)) {
61 return false;
62 }
63
64 CallerId otherCallerId = (CallerId) other;
65
66 return value.equals(otherCallerId.value);
Jonathan Hart0444d932014-01-22 15:06:17 -080067 }
Ray Milkey269ffb92014-04-03 14:43:30 -070068
Jonathan Hart0444d932014-01-22 15:06:17 -080069 @Override
70 public int hashCode() {
Ray Milkey269ffb92014-04-03 14:43:30 -070071 return value.hashCode();
Jonathan Hart0444d932014-01-22 15:06:17 -080072 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080073}