BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / message / PCCreateMessage.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.CompositeInstantiationObject;
14 import org.opendaylight.protocol.pcep.object.CompositeStateReportObject;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
16
17 import com.google.common.collect.Lists;
18
19 /**
20  * @see <a href="http://www.ietf.org/id/draft-crabbe-pce-pce-initiated-lsp-00.txt">5.1. The LSP Create Message</a>
21  */
22 public class PCCreateMessage implements Message {
23
24         private final List<CompositeInstantiationObject> lsps;
25
26         private final List<PCEPObject> objects;
27
28         /**
29          * Constructs {@link PCCreateMessage}.
30          * 
31          * @throws IllegalArgumentException if there is not even one {@link CompositeInstantiationObject} in the list.
32          * 
33          * @param lsps List<CompositeInstantiationObject>. Can't be empty or null.
34          */
35         public PCCreateMessage(final List<CompositeInstantiationObject> lsps) {
36                 if (lsps == null || lsps.isEmpty())
37                         throw new IllegalArgumentException("At least one CompositeStateReportObject is mandatory.");
38
39                 this.lsps = lsps;
40                 this.objects = Lists.newArrayList();
41                 for (final CompositeInstantiationObject cio : lsps) {
42                         this.objects.addAll(cio.getCompositeAsList());
43                 }
44         }
45
46         /**
47          * Gets list of {@link CompositeStateReportObject}.
48          * 
49          * @return List<CompositeStateReportObject>. Can't be null or empty.
50          */
51         public List<CompositeInstantiationObject> getLSPs() {
52                 return this.lsps;
53         }
54
55         public List<PCEPObject> getAllObjects() {
56                 return this.objects;
57         }
58
59         /* (non-Javadoc)
60          * @see java.lang.Object#hashCode()
61          */
62         @Override
63         public int hashCode() {
64                 final int prime = 31;
65                 int result = super.hashCode();
66                 result = prime * result + ((this.lsps == null) ? 0 : this.lsps.hashCode());
67                 return result;
68         }
69
70         /* (non-Javadoc)
71          * @see java.lang.Object#equals(java.lang.Object)
72          */
73         @Override
74         public boolean equals(final Object obj) {
75                 if (this == obj)
76                         return true;
77                 if (!super.equals(obj))
78                         return false;
79                 if (!(obj instanceof PCCreateMessage))
80                         return false;
81                 final PCCreateMessage other = (PCCreateMessage) obj;
82                 if (this.lsps == null) {
83                         if (other.lsps != null)
84                                 return false;
85                 } else if (!this.lsps.equals(other.lsps))
86                         return false;
87                 return true;
88         }
89
90         /* (non-Javadoc)
91          * @see java.lang.Object#toString()
92          */
93         @Override
94         public String toString() {
95                 final StringBuilder builder = new StringBuilder();
96                 builder.append("PCCreateMessage [lsps=");
97                 builder.append(this.lsps);
98                 builder.append("]");
99                 return builder.toString();
100         }
101 }