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