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.core.provisioning.api;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  import org.apache.commons.lang3.builder.EqualsBuilder;
24  import org.apache.commons.lang3.builder.HashCodeBuilder;
25  import org.apache.commons.lang3.builder.ToStringBuilder;
26  
27  public class WorkflowResult<T> {
28  
29      private T result;
30  
31      private final PropagationByResource<String> propByRes;
32  
33      private final Set<String> performedTasks = new HashSet<>();
34  
35      public WorkflowResult(
36              final T result,
37              final PropagationByResource<String> propByRes,
38              final String performedTask) {
39  
40          this.result = result;
41          this.propByRes = propByRes;
42          this.performedTasks.add(performedTask);
43      }
44  
45      public WorkflowResult(
46              final T result,
47              final PropagationByResource<String> propByRes,
48              final Set<String> performedTasks) {
49  
50          this.result = result;
51          this.propByRes = propByRes;
52          this.performedTasks.addAll(performedTasks);
53      }
54  
55      public T getResult() {
56          return result;
57      }
58  
59      public void setResult(final T result) {
60          this.result = result;
61      }
62  
63      public Set<String> getPerformedTasks() {
64          return performedTasks;
65      }
66  
67      public PropagationByResource<String> getPropByRes() {
68          return propByRes;
69      }
70  
71      @Override
72      public int hashCode() {
73          return new HashCodeBuilder().
74                  append(result).
75                  append(propByRes).
76                  append(performedTasks).
77                  build();
78      }
79  
80      @Override
81      public boolean equals(final Object obj) {
82          if (this == obj) {
83              return true;
84          }
85          if (obj == null) {
86              return false;
87          }
88          if (getClass() != obj.getClass()) {
89              return false;
90          }
91          @SuppressWarnings("unchecked")
92          final WorkflowResult<T> other = (WorkflowResult<T>) obj;
93          return new EqualsBuilder().
94                  append(result, other.result).
95                  append(propByRes, other.propByRes).
96                  append(performedTasks, other.performedTasks).
97                  build();
98      }
99  
100     @Override
101     public String toString() {
102         return new ToStringBuilder(this).
103                 append(result).
104                 append(propByRes).
105                 append(performedTasks).
106                 build();
107     }
108 }