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();
55 for (final CompositeReplySvecObject cno : svecList) {
56 this.objects.addAll(cno.getCompositeAsList());
58 if (responses != null)
59 for (final CompositeResponseObject cno : responses) {
60 this.objects.addAll(cno.getCompositeAsList());
63 if (responses == null || responses.isEmpty())
64 throw new IllegalArgumentException("At least one CompositeResponseObject is mandatory.");
65 this.responses = responses;
68 this.svecList = svecList;
70 this.svecList = Collections.emptyList();
74 * Gets list of {@link CompositeResponseObject}.
76 * @return List<CompositeResponseObject>. Can't be null or empty.
78 public List<CompositeResponseObject> getResponses() {
79 return this.responses;
83 * Gets list of {@link CompositeReplySvecObject}.
85 * @return List<CompositeReplySvecObject>. Can't be null but may be empty.
87 public List<CompositeReplySvecObject> getSvecList() {
91 public List<PCEPObject> getAllObjects() {
96 public int hashCode() {
98 int result = super.hashCode();
99 result = prime * result + ((this.responses == null) ? 0 : this.responses.hashCode());
100 result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode());
105 public boolean equals(final Object obj) {
108 if (!super.equals(obj))
110 if (this.getClass() != obj.getClass())
112 final PCEPReplyMessage other = (PCEPReplyMessage) obj;
113 if (this.responses == null) {
114 if (other.responses != null)
116 } else if (!this.responses.equals(other.responses))
118 if (this.svecList == null) {
119 if (other.svecList != null)
121 } else if (!this.svecList.equals(other.svecList))
127 public String toString() {
128 final StringBuilder builder = new StringBuilder();
129 builder.append("PCEPReplyMessage [svecList=");
130 builder.append(this.svecList);
131 builder.append(", responses=");
132 builder.append(this.responses);
134 return builder.toString();