2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.openecomp.crud.entity;
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
29 import java.util.HashMap;
31 import java.util.Optional;
34 private static final Gson gson = new GsonBuilder().create();
36 private final Optional<String> id;
37 private final String type;
38 private final Map<String, Object> properties;
39 private final Vertex source;
40 private final Vertex target;
43 private Edge(Builder builder) {
45 this.type = builder.type;
46 this.source = builder.source;
47 this.target = builder.target;
48 this.properties = builder.properties;
51 public static class Builder {
52 private Optional<String> id = Optional.empty();
53 private final String type;
54 private Vertex source;
55 private Vertex target;
56 private final Map<String, Object> properties = new HashMap<String, Object>();
58 public Builder(String type) {
60 throw new IllegalArgumentException("Type cannot be null");
66 public Builder id(String id) {
68 throw new IllegalArgumentException("id cannot be null");
71 this.id = Optional.of(id);
75 public Builder property(String key, Object value) {
76 if (key == null || value == null) {
77 throw new IllegalArgumentException("Property key/value cannot be null");
79 properties.put(key, value);
83 public Builder source(Vertex source) {
88 public Builder target(Vertex target) {
94 return new Edge(this);
100 public String toString() {
101 return "Edge [id=" + id + ", type=" + type + ", properties=" + properties
102 + ", source=" + source + ", target=" + target + "]";
105 public String toJson() {
106 return gson.toJson(this);
109 public Optional<String> getId() {
113 public String getType() {
117 public Map<String, Object> getProperties() {
121 public Vertex getSource() {
125 public Vertex getTarget() {