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