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();
54 if (svecList != null) {
55 for (final CompositeRequestSvecObject cso : svecList) {
56 this.objects.addAll(cso.getCompositeAsList());
59 if (requests != null) {
60 for (final CompositeRequestObject cro : requests) {
61 this.objects.addAll(cro.getCompositeAsList());
65 if (svecList != null) {
66 this.svecList = svecList;
68 this.svecList = Collections.emptyList();
71 if (requests == null || requests.isEmpty()) {
72 throw new IllegalArgumentException("At least one CompositeRequestObject is mandatory.");
74 this.requests = requests;
79 * Gets list of {@link CompositeRequestSvecObject}.
81 * @return List<CompositeSvecObject>. Can't be null, but may be empty.
83 public List<CompositeRequestSvecObject> getSvecObjects() {
88 * Gets list of {@link CompositeRequestObject}.
90 * @return List<CompositeRequestObject>. Can't be null or empty.
92 public List<CompositeRequestObject> getRequests() {
96 public List<PCEPObject> getAllObjects() {
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());
110 public boolean equals(final Object obj) {
114 if (!super.equals(obj)) {
117 if (this.getClass() != obj.getClass()) {
120 final PCEPRequestMessage other = (PCEPRequestMessage) obj;
121 if (this.requests == null) {
122 if (other.requests != null) {
125 } else if (!this.requests.equals(other.requests)) {
128 if (this.svecList == null) {
129 if (other.svecList != null) {
132 } else if (!this.svecList.equals(other.svecList)) {
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);
146 return builder.toString();
150 public Class<Message> getImplementedInterface() {
151 return Message.class;