Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPCloseObject.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 Close Object.
19  *
20  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.17">PCEP Close
21  *      Object</a>
22  */
23 public class PCEPCloseObject extends PCEPObject {
24
25         /**
26          * Constants for reasons of closing session.
27          */
28         public enum Reason {
29                 UNKNOWN, EXP_DEADTIMER, MALFORMED_MSG, TOO_MANY_UNKNOWN_REQ_REP, TOO_MANY_UNKNOWN_MSG
30         }
31
32         private final Reason reason;
33
34         private List<PCEPTlv> tlvs;
35
36         /**
37          * Constructs Close Object only with mandatory object.
38          *
39          * @param reason
40          *            Reason. Can't be null.
41          */
42         public PCEPCloseObject(Reason reason) {
43                 this(reason, null);
44         }
45
46         /**
47          * Constructs Close Object also with optional objects.
48          *
49          * @param reason
50          *            Reason. Can't be null.
51          * @param tlvs
52          *            List<PCEPTlv>
53          */
54         public PCEPCloseObject(Reason reason, List<PCEPTlv> tlvs) {
55                 super(false, false);
56                 if (reason == null)
57                         throw new IllegalArgumentException("Reason is mandatory.");
58                 this.reason = reason;
59
60                 if (tlvs != null)
61                         this.tlvs = tlvs;
62                 else
63                         this.tlvs = Collections.emptyList();
64         }
65
66         /**
67          * Gets {@link Reason}
68          *
69          * @return Reason. Can't be null.
70          */
71         public Reason getReason() {
72                 return this.reason;
73         }
74
75         /**
76          * Gets list of {@link PCEPTlv}
77          *
78          * @return List<PCEPTlv>. Can't be null, but may be empty.
79          */
80         public List<PCEPTlv> getTlvs() {
81                 return this.tlvs;
82         }
83
84         @Override
85         public int hashCode() {
86                 final int prime = 31;
87                 int result = super.hashCode();
88                 result = prime * result + ((this.reason == null) ? 0 : this.reason.hashCode());
89                 result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
90                 return result;
91         }
92
93         @Override
94         public boolean equals(Object obj) {
95                 if (this == obj)
96                         return true;
97                 if (!super.equals(obj))
98                         return false;
99                 if (this.getClass() != obj.getClass())
100                         return false;
101                 final PCEPCloseObject other = (PCEPCloseObject) obj;
102                 if (this.reason != other.reason)
103                         return false;
104                 if (this.tlvs == null) {
105                         if (other.tlvs != null)
106                                 return false;
107                 } else if (!this.tlvs.equals(other.tlvs))
108                         return false;
109                 return true;
110         }
111
112         @Override
113         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
114                 toStringHelper.add("reason", this.reason);
115                 toStringHelper.add("tlvs", this.tlvs);
116                 return super.addToStringAttributes(toStringHelper);
117         }
118
119 }