Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[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
40                 this.lsps = lsps;
41                 this.objects = Lists.newArrayList();
42                 for (final CompositeInstantiationObject cio : lsps) {
43                         this.objects.addAll(cio.getCompositeAsList());
44                 }
45         }
46
47         /**
48          * Gets list of {@link CompositeStateReportObject}.
49          * 
50          * @return List<CompositeStateReportObject>. Can't be null or empty.
51          */
52         public List<CompositeInstantiationObject> getLSPs() {
53                 return this.lsps;
54         }
55
56         public List<PCEPObject> getAllObjects() {
57                 return this.objects;
58         }
59
60         /* (non-Javadoc)
61          * @see java.lang.Object#hashCode()
62          */
63         @Override
64         public int hashCode() {
65                 final int prime = 31;
66                 int result = super.hashCode();
67                 result = prime * result + ((this.lsps == null) ? 0 : this.lsps.hashCode());
68                 return result;
69         }
70
71         /* (non-Javadoc)
72          * @see java.lang.Object#equals(java.lang.Object)
73          */
74         @Override
75         public boolean equals(final Object obj) {
76                 if (this == obj) {
77                         return true;
78                 }
79                 if (!super.equals(obj)) {
80                         return false;
81                 }
82                 if (!(obj instanceof PCCreateMessage)) {
83                         return false;
84                 }
85                 final PCCreateMessage other = (PCCreateMessage) obj;
86                 if (this.lsps == null) {
87                         if (other.lsps != null) {
88                                 return false;
89                         }
90                 } else if (!this.lsps.equals(other.lsps)) {
91                         return false;
92                 }
93                 return true;
94         }
95
96         /* (non-Javadoc)
97          * @see java.lang.Object#toString()
98          */
99         @Override
100         public String toString() {
101                 final StringBuilder builder = new StringBuilder();
102                 builder.append("PCCreateMessage [lsps=");
103                 builder.append(this.lsps);
104                 builder.append("]");
105                 return builder.toString();
106         }
107
108         @Override
109         public Class<Message> getImplementedInterface() {
110                 return Message.class;
111         }
112 }