2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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============================================
21 package org.onap.aai.champcore.model;
23 import com.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
26 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
28 @JsonDeserialize(builder = ChampField.Builder.class)
29 public final class ChampField implements Comparable<ChampField> {
31 private final String name;
32 private final ChampField.Type type;
34 private ChampField() {
35 throw new RuntimeException("Cannot use ChampField() constructor");
38 public String getName() { return name; }
39 public ChampField.Type getType() { return type; }
42 public Class<?> getJavaType() {
57 throw new RuntimeException("Unknown ChampField.Type " + type);
61 private ChampField(Builder builder) {
62 this.name = builder.name;
63 this.type = builder.type;
66 public static enum Type {
75 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
76 public static class Builder {
77 private final String name;
79 private ChampField.Type type = ChampField.Type.STRING;
81 public Builder(@JsonProperty("name") String name) {
85 public Builder type(ChampField.Type type) {
90 public ChampField build() {
91 return new ChampField(this);
96 public int hashCode() {
97 return 31 * (getName().hashCode());
101 public boolean equals(Object object) {
102 if (object instanceof ChampField) {
103 final ChampField champField = (ChampField) object;
105 if (champField.getName().equals(getName())) return true;
112 public String toString() {
113 return "{name: " + getName() +
114 ", type: " + getType() +
119 public int compareTo(ChampField o) {
120 final int nameComparison = getName().compareTo(o.getName());
122 if (nameComparison == 0) {
123 return getType().compareTo(o.getType());
126 return nameComparison;