2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ===================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.champcore.model;
24 import java.util.HashMap;
25 import java.util.HashSet;
29 import org.onap.aai.champcore.model.fluent.partition.CreateChampPartitionable;
30 import org.onap.aai.champcore.model.fluent.partition.impl.CreateChampPartionableImpl;
32 public final class ChampPartition {
34 private final Set<ChampObject> champObjects;
35 private final Set<ChampRelationship> champRelationships;
37 private ChampPartition() {
38 throw new RuntimeException("Cannot call ChampGraph() constructor");
41 private ChampPartition(Builder builder) {
42 this.champObjects = builder.champObjects;
43 this.champRelationships = builder.champRelationships;
46 public static CreateChampPartitionable create() {
47 return new CreateChampPartionableImpl();
50 public Set<ChampObject> getChampObjects() { return champObjects; }
51 public Set<ChampRelationship> getChampRelationships() { return champRelationships; }
53 public Set<ChampRelationship> getIncidentRelationships(ChampObject source) {
54 final Set<ChampRelationship> incidentRelationships = new HashSet<ChampRelationship> ();
56 for (ChampRelationship relationship : getChampRelationships()) {
57 if (relationship.getSource().equals(source) ||
58 relationship.getTarget().equals(source)) {
59 incidentRelationships.add(relationship);
63 return incidentRelationships;
66 public Map<String, Set<ChampRelationship>> getIncidentRelationshipsByType(ChampObject source) {
67 final Map<String, Set<ChampRelationship>> incidentRelationships = new HashMap<String, Set<ChampRelationship>> ();
69 for (ChampRelationship relationship : getChampRelationships()) {
70 if (relationship.getSource().equals(source) ||
71 relationship.getTarget().equals(source)) {
72 if (!incidentRelationships.containsKey(relationship.getType())) {
73 incidentRelationships.put(relationship.getType(), new HashSet<ChampRelationship> ());
76 incidentRelationships.get(relationship.getType()).add(relationship);
80 return incidentRelationships;
83 public static class Builder {
84 private final Set<ChampObject> champObjects;
85 private final Set<ChampRelationship> champRelationships;
88 this.champObjects = new HashSet<ChampObject> ();
89 this.champRelationships = new HashSet<ChampRelationship> ();
92 public Builder object(ChampObject object) {
93 champObjects.add(object);
97 public Builder relationship(ChampRelationship relationship) {
98 champRelationships.add(relationship);
102 public Builder objects(Set<ChampObject> objects) {
103 champObjects.addAll(objects);
107 public Builder relationships(Set<ChampRelationship> relationships) {
108 champRelationships.addAll(relationships);
112 public ChampPartition build() {
113 return new ChampPartition(this);
118 public String toString() {
120 final StringBuilder sb = new StringBuilder();
122 sb.append("{objects: [");
124 for (ChampObject object : champObjects) {
125 sb.append(object.toString());
129 if (sb.charAt(sb.length() - 1) == ',') {
130 sb.deleteCharAt(sb.length() - 1); //Delete last comma
133 sb.append("], relationships: [");
135 for (ChampRelationship relationship : champRelationships) {
136 sb.append(relationship.toString());
140 if (sb.charAt(sb.length() - 1) == ',') {
141 sb.deleteCharAt(sb.length() - 1); //Delete last comma
146 return sb.toString();