BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPCloseMessage.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.PCEPCloseObject;
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 Close Message.
20  * 
21  * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.8">Close Message</a>
22  */
23 public class PCEPCloseMessage implements Message {
24
25         private final PCEPCloseObject closeObj;
26
27         private final List<PCEPObject> objects;
28
29         /**
30          * Constructs a new Close Message, which has to include PCEP Close Object. Is used to close an established session
31          * between PCEP Peers.
32          * 
33          * @throws IllegalArgumentException if the CloseObject passed, is null.
34          * 
35          * @see <a href="http://tools.ietf.org/html/rfc5440#section-6.8">Close Message</a>
36          * 
37          * @param closeObj Can't be null.
38          */
39         public PCEPCloseMessage(final PCEPCloseObject closeObj) {
40                 if (closeObj == null)
41                         throw new IllegalArgumentException("PCEPCloseObject is mandatory. Can't be null.");
42
43                 this.closeObj = closeObj;
44                 this.objects = Lists.newArrayList();
45                 if (closeObj != null)
46                         this.objects.add(closeObj);
47         }
48
49         /**
50          * Gets {@link PCEPCloseObject}, which is mandatory object of PCEP Close Message.
51          * 
52          * @return {@link PCEPCloseObject} . Can't be null.
53          */
54         public PCEPCloseObject getCloseObject() {
55                 return this.closeObj;
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.closeObj == null) ? 0 : this.closeObj.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 PCEPCloseMessage other = (PCEPCloseMessage) obj;
79                 if (this.closeObj == null) {
80                         if (other.closeObj != null)
81                                 return false;
82                 } else if (!this.closeObj.equals(other.closeObj))
83                         return false;
84                 return true;
85         }
86
87         @Override
88         public String toString() {
89                 final StringBuilder builder = new StringBuilder();
90                 builder.append("PCEPCloseMessage [closeObj=");
91                 builder.append(this.closeObj);
92                 builder.append("]");
93                 return builder.toString();
94         }
95 }