View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kcb.quartz;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
22  /**
23   * Encapsulates the number of successes and failures in a giving processing run
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class ProcessingResult<T> {
27      /**
28       * Represents a failure of a work item
29       */
30      public static class Failure<T> {
31          private T item;
32          private Throwable exception;
33          private String message;
34          
35          public Failure(T item) {
36              this.item = item;
37          }
38          
39          public Failure(String message) {
40              this(null, null, message);
41          }
42  
43          public Failure(Throwable exception) {
44              this(null, exception, null);
45          }
46  
47          public Failure(Throwable exception, String message) {
48              this(null, exception, message);
49          }
50  
51  
52          public Failure(T item, Throwable exception) {
53              this(item, exception, null);
54          }
55          
56          public Failure(T item, String message) {
57              this(item, null, message);
58          }
59          
60          public Failure(T item, Throwable exception, String message) {
61              this.item = item;
62              this.exception = exception;
63              this.message = message;
64          }
65  
66          public T getItem() {
67              return this.item;
68          }
69          public Throwable getException() {
70              return this.exception;
71          }
72          public String getMessage() {
73              return this.message;
74          }
75      }
76  
77      /**
78       * List of failures
79       */
80      private List<Failure<T>> failures = new ArrayList<Failure<T>>();
81      /**
82       * List of successes
83       */
84      private List<T> successes = new ArrayList<T>();
85  
86      /**
87       * Returns the list of failures
88       * @return the list of failures
89       */
90      public List<Failure<T>> getFailures() {
91          return failures;
92      }
93  
94      /**
95       * Returns the list of successes
96       * @return the list of successes
97       */
98      public List<T> getSuccesses() {
99          return successes;
100     }
101 
102     /**
103      * Adds a failure
104      * @param o an object representing a failure
105      */
106     public void addFailure(Failure<T> o) {
107         failures.add(o);
108     }
109 
110     /**
111      * Adds a collection of failures
112      * @param Collection a collection of failures
113      */
114     public void addAllFailures(Collection<Failure<T>> c) {
115         failures.addAll(c);
116     }
117 
118     /**
119      * Adds a success
120      * @param o an object representing a success
121      */
122     public void addSuccess(T o) {
123         successes.add(o);
124     }
125     
126     /**
127      * Adds a collectin of successes
128      * @param Collection a collection of successes
129      */
130     public void addAllSuccesses(Collection<T> c) {
131         successes.addAll(c);
132     }
133     
134     /**
135      * Adds the contents of the specified ProcessingResult to this ProcessingResult
136      * @param result the result to append to this result
137      */
138     public void add(ProcessingResult<T> result) {
139         failures.addAll(result.getFailures());
140         successes.addAll(result.getSuccesses());
141     }
142     
143     /**
144      * Returns a string representation of this ProcessingResults object
145      * @see java.lang.Object#toString()
146      */
147     public String toString() {
148         return "[ProcessingResults: successes(" + successes.size() + ")=" + successes +
149                                  ", failures(" + failures.size() + ")=" + failures + "]";
150     }
151 }