2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.object;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.protocol.pcep.PCEPObject;
15 import org.opendaylight.protocol.pcep.message.PCEPRequestMessage;
18 * Composite SvecObject used in {@link PCEPRequestMessage}
20 public class CompositeRequestSvecObject {
22 private final PCEPSvecObject svec;
23 private final PCEPObjectiveFunctionObject objectiveFunction;
24 private final PCEPGlobalConstraintsObject globalConstraints;
25 private final PCEPExcludeRouteObject excludeRoute;
26 private final List<PCEPMetricObject> metrics;
29 * Constructs basic composite object only with mandatory objects.
34 public CompositeRequestSvecObject(PCEPSvecObject svec) {
35 this(svec, null, null, null, null);
39 * Constructs composite object with optional objects.
43 * @param objectiveFunction
44 * PCEPObjectiveFunctionObject
45 * @param globalConstraints
46 * PCEPGlobalConstraints
48 * PCEPExcludeRouteObject
50 * list of PCEPMetricObject
52 public CompositeRequestSvecObject(PCEPSvecObject svec, PCEPObjectiveFunctionObject objectiveFunction, PCEPGlobalConstraintsObject globalConstraints,
53 PCEPExcludeRouteObject excludeRoute, List<PCEPMetricObject> metrics) {
55 throw new IllegalArgumentException("Svec object is mandatory.");
57 this.objectiveFunction = objectiveFunction;
58 this.globalConstraints = globalConstraints;
59 this.excludeRoute = excludeRoute;
61 this.metrics = metrics;
63 this.metrics = Collections.emptyList();
67 * Gets list of all objects, which are in appropriate order.
69 * @return List<PCEPObject>. Can't be null or empty.
71 public List<PCEPObject> getCompositeAsList() {
72 final List<PCEPObject> list = new ArrayList<PCEPObject>();
74 if (this.objectiveFunction != null)
75 list.add(this.objectiveFunction);
76 if (this.globalConstraints != null)
77 list.add(this.globalConstraints);
78 if (this.excludeRoute != null)
79 list.add(this.excludeRoute);
80 if (this.metrics != null && !this.metrics.isEmpty())
81 list.addAll(this.metrics);
86 * Creates this object from a list of PCEPObjects.
89 * List<PCEPObject> list of PCEPObjects from whose this object
91 * @return CompositePathObject
93 public static CompositeRequestSvecObject getCompositeFromList(List<PCEPObject> objects) {
94 if (objects == null || objects.isEmpty()) {
95 throw new IllegalArgumentException("List cannot be null or empty.");
98 PCEPSvecObject svec = null;
99 if (objects.get(0) instanceof PCEPSvecObject) {
100 svec = (PCEPSvecObject) objects.get(0);
101 objects.remove(svec);
105 PCEPObjectiveFunctionObject of = null;
106 PCEPGlobalConstraintsObject gc = null;
107 PCEPExcludeRouteObject xro = null;
108 final List<PCEPMetricObject> metrics = new ArrayList<PCEPMetricObject>();
111 while (!objects.isEmpty()) {
112 final PCEPObject obj = objects.get(0);
117 if (obj instanceof PCEPObjectiveFunctionObject) {
118 of = (PCEPObjectiveFunctionObject) obj;
123 if (obj instanceof PCEPGlobalConstraintsObject) {
124 gc = (PCEPGlobalConstraintsObject) obj;
129 if (obj instanceof PCEPExcludeRouteObject) {
130 xro = (PCEPExcludeRouteObject) obj;
135 if (obj instanceof PCEPMetricObject) {
136 metrics.add((PCEPMetricObject) obj);
149 return new CompositeRequestSvecObject(svec, of, gc, xro, metrics);
153 * Gets {@link PCEPSvecObject}
155 * @return PCEPSvecObject. Can't be null.
157 public PCEPSvecObject getSvec() {
162 * Gets {@link PCEPObjectiveFunctionObject}
164 * @return PCEPObjectiveFunctionObject. May be null.
166 public PCEPObjectiveFunctionObject getObjectiveFunction() {
167 return this.objectiveFunction;
171 * Gets {@link PCEPGlobalConstraintsObject}
173 * @return PCEPGlobalConstraints. May be null.
175 public PCEPGlobalConstraintsObject getGlobalConstraints() {
176 return this.globalConstraints;
180 * Gets {@link PCEPExcludeRouteObject}
182 * @return PCEPExcludeRouteObject. May be null.
184 public PCEPExcludeRouteObject getExcludeRoute() {
185 return this.excludeRoute;
189 * @return the metrics
191 public List<PCEPMetricObject> getMetrics() {
196 public String toString() {
197 final StringBuilder builder = new StringBuilder();
198 builder.append("CompositeSvecObject [svec=");
199 builder.append(this.svec);
200 builder.append(", objectiveFunction=");
201 builder.append(this.objectiveFunction);
202 builder.append(", globalConstraints=");
203 builder.append(this.globalConstraints);
204 builder.append(", excludeRoute=");
205 builder.append(this.excludeRoute);
206 builder.append(", metrics=");
207 builder.append(this.metrics);
209 return builder.toString();
213 public int hashCode() {
214 final int prime = 31;
216 result = prime * result + ((this.excludeRoute == null) ? 0 : this.excludeRoute.hashCode());
217 result = prime * result + ((this.globalConstraints == null) ? 0 : this.globalConstraints.hashCode());
218 result = prime * result + ((this.metrics == null) ? 0 : this.metrics.hashCode());
219 result = prime * result + ((this.objectiveFunction == null) ? 0 : this.objectiveFunction.hashCode());
220 result = prime * result + ((this.svec == null) ? 0 : this.svec.hashCode());
225 public boolean equals(Object obj) {
230 if (this.getClass() != obj.getClass())
232 final CompositeRequestSvecObject other = (CompositeRequestSvecObject) obj;
233 if (this.excludeRoute == null) {
234 if (other.excludeRoute != null)
236 } else if (!this.excludeRoute.equals(other.excludeRoute))
238 if (this.globalConstraints == null) {
239 if (other.globalConstraints != null)
241 } else if (!this.globalConstraints.equals(other.globalConstraints))
243 if (this.metrics == null) {
244 if (other.metrics != null)
246 } else if (!this.metrics.equals(other.metrics))
248 if (this.objectiveFunction == null) {
249 if (other.objectiveFunction != null)
251 } else if (!this.objectiveFunction.equals(other.objectiveFunction))
253 if (this.svec == null) {
254 if (other.svec != null)
256 } else if (!this.svec.equals(other.svec))