2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.gates.impl;
7 import org.pcmm.base.impl.PCMMBaseObject;
8 import org.pcmm.gates.ISubscriberID;
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
14 * Implementation of the ISubscriberID interface
16 public class SubscriberID extends PCMMBaseObject implements ISubscriberID {
19 * The source IPv4 or IPv6 address
21 private final InetAddress srcIp;
25 * @param srcIp - the source host address
27 public SubscriberID(final InetAddress srcIp) {
28 super(SNum.SUBSCRIBER_ID, STYPE);
29 if (srcIp == null) throw new IllegalArgumentException("srcIp must not be null");
34 public InetAddress getSourceIPAddress() {
39 protected byte[] getBytes() {
40 return srcIp.getAddress();
44 public boolean equals(final Object o) {
48 if (!(o instanceof SubscriberID)) {
51 if (!super.equals(o)) {
54 final SubscriberID that = (SubscriberID) o;
55 return srcIp.equals(that.srcIp);
59 public int hashCode() {
60 int result = super.hashCode();
61 result = 31 * result + srcIp.hashCode();
66 * Returns a SubscriberID object from a byte array
67 * @param data - the data to parse
68 * @return - the object or null if cannot be parsed
69 * TODO - make me more robust as RuntimeExceptions can be thrown here.
71 public static SubscriberID parse(final byte[] data) {
73 return new SubscriberID(InetAddress.getByAddress(data));
74 } catch (UnknownHostException e) {