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.CompositeReplySvecObject;
15 import org.opendaylight.protocol.pcep.object.CompositeResponseObject;
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 for Reply Message.
23 * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.5">Reply Message</a>
25 public class PCEPReplyMessage implements Message {
27 private final List<CompositeReplySvecObject> svecList;
29 private final List<CompositeResponseObject> responses;
31 private final List<PCEPObject> objects;
34 * Constructs new Reply Message.
36 * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list.
38 * @param responses List<CompositeResponseObject>. Can't be empty or null.
40 public PCEPReplyMessage(final List<CompositeResponseObject> responses) {
41 this(responses, null);
45 * Constructs {@link PCEPReplyMessage}.
47 * @throws IllegalArgumentException if there is not even one {@link CompositeResponseObject} in the list.
49 * @param svecList List<CompositeSvecObject>
50 * @param responses List<CompositeResponseObject>. Can't be empty or null.
52 public PCEPReplyMessage(final List<CompositeResponseObject> responses, final List<CompositeReplySvecObject> svecList) {
53 this.objects = Lists.newArrayList();
54 if (svecList != null) {
55 for (final CompositeReplySvecObject cno : svecList) {
56 this.objects.addAll(cno.getCompositeAsList());
59 if (responses != null) {
60 for (final CompositeResponseObject cno : responses) {
61 this.objects.addAll(cno.getCompositeAsList());
65 if (responses == null || responses.isEmpty()) {
66 throw new IllegalArgumentException("At least one CompositeResponseObject is mandatory.");
68 this.responses = responses;
70 if (svecList != null) {
71 this.svecList = svecList;
73 this.svecList = Collections.emptyList();
78 * Gets list of {@link CompositeResponseObject}.
80 * @return List<CompositeResponseObject>. Can't be null or empty.
82 public List<CompositeResponseObject> getResponses() {
83 return this.responses;
87 * Gets list of {@link CompositeReplySvecObject}.
89 * @return List<CompositeReplySvecObject>. Can't be null but may be empty.
91 public List<CompositeReplySvecObject> getSvecList() {
95 public List<PCEPObject> getAllObjects() {
100 public int hashCode() {
101 final int prime = 31;
102 int result = super.hashCode();
103 result = prime * result + ((this.responses == null) ? 0 : this.responses.hashCode());
104 result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode());
109 public boolean equals(final Object obj) {
113 if (!super.equals(obj)) {
116 if (this.getClass() != obj.getClass()) {
119 final PCEPReplyMessage other = (PCEPReplyMessage) obj;
120 if (this.responses == null) {
121 if (other.responses != null) {
124 } else if (!this.responses.equals(other.responses)) {
127 if (this.svecList == null) {
128 if (other.svecList != null) {
131 } else if (!this.svecList.equals(other.svecList)) {
138 public String toString() {
139 final StringBuilder builder = new StringBuilder();
140 builder.append("PCEPReplyMessage [svecList=");
141 builder.append(this.svecList);
142 builder.append(", responses=");
143 builder.append(this.responses);
145 return builder.toString();
149 public Class<Message> getImplementedInterface() {
150 return Message.class;