BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPOpenMessage.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.PCEPOpenObject;
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 Open Message.
20  * 
21  * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.2">Open Message</a>
22  */
23 public class PCEPOpenMessage implements Message {
24
25         private final PCEPOpenObject openObj;
26
27         private final List<PCEPObject> objects;
28
29         /**
30          * Constructs new Open Message.
31          * 
32          * @throws IllegalArgumentException if the PCEPOpenObject is null.
33          * 
34          * @param openObj {@link PCEPOpenObject}. Can't be null.
35          */
36         public PCEPOpenMessage(final PCEPOpenObject openObj) {
37                 this.objects = Lists.newArrayList();
38                 if (openObj != null)
39                         this.objects.add(openObj);
40                 else
41                         throw new IllegalArgumentException("PCEPOpenObject is mandatory.");
42
43                 this.openObj = openObj;
44         }
45
46         /**
47          * Gets {@link PCEPOpenObject}
48          * 
49          * @return {@link PCEPOpenObject}. Can't be null.
50          */
51         public PCEPOpenObject getOpenObject() {
52                 return this.openObj;
53         }
54
55         public List<PCEPObject> getAllObjects() {
56                 return this.objects;
57         }
58
59         @Override
60         public int hashCode() {
61                 final int prime = 31;
62                 int result = super.hashCode();
63                 result = prime * result + ((this.openObj == null) ? 0 : this.openObj.hashCode());
64                 return result;
65         }
66
67         @Override
68         public boolean equals(final Object obj) {
69                 if (this == obj)
70                         return true;
71                 if (!super.equals(obj))
72                         return false;
73                 if (this.getClass() != obj.getClass())
74                         return false;
75                 final PCEPOpenMessage other = (PCEPOpenMessage) obj;
76                 if (this.openObj == null) {
77                         if (other.openObj != null)
78                                 return false;
79                 } else if (!this.openObj.equals(other.openObj))
80                         return false;
81                 return true;
82         }
83
84         @Override
85         public String toString() {
86                 final StringBuilder builder = new StringBuilder();
87                 builder.append("PCEPOpenMessage [openObj=");
88                 builder.append(this.openObj);
89                 builder.append("]");
90                 return builder.toString();
91         }
92 }