BUG-47 : removed PCEPMessage interface, switched to generated Message.
[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                 if (reports == null || reports.isEmpty())
43                         throw new IllegalArgumentException("At least one CompositeStateReportObject is mandatory.");
44
45                 this.reports = reports;
46         }
47
48         /**
49          * Gets list of {@link CompositeStateReportObject}.
50          * 
51          * @return List<CompositeStateReportObject>. Can't be null or empty.
52          */
53         public List<CompositeStateReportObject> getStateReports() {
54                 return this.reports;
55         }
56
57         public List<PCEPObject> getAllObjects() {
58                 return this.objects;
59         }
60
61         @Override
62         public int hashCode() {
63                 final int prime = 31;
64                 int result = super.hashCode();
65                 result = prime * result + ((this.reports == null) ? 0 : this.reports.hashCode());
66                 return result;
67         }
68
69         @Override
70         public boolean equals(final Object obj) {
71                 if (this == obj)
72                         return true;
73                 if (!super.equals(obj))
74                         return false;
75                 if (this.getClass() != obj.getClass())
76                         return false;
77                 final PCEPReportMessage other = (PCEPReportMessage) obj;
78                 if (this.reports == null) {
79                         if (other.reports != null)
80                                 return false;
81                 } else if (!this.reports.equals(other.reports))
82                         return false;
83                 return true;
84         }
85
86         @Override
87         public String toString() {
88                 final StringBuilder builder = new StringBuilder();
89                 builder.append("PCEPReportMessage [reports=");
90                 builder.append(this.reports);
91                 builder.append("]");
92                 return builder.toString();
93         }
94 }