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.openecomp.aai.champ.model;
24 import com.fasterxml.jackson.annotation.JsonIgnore;
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
27 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
29 @JsonDeserialize(builder = ChampField.Builder.class)
30 public final class ChampField implements Comparable<ChampField> {
32 private final String name;
33 private final ChampField.Type type;
35 private ChampField() {
36 throw new RuntimeException("Cannot use ChampField() constructor");
39 public String getName() { return name; }
40 public ChampField.Type getType() { return type; }
43 public Class<?> getJavaType() {
58 throw new RuntimeException("Unknown ChampField.Type " + type);
62 private ChampField(Builder builder) {
63 this.name = builder.name;
64 this.type = builder.type;
67 public static enum Type {
76 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
77 public static class Builder {
78 private final String name;
80 private ChampField.Type type = ChampField.Type.STRING;
82 public Builder(@JsonProperty("name") String name) {
86 public Builder type(ChampField.Type type) {
91 public ChampField build() {
92 return new ChampField(this);
97 public int hashCode() {
98 return 31 * (getName().hashCode());
102 public boolean equals(Object object) {
103 if (object instanceof ChampField) {
104 final ChampField champField = (ChampField) object;
106 if (champField.getName().equals(getName())) return true;
113 public String toString() {
114 return "{name: " + getName() +
115 ", type: " + getType() +
120 public int compareTo(ChampField o) {
121 final int nameComparison = getName().compareTo(o.getName());
123 if (nameComparison == 0) {
124 return getType().compareTo(o.getType());
127 return nameComparison;