BUG-47 : removed PCEPMessage interface, switched to generated Message.
[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                 if (requests != null)
59                         for (final CompositeRequestObject cro : requests) {
60                                 this.objects.addAll(cro.getCompositeAsList());
61                         }
62
63                 if (svecList != null)
64                         this.svecList = svecList;
65                 else
66                         this.svecList = Collections.emptyList();
67
68                 if (requests == null || requests.isEmpty())
69                         throw new IllegalArgumentException("At least one CompositeRequestObject is mandatory.");
70                 this.requests = requests;
71
72         }
73
74         /**
75          * Gets list of {@link CompositeRequestSvecObject}.
76          * 
77          * @return List<CompositeSvecObject>. Can't be null, but may be empty.
78          */
79         public List<CompositeRequestSvecObject> getSvecObjects() {
80                 return this.svecList;
81         }
82
83         /**
84          * Gets list of {@link CompositeRequestObject}.
85          * 
86          * @return List<CompositeRequestObject>. Can't be null or empty.
87          */
88         public List<CompositeRequestObject> getRequests() {
89                 return this.requests;
90         }
91
92         public List<PCEPObject> getAllObjects() {
93                 return this.objects;
94         }
95
96         @Override
97         public int hashCode() {
98                 final int prime = 31;
99                 int result = super.hashCode();
100                 result = prime * result + ((this.requests == null) ? 0 : this.requests.hashCode());
101                 result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode());
102                 return result;
103         }
104
105         @Override
106         public boolean equals(final Object obj) {
107                 if (this == obj)
108                         return true;
109                 if (!super.equals(obj))
110                         return false;
111                 if (this.getClass() != obj.getClass())
112                         return false;
113                 final PCEPRequestMessage other = (PCEPRequestMessage) obj;
114                 if (this.requests == null) {
115                         if (other.requests != null)
116                                 return false;
117                 } else if (!this.requests.equals(other.requests))
118                         return false;
119                 if (this.svecList == null) {
120                         if (other.svecList != null)
121                                 return false;
122                 } else if (!this.svecList.equals(other.svecList))
123                         return false;
124                 return true;
125         }
126
127         @Override
128         public String toString() {
129                 final StringBuilder builder = new StringBuilder();
130                 builder.append("PCEPRequestMessage [svecObjs=");
131                 builder.append(this.svecList);
132                 builder.append(", requests=");
133                 builder.append(this.requests);
134                 builder.append("]");
135                 return builder.toString();
136         }
137
138 }