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.JsonProperty;
24 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
27 @JsonDeserialize(builder = ChampPropertyConstraint.Builder.class)
28 public final class ChampPropertyConstraint implements Comparable<ChampPropertyConstraint> {
30 private final ChampField field;
31 private final boolean required;
32 private final ChampCardinality cardinality;
34 private ChampPropertyConstraint() {
35 throw new RuntimeException("Cannot call ChampPropertyConstraint() constructor");
38 private ChampPropertyConstraint(Builder builder) {
39 this.field = builder.field;
40 this.required = builder.required;
41 this.cardinality = builder.cardinality;
44 public ChampField getField() { return field; }
45 public boolean isRequired() { return required; }
46 public ChampCardinality getCardinality() { return cardinality; }
48 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
49 public static class Builder {
50 private final ChampField field;
52 private boolean required = false;
53 private ChampCardinality cardinality = ChampCardinality.SINGLE;
55 public Builder(@JsonProperty("field") ChampField field) {
59 public Builder required(boolean required) {
60 this.required = required;
64 public Builder cardinality(ChampCardinality cardinality) {
65 this.cardinality = cardinality;
69 public ChampPropertyConstraint build() {
70 return new ChampPropertyConstraint(this);
75 public int hashCode() {
76 return 31 * (getField().hashCode());
80 public boolean equals(Object o) {
81 if (o instanceof ChampPropertyConstraint) {
82 final ChampPropertyConstraint propertyConstraint = (ChampPropertyConstraint) o;
84 if (propertyConstraint.getField().equals(getField()))
92 public String toString() {
93 return "{field: " + getField() +
94 ", required: " + isRequired() +
95 ", cardinality: " + getCardinality() +
100 public int compareTo(ChampPropertyConstraint o) {
101 final int fieldComparison = o.getField().compareTo(getField());
103 if (fieldComparison == 0) {
104 return o.getCardinality().compareTo(getCardinality());
107 return fieldComparison;