1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.lib;
20
21 import com.fasterxml.jackson.annotation.JsonProperty;
22 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
23 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import javax.ws.rs.PathParam;
28 import org.apache.commons.lang3.builder.CompareToBuilder;
29 import org.apache.commons.lang3.builder.EqualsBuilder;
30 import org.apache.commons.lang3.builder.HashCodeBuilder;
31
32 public class Attr implements Comparable<Attr>, BaseBean {
33
34 private static final long serialVersionUID = 4941691338796323623L;
35
36 public static class Builder {
37
38 private final Attr instance = new Attr();
39
40 public Builder(final String schema) {
41 instance.setSchema(schema);
42 }
43
44 public Builder value(final String value) {
45 instance.getValues().add(value);
46 return this;
47 }
48
49 public Builder values(final String... values) {
50 instance.getValues().addAll(List.of(values));
51 return this;
52 }
53
54 public Builder values(final Collection<String> values) {
55 instance.getValues().addAll(values);
56 return this;
57 }
58
59 public Attr build() {
60 return instance;
61 }
62 }
63
64
65
66
67 private String schema;
68
69
70
71
72 private final List<String> values = new ArrayList<>();
73
74
75
76
77 @JsonProperty(required = true)
78 public String getSchema() {
79 return schema;
80 }
81
82
83
84
85 @PathParam("schema")
86 public void setSchema(final String schema) {
87 this.schema = schema;
88
89 }
90
91
92
93
94 @JacksonXmlElementWrapper(localName = "values")
95 @JacksonXmlProperty(localName = "value")
96 @JsonProperty(required = true)
97 public List<String> getValues() {
98 return values;
99 }
100
101 @Override
102 public int compareTo(final Attr other) {
103 return equals(other)
104 ? 0
105 : new CompareToBuilder().
106 append(schema, other.schema).
107 append(values.toArray(), other.values.toArray()).
108 toComparison();
109 }
110
111 @Override
112 public int hashCode() {
113 return new HashCodeBuilder().
114 append(schema).
115 append(values).
116 build();
117 }
118
119 @Override
120 public boolean equals(final Object obj) {
121 if (this == obj) {
122 return true;
123 }
124 if (obj == null) {
125 return false;
126 }
127 if (getClass() != obj.getClass()) {
128 return false;
129 }
130 final Attr other = (Attr) obj;
131 return new EqualsBuilder().
132 append(schema, other.schema).
133 append(values, other.values).
134 build();
135 }
136 }