BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPUpdateRequestMessage.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.List;
11
12 import org.opendaylight.protocol.pcep.PCEPObject;
13 import org.opendaylight.protocol.pcep.object.CompositeUpdateRequestObject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
15
16 import com.google.common.collect.Lists;
17
18 /**
19  * Structure of Update Request Message.
20  * 
21  * @see <a href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-6.2">Update Request Message</a>
22  */
23 public class PCEPUpdateRequestMessage implements Message {
24
25         private final List<CompositeUpdateRequestObject> updateRequests;
26
27         private final List<PCEPObject> objects;
28
29         /**
30          * Constructs new Update Request Message.
31          * 
32          * @throws IllegalArgumentException if there is not even one {@link CompositeUpdateRequestObject} in the list.
33          * 
34          * @param updateRequests List<CompositeUpdateRequestObject>. Can't be empty or null.
35          */
36         public PCEPUpdateRequestMessage(final List<CompositeUpdateRequestObject> updateRequests) {
37                 this.objects = Lists.newArrayList();
38                 if (updateRequests != null)
39                         for (final CompositeUpdateRequestObject curo : updateRequests) {
40                                 this.objects.addAll(curo.getCompositeAsList());
41                         }
42
43                 if (updateRequests == null || updateRequests.isEmpty())
44                         throw new IllegalArgumentException("At least one CompositeUpdateRequestObject is mandatory.");
45                 this.updateRequests = updateRequests;
46         }
47
48         /**
49          * Gets list of {@link CompositeUpdateRequestObject}.
50          * 
51          * @return List<CompositeUpdateRequestObject>. Can't be null or empty.
52          */
53         public List<CompositeUpdateRequestObject> getUpdateRequests() {
54                 return this.updateRequests;
55         }
56
57         public List<PCEPObject> getAllObjects() {
58                 return this.objects;
59         }
60
61         @Override
62         public int hashCode() {
63                 final int prime = 31;
64                 int result = super.hashCode();
65                 result = prime * result + ((this.updateRequests == null) ? 0 : this.updateRequests.hashCode());
66                 return result;
67         }
68
69         @Override
70         public boolean equals(final Object obj) {
71                 if (this == obj)
72                         return true;
73                 if (!super.equals(obj))
74                         return false;
75                 if (this.getClass() != obj.getClass())
76                         return false;
77                 final PCEPUpdateRequestMessage other = (PCEPUpdateRequestMessage) obj;
78                 if (this.updateRequests == null) {
79                         if (other.updateRequests != null)
80                                 return false;
81                 } else if (!this.updateRequests.equals(other.updateRequests))
82                         return false;
83                 return true;
84         }
85
86         @Override
87         public String toString() {
88                 final StringBuilder builder = new StringBuilder();
89                 builder.append("PCEPUpdateRequestMessage [updateRequests=");
90                 builder.append(this.updateRequests);
91                 builder.append("]");
92                 return builder.toString();
93         }
94 }