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.1">The
21 * PCRpt Message</a> - <state-report></br>
23 public class CompositeStateReportObject {
25 private final PCEPLspObject lsp;
27 private List<CompositeRptPathObject> paths;
30 * Constructs basic composite object only with mandatory objects.
35 public CompositeStateReportObject(PCEPLspObject lsp) {
40 * Constructs composite object with optional objects.
45 * List<CompositeRptPathObject> Can't be null.
47 public CompositeStateReportObject(PCEPLspObject lsp, List<CompositeRptPathObject> paths) {
49 throw new IllegalArgumentException("LSP Object is mandatory.");
54 this.paths = Collections.emptyList();
58 * Creates this object from a list of PCEPObjects.
59 * @param objects List<PCEPObject> list of PCEPObjects from whose this
60 * object should be created.
61 * @return CompositeStateReportObject
63 public static CompositeStateReportObject getCompositeFromList(List<PCEPObject> objects) {
64 if (objects == null || objects.isEmpty()) {
65 throw new IllegalArgumentException("List can not be null or empty.");
68 PCEPLspObject lsp = null;
69 if (objects.get(0) instanceof PCEPLspObject) {
70 lsp = (PCEPLspObject) objects.get(0);
75 final List<CompositeRptPathObject> paths = new ArrayList<CompositeRptPathObject>();
77 if (!objects.isEmpty()) {
78 CompositeRptPathObject path = CompositeRptPathObject.getCompositeFromList(objects);
79 while (path != null) {
81 if (objects.isEmpty())
83 path = CompositeRptPathObject.getCompositeFromList(objects);
87 return new CompositeStateReportObject(lsp, paths);
91 * Gets list of all objects, which are in appropriate order.
93 * @return List<PCEPObject>
95 public List<PCEPObject> getCompositeAsList() {
96 final List<PCEPObject> list = new ArrayList<PCEPObject>();
98 if (this.paths != null && !this.paths.isEmpty())
99 for (final CompositeRptPathObject cpo : this.paths)
100 list.addAll(cpo.getCompositeAsList());
105 * Gets {@link PCEPLspObject}.
107 * @return PCEPLspObject. Can't be null.
109 public PCEPLspObject getLsp() {
114 * Gets list of {@link CompositeRptPathObject}.
116 * @return List<CompositeRptPathObject>. May be null.
118 public List<CompositeRptPathObject> 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 CompositeStateReportObject other = (CompositeStateReportObject) 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("CompositeStateReportObject [lsp=");
157 builder.append(this.lsp);
158 builder.append(", paths=");
159 builder.append(this.paths);
161 return builder.toString();