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