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.object;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPObject;
17 * Structure that combines set of related objects.
19 * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.6">Notification
20 * (PCNtf) Message</a> - <notify>
22 public class CompositeNotifyObject {
24 private List<PCEPRequestParameterObject> requestParameters;
26 private final List<PCEPNotificationObject> notifications;
29 * Constructs basic composite object only with mandatory objects.
31 * @param notifications
32 * List<PCEPNotificationObject>. Can't be null or empty.
34 public CompositeNotifyObject(List<PCEPNotificationObject> notifications) {
35 this(null, notifications);
39 * Constructs composite object with optional objects.
41 * @param requestParameters
42 * List<PCEPRequestParameterObject>
43 * @param notifications
44 * List<PCEPNotificationObject>. Can't be null or empty.
46 public CompositeNotifyObject(List<PCEPRequestParameterObject> requestParameters, List<PCEPNotificationObject> notifications) {
47 if (notifications == null || notifications.isEmpty())
48 throw new IllegalArgumentException("Notification Object is mandatory.");
49 if (requestParameters != null)
50 this.requestParameters = requestParameters;
52 this.requestParameters = Collections.emptyList();
53 this.notifications = notifications;
57 * Gets list of all objects, which are in appropriate order.
59 * @return List<PCEPObject>
61 public List<PCEPObject> getCompositeAsList() {
62 final List<PCEPObject> list = new ArrayList<PCEPObject>();
63 if (this.requestParameters != null && !this.requestParameters.isEmpty())
64 list.addAll(this.requestParameters);
65 list.addAll(this.notifications);
70 * Creates this object from a list of PCEPObjects.
71 * @param objects List<PCEPObject> list of PCEPObjects from whose this
72 * object should be created.
73 * @return CompositeNotifyObject
75 public static CompositeNotifyObject getCompositeFromList(List<PCEPObject> objects) {
76 if (objects == null || objects.isEmpty())
77 throw new IllegalArgumentException("List cannot be null or empty.");
79 final List<PCEPRequestParameterObject> requestParameters = new ArrayList<PCEPRequestParameterObject>();
80 final List<PCEPNotificationObject> notifications = new ArrayList<PCEPNotificationObject>();
83 while (!objects.isEmpty()) {
84 final PCEPObject obj = objects.get(0);
88 if (obj instanceof PCEPRequestParameterObject) {
89 requestParameters.add((PCEPRequestParameterObject) obj);
95 if (obj instanceof PCEPNotificationObject) {
96 notifications.add((PCEPNotificationObject) obj);
109 if (notifications.isEmpty())
112 return new CompositeNotifyObject(requestParameters, notifications);
116 * Gets list of {@link PCEPRequestParameterObject}.
118 * @return List<PCEPRequestParameterObject>. Can't be null, but may be
121 public List<PCEPRequestParameterObject> getRequestParameters() {
122 return this.requestParameters;
126 * Gets list of {@link PCEPNotificationObject}.
128 * @return List<PCEPNotificationObject>. Can't be null or empty.
130 public List<PCEPNotificationObject> getNotificationObjects() {
131 return this.notifications;
135 public int hashCode() {
136 final int prime = 31;
138 result = prime * result + ((this.notifications == null) ? 0 : this.notifications.hashCode());
139 result = prime * result + ((this.requestParameters == null) ? 0 : this.requestParameters.hashCode());
144 public boolean equals(Object obj) {
149 if (this.getClass() != obj.getClass())
151 final CompositeNotifyObject other = (CompositeNotifyObject) obj;
152 if (this.notifications == null) {
153 if (other.notifications != null)
155 } else if (!this.notifications.equals(other.notifications))
157 if (this.requestParameters == null) {
158 if (other.requestParameters != null)
160 } else if (!this.requestParameters.equals(other.requestParameters))
166 public String toString() {
167 final StringBuilder builder = new StringBuilder();
168 builder.append("CompositeNotifyObject [requestParameters=");
169 builder.append(this.requestParameters);
170 builder.append(", notifications=");
171 builder.append(this.notifications);
173 return builder.toString();