Renaming openecomp to onap
[aai/champ.git] / src / main / java / org / onap / aai / champ / model / ChampConnectionConstraint.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
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
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
21  */
22 package org.onap.aai.champ.model;
23
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
26 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
27
28 @JsonDeserialize(builder = ChampConnectionConstraint.Builder.class)
29 public final class ChampConnectionConstraint {
30
31         private final String sourceType;
32         private final String targetType;
33         private final ChampConnectionMultiplicity cardinality;
34
35         private ChampConnectionConstraint() {
36                 throw new RuntimeException("Cannot call ConnectionConstraint() constructor");
37         }
38         
39         private ChampConnectionConstraint(Builder builder) {
40                 this.sourceType = builder.sourceType;
41                 this.targetType = builder.targetType;
42                 this.cardinality = builder.multiplicity;
43         }
44         
45         public String getSourceType() { return sourceType; }
46         public String getTargetType() { return targetType; }
47         public ChampConnectionMultiplicity getMultiplicity() { return cardinality; }
48
49         @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
50         public static class Builder {
51                 private final String sourceType;
52                 private final String targetType;
53
54                 private ChampConnectionMultiplicity multiplicity = ChampConnectionMultiplicity.MANY;
55                 
56                 public Builder(@JsonProperty("sourceType") String sourceType, @JsonProperty("targetType") String targetType) {
57                         this.sourceType = sourceType;
58                         this.targetType = targetType;
59                 }
60
61                 public Builder multiplicity(ChampConnectionMultiplicity multiplicity) {
62                         this.multiplicity = multiplicity;
63                         return this;
64                 }
65
66                 public ChampConnectionConstraint build() {
67                         return new ChampConnectionConstraint(this);
68                 }
69         }
70
71         @Override
72         public int hashCode() {
73                 return 31 * (getSourceType().hashCode() + getTargetType().hashCode());
74         }
75
76         @Override
77         public boolean equals(Object o) {
78                 if (o instanceof ChampConnectionConstraint) {
79                         final ChampConnectionConstraint connConstraint = (ChampConnectionConstraint) o;
80
81                         if (connConstraint.getSourceType().equals(getSourceType()) &&
82                                 connConstraint.getTargetType().equals(getTargetType()) &&
83                                 connConstraint.getMultiplicity().equals(getMultiplicity())) return true;
84                 }
85
86                 return false;
87         }
88
89         @Override
90         public String toString() {
91                 return "{sourceType: " + getSourceType() +
92                                 ", targetType: " + getTargetType() +
93                                 ", multiplicity: " + getMultiplicity()
94                                 + "}";
95         }
96 }