Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCEPReportMessage.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.CompositeStateReportObject;
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 Report Message
20  * 
21  * @see <a href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-6.1">State Report Message</a>
22  */
23 public class PCEPReportMessage implements Message {
24
25         private final List<CompositeStateReportObject> reports;
26
27         private final List<PCEPObject> objects;
28
29         /**
30          * Constructs {@link PCEPReportMessage}.
31          * 
32          * @throws IllegalArgumentException if there is not even one {@link CompositeStateReportObject} in the list.
33          * 
34          * @param reports List<CompositeStateReportObject>. Can't be empty or null.
35          */
36         public PCEPReportMessage(final List<CompositeStateReportObject> reports) {
37                 this.objects = Lists.newArrayList();
38                 if (reports != null) {
39                         for (final CompositeStateReportObject csro : reports) {
40                                 this.objects.addAll(csro.getCompositeAsList());
41                         }
42                 }
43                 if (reports == null || reports.isEmpty()) {
44                         throw new IllegalArgumentException("At least one CompositeStateReportObject is mandatory.");
45                 }
46
47                 this.reports = reports;
48         }
49
50         /**
51          * Gets list of {@link CompositeStateReportObject}.
52          * 
53          * @return List<CompositeStateReportObject>. Can't be null or empty.
54          */
55         public List<CompositeStateReportObject> getStateReports() {
56                 return this.reports;
57         }
58
59         public List<PCEPObject> getAllObjects() {
60                 return this.objects;
61         }
62
63         @Override
64         public int hashCode() {
65                 final int prime = 31;
66                 int result = super.hashCode();
67                 result = prime * result + ((this.reports == null) ? 0 : this.reports.hashCode());
68                 return result;
69         }
70
71         @Override
72         public boolean equals(final Object obj) {
73                 if (this == obj) {
74                         return true;
75                 }
76                 if (!super.equals(obj)) {
77                         return false;
78                 }
79                 if (this.getClass() != obj.getClass()) {
80                         return false;
81                 }
82                 final PCEPReportMessage other = (PCEPReportMessage) obj;
83                 if (this.reports == null) {
84                         if (other.reports != null) {
85                                 return false;
86                         }
87                 } else if (!this.reports.equals(other.reports)) {
88                         return false;
89                 }
90                 return true;
91         }
92
93         @Override
94         public String toString() {
95                 final StringBuilder builder = new StringBuilder();
96                 builder.append("PCEPReportMessage [reports=");
97                 builder.append(this.reports);
98                 builder.append("]");
99                 return builder.toString();
100         }
101
102         @Override
103         public Class<Message> getImplementedInterface() {
104                 return Message.class;
105         }
106 }