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