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;
41 private Vertex(Builder builder) {
43 this.type = builder.type;
44 this.properties = builder.properties;
47 public static class Builder {
48 private Optional<String> id = Optional.empty();
49 private final String type;
50 private final Map<String, Object> properties = new HashMap<String, Object>();
52 public Builder(String type) {
54 throw new IllegalArgumentException("Type cannot be null");
59 public Builder id(String id) {
61 throw new IllegalArgumentException("id cannot be null");
64 this.id = Optional.of(id);
68 public Builder property(String key, Object value) {
69 if (key == null || value == null) {
70 throw new IllegalArgumentException("Property key/value cannot be null");
72 properties.put(key, value);
76 public Vertex build() {
77 return new Vertex(this);
81 public String toJson() {
82 return gson.toJson(this);
86 public String toString() {
87 return "Vertex [id=" + id + ", type=" + type + ", properties=" + properties + "]";
90 public Optional<String> getId() {
94 public String getType() {
98 public Map<String, Object> getProperties() {