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