BUG-54 : switched channel pipeline to be protocol specific.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / PCEPMessage.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;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.framework.ProtocolMessage;
13
14 /**
15  * Basic structure for PCEP Message. Cannot be instantiated directly. Current PCEP version is 1. Each message contains a
16  * list of PCEP objects.
17  * 
18  */
19 public abstract class PCEPMessage implements ProtocolMessage {
20
21         private static final long serialVersionUID = 4293319459468168384L;
22
23         /**
24          * Current supported version of PCEP.
25          */
26         public static final int PCEP_VERSION = 1;
27
28         private final List<PCEPObject> objects;
29
30         /**
31          * Constructor is protected to prevent direct instantiation, but to allow to call this constructor via super().
32          * 
33          * @param objects
34          */
35         protected PCEPMessage(final List<PCEPObject> objects) {
36                 if (objects.contains(null))
37                         throw new IllegalArgumentException("Object list contains null element at offset " + objects.indexOf(null));
38
39                 this.objects = objects;
40         }
41
42         /**
43          * Returns list of all objects that the message contains
44          * 
45          * @return list of all objects that the message contains
46          */
47         public List<PCEPObject> getAllObjects() {
48                 return this.objects;
49         }
50
51         @Override
52         public int hashCode() {
53                 final int prime = 31;
54                 int result = 1;
55                 result = prime * result + ((this.objects == null) ? 0 : this.objects.hashCode());
56                 return result;
57         }
58
59         @Override
60         public boolean equals(final Object obj) {
61                 if (this == obj)
62                         return true;
63                 if (obj == null)
64                         return false;
65                 if (this.getClass() != obj.getClass())
66                         return false;
67                 final PCEPMessage other = (PCEPMessage) obj;
68                 if (this.objects == null) {
69                         if (other.objects != null)
70                                 return false;
71                 } else if (!this.objects.equals(other.objects))
72                         return false;
73                 return true;
74         }
75
76         @Override
77         public String toString() {
78                 final StringBuilder builder = new StringBuilder();
79                 builder.append("PCEPMessage [objects=");
80                 builder.append(this.objects);
81                 builder.append("]");
82                 return builder.toString();
83         }
84
85 }