View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.request;
20  
21  import com.fasterxml.jackson.annotation.JsonIgnore;
22  import org.apache.commons.lang3.builder.EqualsBuilder;
23  import org.apache.commons.lang3.builder.HashCodeBuilder;
24  import org.apache.syncope.common.lib.Attr;
25  
26  public class AttrPatch extends AbstractPatch {
27  
28      private static final long serialVersionUID = 6881634224246176673L;
29  
30      public static class Builder extends AbstractPatch.Builder<AttrPatch, Builder> {
31  
32          public Builder(final Attr attr) {
33              super();
34              getInstance().setAttr(attr);
35          }
36  
37          @Override
38          protected AttrPatch newInstance() {
39              return new AttrPatch();
40          }
41      }
42  
43      private Attr attr;
44  
45      public Attr getAttr() {
46          return attr;
47      }
48  
49      public void setAttr(final Attr attr) {
50          this.attr = attr;
51      }
52  
53      @JsonIgnore
54      public boolean isEmpty() {
55          return attr == null || attr.getValues().isEmpty();
56      }
57  
58      @Override
59      public int hashCode() {
60          return new HashCodeBuilder().
61                  appendSuper(super.hashCode()).
62                  append(attr).
63                  build();
64      }
65  
66      @Override
67      public boolean equals(final Object obj) {
68          if (this == obj) {
69              return true;
70          }
71          if (obj == null) {
72              return false;
73          }
74          if (getClass() != obj.getClass()) {
75              return false;
76          }
77          final AttrPatch other = (AttrPatch) obj;
78          return new EqualsBuilder().
79                  appendSuper(super.equals(obj)).
80                  append(attr, other.attr).
81                  build();
82      }
83  }