Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPNotificationObject.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 package org.opendaylight.protocol.pcep.object;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.protocol.pcep.PCEPObject;
14 import org.opendaylight.protocol.pcep.PCEPTlv;
15 import com.google.common.base.Objects.ToStringHelper;
16
17 /**
18  * Structure of PCEP Notification Object.
19  *
20  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.14">PCEP
21  *      Notification Object</a>
22  */
23 public class PCEPNotificationObject extends PCEPObject {
24
25     private final short type;
26
27     private final short value;
28
29     private List<PCEPTlv> tlvs;
30
31     /**
32      * Constructs PCEP Notification Object only with mandatory values.
33      *
34      * @param type
35      *            short
36      * @param value
37      *            short
38      */
39     public PCEPNotificationObject(short type, short value) {
40         this(type, value, null);
41     }
42
43     /**
44      * Constructs PCEP Notification Object also with optional Objects.
45      *
46      * @param type
47      *            short
48      * @param value
49      *            short
50      * @param tlvs
51      *            List<PCEPTlv>
52      */
53     public PCEPNotificationObject(short type, short value, List<PCEPTlv> tlvs) {
54         super(false, false);
55         this.type = type;
56         this.value = value;
57         if (tlvs != null)
58             this.tlvs = tlvs;
59         else
60             this.tlvs = Collections.emptyList();
61     }
62
63     /**
64      * Returns short representation of Type.
65      *
66      * @return short
67      */
68     public short getType() {
69         return this.type;
70     }
71
72     /**
73      * Returns short value.
74      *
75      * @return short
76      */
77     public short getValue() {
78         return this.value;
79     }
80
81     /**
82      * Gets list of {@link PCEPTlv}
83      *
84      * @return List<PCEPTlv>. Can't be null, but may be empty.
85      */
86     public List<PCEPTlv> getTlvs() {
87         return this.tlvs;
88     }
89
90     @Override
91     public int hashCode() {
92         final int prime = 31;
93         int result = super.hashCode();
94         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
95         result = prime * result + this.type;
96         result = prime * result + this.value;
97         return result;
98     }
99
100     @Override
101     public boolean equals(Object obj) {
102         if (this == obj)
103             return true;
104         if (!super.equals(obj))
105             return false;
106         if (this.getClass() != obj.getClass())
107             return false;
108         final PCEPNotificationObject other = (PCEPNotificationObject) obj;
109         if (this.tlvs == null) {
110             if (other.tlvs != null)
111                 return false;
112         } else if (!this.tlvs.equals(other.tlvs))
113             return false;
114         if (this.type != other.type)
115             return false;
116         if (this.value != other.value)
117             return false;
118         return true;
119     }
120
121     @Override
122         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
123                 toStringHelper.add("type", this.type);
124                 toStringHelper.add("value", this.value);
125                 toStringHelper.add("tlvs", this.tlvs);
126                 return super.addToStringAttributes(toStringHelper);
127         }
128 }