BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / EROPathKeyWith128PCEIDSubobject.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.protocol.pcep.subobject;
10
11 import java.util.Arrays;
12
13 import com.google.common.base.Objects.ToStringHelper;
14
15 public class EROPathKeyWith128PCEIDSubobject extends ExplicitRouteSubobject {
16
17     private final int pathKey;
18
19     private final byte[] pceId;
20
21     public EROPathKeyWith128PCEIDSubobject(int pathKey, byte[] pceId, boolean loose) {
22         super(loose);
23         this.pathKey = pathKey;
24         if (pceId == null)
25             throw new IllegalArgumentException("PCE ID can't be null.");
26
27         if (pceId.length != 16)
28             throw new IllegalArgumentException("PCE ID is not 16 bytes long.");
29
30         this.pceId = pceId;
31     }
32
33     public int getPathKey() {
34         return this.pathKey;
35     }
36
37     public byte[] getPceId() {
38         return this.pceId;
39     }
40
41     @Override
42     public int hashCode() {
43         final int prime = 31;
44         int result = super.hashCode();
45         result = prime * result + this.pathKey;
46         result = prime * result + Arrays.hashCode(this.pceId);
47         return result;
48     }
49
50     @Override
51     public boolean equals(Object obj) {
52         if (this == obj)
53             return true;
54         if (!super.equals(obj))
55             return false;
56         if (this.getClass() != obj.getClass())
57             return false;
58         final EROPathKeyWith128PCEIDSubobject other = (EROPathKeyWith128PCEIDSubobject) obj;
59         if (this.pathKey != other.pathKey)
60             return false;
61         if (!Arrays.equals(this.pceId, other.pceId))
62             return false;
63         return true;
64     }
65
66     @Override
67         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
68                 toStringHelper.add("pathKey", this.pathKey);
69                 toStringHelper.add("pceId", this.pceId);
70                 return super.addToStringAttributes(toStringHelper);
71         }
72
73 }