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.request;
20
21 import org.apache.commons.lang3.builder.EqualsBuilder;
22 import org.apache.commons.lang3.builder.HashCodeBuilder;
23 import org.apache.syncope.common.lib.BaseBean;
24 import org.apache.syncope.common.lib.types.PatchOperation;
25
26 public abstract class AbstractPatch implements BaseBean {
27
28 private static final long serialVersionUID = -4729181508529829580L;
29
30 protected abstract static class Builder<P extends AbstractPatch, B extends Builder<P, B>> {
31
32 protected P instance;
33
34 protected abstract P newInstance();
35
36 protected P getInstance() {
37 if (instance == null) {
38 instance = newInstance();
39 }
40 return instance;
41 }
42
43 @SuppressWarnings("unchecked")
44 public B operation(final PatchOperation operation) {
45 getInstance().setOperation(operation);
46 return (B) this;
47 }
48
49 public P build() {
50 if (getInstance().getOperation() == null) {
51 instance.setOperation(PatchOperation.ADD_REPLACE);
52 }
53 return getInstance();
54 }
55 }
56
57 private PatchOperation operation;
58
59 public PatchOperation getOperation() {
60 return operation;
61 }
62
63 public void setOperation(final PatchOperation operation) {
64 this.operation = operation;
65 }
66
67 @Override
68 public int hashCode() {
69 return new HashCodeBuilder().
70 append(operation).
71 build();
72 }
73
74 @Override
75 public boolean equals(final Object obj) {
76 if (this == obj) {
77 return true;
78 }
79 if (obj == null) {
80 return false;
81 }
82 if (getClass() != obj.getClass()) {
83 return false;
84 }
85 final AbstractPatch other = (AbstractPatch) obj;
86 return new EqualsBuilder().
87 append(operation, other.operation).
88 build();
89 }
90 }