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.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPMessage;
15 import org.opendaylight.protocol.pcep.PCEPObject;
16 import org.opendaylight.protocol.pcep.object.CompositeReplySvecObject;
17 import org.opendaylight.protocol.pcep.object.CompositeResponseObject;
20 * Structure for Reply Message.
22 * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.5">Reply
25 public class PCEPReplyMessage extends PCEPMessage {
27 private static final long serialVersionUID = -4604680426345882626L;
29 private final List<CompositeReplySvecObject> svecList;
31 private final List<CompositeResponseObject> responses;
34 * Constructs new Reply Message.
36 * @throws IllegalArgumentException
37 * if there is not even one {@link CompositeResponseObject} in
41 * List<CompositeResponseObject>. Can't be empty or null.
43 public PCEPReplyMessage(final List<CompositeResponseObject> responses) {
44 this(responses, null);
48 * Constructs {@link PCEPReplyMessage}.
50 * @throws IllegalArgumentException
51 * if there is not even one {@link CompositeResponseObject} in
55 * List<CompositeSvecObject>
57 * List<CompositeResponseObject>. Can't be empty or null.
59 public PCEPReplyMessage(final List<CompositeResponseObject> responses, final List<CompositeReplySvecObject> svecList) {
60 super(new ArrayList<PCEPObject>() {
62 private static final long serialVersionUID = 4464502017081110298L;
66 for (final CompositeReplySvecObject cno : svecList) {
67 this.addAll(cno.getCompositeAsList());
69 if (responses != null)
70 for (final CompositeResponseObject cno : responses) {
71 this.addAll(cno.getCompositeAsList());
76 if (responses == null || responses.isEmpty())
77 throw new IllegalArgumentException("At least one CompositeResponseObject is mandatory.");
78 this.responses = responses;
81 this.svecList = svecList;
83 this.svecList = Collections.emptyList();
87 * Gets list of {@link CompositeResponseObject}.
89 * @return List<CompositeResponseObject>. Can't be null or empty.
91 public List<CompositeResponseObject> getResponses() {
92 return this.responses;
96 * Gets list of {@link CompositeReplySvecObject}.
98 * @return List<CompositeReplySvecObject>. Can't be null but may be empty.
100 public List<CompositeReplySvecObject> getSvecList() {
101 return this.svecList;
105 public int hashCode() {
106 final int prime = 31;
107 int result = super.hashCode();
108 result = prime * result + ((this.responses == null) ? 0 : this.responses.hashCode());
109 result = prime * result + ((this.svecList == null) ? 0 : this.svecList.hashCode());
114 public boolean equals(Object obj) {
117 if (!super.equals(obj))
119 if (this.getClass() != obj.getClass())
121 final PCEPReplyMessage other = (PCEPReplyMessage) obj;
122 if (this.responses == null) {
123 if (other.responses != null)
125 } else if (!this.responses.equals(other.responses))
127 if (this.svecList == null) {
128 if (other.svecList != null)
130 } else if (!this.svecList.equals(other.svecList))
136 public String toString() {
137 final StringBuilder builder = new StringBuilder();
138 builder.append("PCEPReplyMessage [svecList=");
139 builder.append(this.svecList);
140 builder.append(", responses=");
141 builder.append(this.responses);
143 return builder.toString();