2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.message;
10 import java.util.Collections;
11 import java.util.List;
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;
18 import com.google.common.collect.Lists;
21 * Structure of Request Message.
23 * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.4">Request Message</a>
25 public class PCEPRequestMessage implements Message {
27 private final List<CompositeRequestSvecObject> svecList;
29 private final List<CompositeRequestObject> requests;
31 private final List<PCEPObject> objects;
34 * Constructs new Request Message.
36 * @throws IllegalArgumentException if there is not even one {@link CompositeRequestObject} in the list.
38 * @param requests List<CompositeRequestObject>. Can't be empty or null.
40 public PCEPRequestMessage(final List<CompositeRequestObject> requests) {
45 * Constructs new Request Message.
47 * @throws IllegalArgumentException if there is not even one {@link CompositeRequestObject} in the list.
49 * @param svecList List<CompositeSvecObject>
50 * @param requests List<CompositeRequestObject>. Can't be null or empty.
52 public PCEPRequestMessage(final List<CompositeRequestSvecObject> svecList, final List<CompositeRequestObject> requests) {
53 this.objects = Lists.newArrayList();
55 for (final CompositeRequestSvecObject cso : svecList) {
56 this.objects.addAll(cso.getCompositeAsList());
59 for (final CompositeRequestObject cro : requests) {
60 this.objects.addAll(cro.getCompositeAsList());
64 this.svecList = svecList;
66 this.svecList = Collections.emptyList();
68 if (requests == null || requests.isEmpty())
69 throw new IllegalArgumentException("At least one CompositeRequestObject is mandatory.");
70 this.requests = requests;
75 * Gets list of {@link CompositeRequestSvecObject}.
77 * @return List<CompositeSvecObject>. Can't be null, but may be empty.
79 public List<CompositeRequestSvecObject> getSvecObjects() {
84 * Gets list of {@link CompositeRequestObject}.
86 * @return List<CompositeRequestObject>. Can't be null or empty.
88 public List<CompositeRequestObject> getRequests() {
92 public List<PCEPObject> getAllObjects() {
97 public int hashCode() {
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());
106 public boolean equals(final Object obj) {
109 if (!super.equals(obj))
111 if (this.getClass() != obj.getClass())
113 final PCEPRequestMessage other = (PCEPRequestMessage) obj;
114 if (this.requests == null) {
115 if (other.requests != null)
117 } else if (!this.requests.equals(other.requests))
119 if (this.svecList == null) {
120 if (other.svecList != null)
122 } else if (!this.svecList.equals(other.svecList))
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);
135 return builder.toString();