BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPNotificationMessage.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.message;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.pcep.PCEPObject;
13 import org.opendaylight.protocol.pcep.object.CompositeNotifyObject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
15
16 import com.google.common.collect.Lists;
17
18 /**
19  * Structure of Notification Message.
20  * 
21  * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.6">Notification Message</a>
22  */
23 public class PCEPNotificationMessage implements Message {
24
25         private final List<CompositeNotifyObject> notifications;
26
27         private final List<PCEPObject> objects;
28
29         /**
30          * Constructs new Notification Message.
31          * 
32          * @throws IllegalArgumentException if there is not even one {@link CompositeNotifyObject} in the list.
33          * 
34          * @param notifications List<CompositeNotifyObject>. Can't be empty or null.
35          */
36         public PCEPNotificationMessage(final List<CompositeNotifyObject> notifications) {
37                 this.objects = Lists.newArrayList();
38                 if (notifications != null) {
39                         for (final CompositeNotifyObject cno : notifications) {
40                                 this.objects.addAll(cno.getCompositeAsList());
41                         }
42                 }
43                 if (notifications == null || notifications.isEmpty())
44                         throw new IllegalArgumentException("At least one CompositeNotifyObject is mandatory.");
45
46                 this.notifications = notifications;
47         }
48
49         /**
50          * Gets list of {@link org.opendaylight.protocol.pcep.object.CompositeNotifyObject CompositeNotifyObjects}.
51          * 
52          * @return List<CompositeNotifyObject>. Can't be null or empty.
53          */
54         public List<CompositeNotifyObject> getNotifications() {
55                 return this.notifications;
56         }
57
58         public List<PCEPObject> getAllObjects() {
59                 return this.objects;
60         }
61
62         @Override
63         public int hashCode() {
64                 final int prime = 31;
65                 int result = super.hashCode();
66                 result = prime * result + ((this.notifications == null) ? 0 : this.notifications.hashCode());
67                 return result;
68         }
69
70         @Override
71         public boolean equals(final Object obj) {
72                 if (this == obj)
73                         return true;
74                 if (!super.equals(obj))
75                         return false;
76                 if (this.getClass() != obj.getClass())
77                         return false;
78                 final PCEPNotificationMessage other = (PCEPNotificationMessage) obj;
79                 if (this.notifications == null) {
80                         if (other.notifications != null)
81                                 return false;
82                 } else if (!this.notifications.equals(other.notifications))
83                         return false;
84                 return true;
85         }
86
87         @Override
88         public String toString() {
89                 final StringBuilder builder = new StringBuilder();
90                 builder.append("PCEPNotificationMessage [notifications=");
91                 builder.append(this.notifications);
92                 builder.append("]");
93                 return builder.toString();
94         }
95 }