Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[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
44                 this.openObj = openObj;
45         }
46
47         /**
48          * Gets {@link PCEPOpenObject}
49          * 
50          * @return {@link PCEPOpenObject}. Can't be null.
51          */
52         public PCEPOpenObject getOpenObject() {
53                 return this.openObj;
54         }
55
56         public List<PCEPObject> getAllObjects() {
57                 return this.objects;
58         }
59
60         @Override
61         public int hashCode() {
62                 final int prime = 31;
63                 int result = super.hashCode();
64                 result = prime * result + ((this.openObj == null) ? 0 : this.openObj.hashCode());
65                 return result;
66         }
67
68         @Override
69         public boolean equals(final Object obj) {
70                 if (this == obj) {
71                         return true;
72                 }
73                 if (!super.equals(obj)) {
74                         return false;
75                 }
76                 if (this.getClass() != obj.getClass()) {
77                         return false;
78                 }
79                 final PCEPOpenMessage other = (PCEPOpenMessage) obj;
80                 if (this.openObj == null) {
81                         if (other.openObj != null) {
82                                 return false;
83                         }
84                 } else if (!this.openObj.equals(other.openObj)) {
85                         return false;
86                 }
87                 return true;
88         }
89
90         @Override
91         public String toString() {
92                 final StringBuilder builder = new StringBuilder();
93                 builder.append("PCEPOpenMessage [openObj=");
94                 builder.append(this.openObj);
95                 builder.append("]");
96                 return builder.toString();
97         }
98
99         @Override
100         public Class<Message> getImplementedInterface() {
101                 return Message.class;
102         }
103 }