Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPReplyMessage.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.message;
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.object.CompositeReplySvecObject;
15 import org.opendaylight.protocol.pcep.object.CompositeResponseObject;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
17
18 import com.google.common.collect.Lists;
19
20 /**
21  * Structure for Reply Message.
22  * 
23  * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.5">Reply Message</a>
24  */
25 public class PCEPReplyMessage implements Message {
26
27         private final List<CompositeReplySvecObject> svecList;
28
29         private final List<CompositeResponseObject> responses;
30
31         private final List<PCEPObject> objects;
32
33         /**
34          * Constructs new Reply Message.
35          * 
36          * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list.
37          * 
38          * @param responses List<CompositeResponseObject>. Can't be empty or null.
39          */
40         public PCEPReplyMessage(final List<CompositeResponseObject> responses) {
41                 this(responses, null);
42         }
43
44         /**
45          * Constructs {@link PCEPReplyMessage}.
46          * 
47          * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list.
48          * 
49          * @param svecList List<CompositeSvecObject>
50          * @param responses List<CompositeResponseObject>. Can't be empty or null.
51          */
52         public PCEPReplyMessage(final List<CompositeResponseObject> responses, final List<CompositeReplySvecObject> svecList) {
53                 this.objects = Lists.newArrayList();
54                 if (svecList != null) {
55                         for (final CompositeReplySvecObject cno : svecList) {
56                                 this.objects.addAll(cno.getCompositeAsList());
57                         }
58                 }
59                 if (responses != null) {
60                         for (final CompositeResponseObject cno : responses) {
61                                 this.objects.addAll(cno.getCompositeAsList());
62                         }
63                 }
64
65                 if (responses == null || responses.isEmpty()) {
66                         throw new IllegalArgumentException("At least one CompositeResponseObject is mandatory.");
67                 }
68                 this.responses = responses;
69
70                 if (svecList != null) {
71                         this.svecList = svecList;
72                 } else {
73                         this.svecList = Collections.emptyList();
74                 }
75         }
76
77         /**
78          * Gets list of {@link CompositeResponseObject}.
79          * 
80          * @return List<CompositeResponseObject>. Can't be null or empty.
81          */
82         public List<CompositeResponseObject> getResponses() {
83                 return this.responses;
84         }
85
86         /**
87          * Gets list of {@link CompositeReplySvecObject}.
88          * 
89          * @return List<CompositeReplySvecObject>. Can't be null but may be empty.
90          */
91         public List<CompositeReplySvecObject> getSvecList() {
92                 return this.svecList;
93         }
94
95         public List<PCEPObject> getAllObjects() {
96                 return this.objects;
97         }
98
99         @Override
100         public int hashCode() {
101                 final int prime = 31;
102                 int result = super.hashCode();
103                 result = prime * result + ((this.responses == null) ? 0 : this.responses.hashCode());
104                 result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode());
105                 return result;
106         }
107
108         @Override
109         public boolean equals(final Object obj) {
110                 if (this == obj) {
111                         return true;
112                 }
113                 if (!super.equals(obj)) {
114                         return false;
115                 }
116                 if (this.getClass() != obj.getClass()) {
117                         return false;
118                 }
119                 final PCEPReplyMessage other = (PCEPReplyMessage) obj;
120                 if (this.responses == null) {
121                         if (other.responses != null) {
122                                 return false;
123                         }
124                 } else if (!this.responses.equals(other.responses)) {
125                         return false;
126                 }
127                 if (this.svecList == null) {
128                         if (other.svecList != null) {
129                                 return false;
130                         }
131                 } else if (!this.svecList.equals(other.svecList)) {
132                         return false;
133                 }
134                 return true;
135         }
136
137         @Override
138         public String toString() {
139                 final StringBuilder builder = new StringBuilder();
140                 builder.append("PCEPReplyMessage [svecList=");
141                 builder.append(this.svecList);
142                 builder.append(", responses=");
143                 builder.append(this.responses);
144                 builder.append("]");
145                 return builder.toString();
146         }
147
148         @Override
149         public Class<Message> getImplementedInterface() {
150                 return Message.class;
151         }
152 }