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.JsonProperty;
25 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
26 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
28 @JsonDeserialize(builder = ChampPropertyConstraint.Builder.class)
29 public final class ChampPropertyConstraint implements Comparable<ChampPropertyConstraint> {
31 private final ChampField field;
32 private final boolean required;
33 private final ChampCardinality cardinality;
35 private ChampPropertyConstraint() {
36 throw new RuntimeException("Cannot call ChampPropertyConstraint() constructor");
39 private ChampPropertyConstraint(Builder builder) {
40 this.field = builder.field;
41 this.required = builder.required;
42 this.cardinality = builder.cardinality;
45 public ChampField getField() { return field; }
46 public boolean isRequired() { return required; }
47 public ChampCardinality getCardinality() { return cardinality; }
49 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
50 public static class Builder {
51 private final ChampField field;
53 private boolean required = false;
54 private ChampCardinality cardinality = ChampCardinality.SINGLE;
56 public Builder(@JsonProperty("field") ChampField field) {
60 public Builder required(boolean required) {
61 this.required = required;
65 public Builder cardinality(ChampCardinality cardinality) {
66 this.cardinality = cardinality;
70 public ChampPropertyConstraint build() {
71 return new ChampPropertyConstraint(this);
76 public int hashCode() {
77 return 31 * (getField().hashCode());
81 public boolean equals(Object o) {
82 if (o instanceof ChampPropertyConstraint) {
83 final ChampPropertyConstraint propertyConstraint = (ChampPropertyConstraint) o;
85 if (propertyConstraint.getField().equals(getField()))
93 public String toString() {
94 return "{field: " + getField() +
95 ", required: " + isRequired() +
96 ", cardinality: " + getCardinality() +
101 public int compareTo(ChampPropertyConstraint o) {
102 final int fieldComparison = o.getField().compareTo(getField());
104 if (fieldComparison == 0) {
105 return o.getCardinality().compareTo(getCardinality());
108 return fieldComparison;