Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPLspObject.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 LSP Object.
19  *
20  * @see <a
21  *      href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-8.3">PCEP
22  *      LSP Object</a>
23  */
24 public class PCEPLspObject extends PCEPObject {
25
26     private final int lspID;
27
28     private final boolean delegate;
29
30     private final boolean sync;
31
32     private final boolean operational;
33
34     private final boolean remove;
35
36     private final List<PCEPTlv> tlvs;
37
38     /**
39      * Constructs PCEP LSP Object only with mandatory values.
40      *
41      * @param lspID
42      *            int
43      * @param delegate
44      *            boolean
45      * @param sync
46      *            boolean
47      * @param operational
48      *            boolean
49      * @param remove
50      *            boolean
51      */
52     public PCEPLspObject(int lspID, boolean delegate, boolean sync, boolean operational, boolean remove) {
53         this(lspID, delegate, sync, operational, remove, null);
54     }
55
56     /**
57      * Constructs PCEP LSP Object also with optional Objects.
58      *
59      * @param lspID
60      *            int
61      * @param delegate
62      *            boolean
63      * @param sync
64      *            boolean
65      * @param operational
66      *            boolean
67      * @param remove
68      *            boolean
69      * @param tlvs
70      *            List<PCEPTlv>
71      */
72     public PCEPLspObject(int lspID, boolean delegate, boolean sync, boolean operational, boolean remove, List<PCEPTlv> tlvs) {
73         super(false, false);
74         this.lspID = lspID;
75         this.delegate = delegate;
76         this.sync = sync;
77         this.operational = operational;
78         this.remove = remove;
79         if (tlvs != null)
80             this.tlvs = tlvs;
81         else
82             this.tlvs = Collections.emptyList();
83     }
84
85     /**
86      * Gets integer representation of LSP ID.
87      *
88      * @return int
89      */
90     public int getLspID() {
91         return this.lspID;
92     }
93
94     /**
95      * Gets Delegate flag.
96      *
97      * @return boolean
98      */
99     public boolean isDelegate() {
100         return this.delegate;
101     }
102
103     /**
104      * Gets Sync flag.
105      *
106      * @return boolean
107      */
108     public boolean isSync() {
109         return this.sync;
110     }
111
112     /**
113      * Gets Operational flag.
114      *
115      * @return boolean
116      */
117     public boolean isOperational() {
118         return this.operational;
119     }
120
121     /**
122      * Gets Remove flag.
123      *
124      * @return boolean
125      */
126     public boolean isRemove() {
127         return this.remove;
128     }
129
130     /**
131      * Gets list of {@link PCEPTlv}
132      *
133      * @return List<PCEPTlv>. Can't be null, but may be empty.
134      */
135     public List<PCEPTlv> getTlvs() {
136         return this.tlvs;
137     }
138
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = super.hashCode();
143         result = prime * result + (this.delegate ? 1231 : 1237);
144         result = prime * result + this.lspID;
145         result = prime * result + (this.operational ? 1231 : 1237);
146         result = prime * result + (this.remove ? 1231 : 1237);
147         result = prime * result + (this.sync ? 1231 : 1237);
148         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
149         return result;
150     }
151
152     @Override
153     public boolean equals(Object obj) {
154         if (this == obj)
155             return true;
156         if (!super.equals(obj))
157             return false;
158         if (this.getClass() != obj.getClass())
159             return false;
160         final PCEPLspObject other = (PCEPLspObject) obj;
161         if (this.delegate != other.delegate)
162             return false;
163         if (this.lspID != other.lspID)
164             return false;
165         if (this.operational != other.operational)
166             return false;
167         if (this.remove != other.remove)
168             return false;
169         if (this.sync != other.sync)
170             return false;
171         if (this.tlvs == null) {
172             if (other.tlvs != null)
173                 return false;
174         } else if (!this.tlvs.equals(other.tlvs))
175             return false;
176         return true;
177     }
178
179         @Override
180         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
181                 toStringHelper.add("lspID", this.lspID);
182                 toStringHelper.add("delegate", this.delegate);
183                 toStringHelper.add("sync", this.sync);
184                 toStringHelper.add("operational", this.operational);
185                 toStringHelper.add("remove", this.remove);
186                 toStringHelper.add("tlvs", this.tlvs);
187                 return super.addToStringAttributes(toStringHelper);
188         }
189 }