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;
17 * Structure that combines set of related objects.
20 * href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-6.2">The
21 * PCRpt Message</a> - <update-request></br>
23 public class CompositeUpdateRequestObject {
25 private final PCEPLspObject lsp;
27 private List<CompositeUpdPathObject> paths;
30 * Constructs basic composite object only with mandatory objects.
33 * PCEPLspObject. Can't be null.
35 public CompositeUpdateRequestObject(PCEPLspObject lsp) {
40 * Constructs composite object with optional objects.
43 * PCEPLspObject. Can't be null.
45 * List<CompositeUpdPathObject>
47 public CompositeUpdateRequestObject(PCEPLspObject lsp, List<CompositeUpdPathObject> paths) {
49 throw new IllegalArgumentException("LSP Object is mandatory.");
54 this.paths = Collections.emptyList();
58 * Gets list of all objects, which are in appropriate order.
60 * @return List<PCEPObject>. Can't be null.
62 public List<PCEPObject> getCompositeAsList() {
63 final List<PCEPObject> list = new ArrayList<PCEPObject>();
65 if (this.paths != null && !this.paths.isEmpty())
66 for (final CompositeUpdPathObject cpo : this.paths)
67 list.addAll(cpo.getCompositeAsList());
72 * Creates this object from a list of PCEPObjects.
73 * @param objects List<PCEPObject> list of PCEPObjects from whose this
74 * object should be created.
75 * @return CompositeUpdateRequestObject
77 public static CompositeUpdateRequestObject getCompositeFromList(List<PCEPObject> objects) {
78 if (objects == null || objects.isEmpty()) {
79 throw new IllegalArgumentException("List cannot be null or empty.");
82 PCEPLspObject lsp = null;
83 if (objects.get(0) instanceof PCEPLspObject) {
84 lsp = (PCEPLspObject) objects.get(0);
89 final List<CompositeUpdPathObject> paths = new ArrayList<CompositeUpdPathObject>();
91 if (!objects.isEmpty()) {
92 CompositeUpdPathObject path = CompositeUpdPathObject.getCompositeFromList(objects);
93 while (path != null) {
95 if (objects.isEmpty())
97 path = CompositeUpdPathObject.getCompositeFromList(objects);
101 return new CompositeUpdateRequestObject(lsp, paths);
105 * Gets {@link PCEPLspObject}.
107 * @return PCEPLspObject. Can't be null.
109 public PCEPLspObject getLsp() {
114 * Gets list of {@link CompositeUpdPathObject}.
116 * @return List<CompositeUpdPathObject>. Can't be null, but may be empty.
118 public List<CompositeUpdPathObject> getPaths() {
123 public int hashCode() {
124 final int prime = 31;
126 result = prime * result + ((this.lsp == null) ? 0 : this.lsp.hashCode());
127 result = prime * result + ((this.paths == null) ? 0 : this.paths.hashCode());
132 public boolean equals(Object obj) {
137 if (this.getClass() != obj.getClass())
139 final CompositeUpdateRequestObject other = (CompositeUpdateRequestObject) obj;
140 if (this.lsp == null) {
141 if (other.lsp != null)
143 } else if (!this.lsp.equals(other.lsp))
145 if (this.paths == null) {
146 if (other.paths != null)
148 } else if (!this.paths.equals(other.paths))
154 public String toString() {
155 final StringBuilder builder = new StringBuilder();
156 builder.append("CompositeUpdateRequestObject [lsp=");
157 builder.append(this.lsp);
158 builder.append(", paths=");
159 builder.append(this.paths);
161 return builder.toString();