001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kcb.quartz; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.List; 021 022 /** 023 * Encapsulates the number of successes and failures in a giving processing run 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026 public class ProcessingResult<T> { 027 /** 028 * Represents a failure of a work item 029 */ 030 public static class Failure<T> { 031 private T item; 032 private Throwable exception; 033 private String message; 034 035 public Failure(T item) { 036 this.item = item; 037 } 038 039 public Failure(String message) { 040 this(null, null, message); 041 } 042 043 public Failure(Throwable exception) { 044 this(null, exception, null); 045 } 046 047 public Failure(Throwable exception, String message) { 048 this(null, exception, message); 049 } 050 051 052 public Failure(T item, Throwable exception) { 053 this(item, exception, null); 054 } 055 056 public Failure(T item, String message) { 057 this(item, null, message); 058 } 059 060 public Failure(T item, Throwable exception, String message) { 061 this.item = item; 062 this.exception = exception; 063 this.message = message; 064 } 065 066 public T getItem() { 067 return this.item; 068 } 069 public Throwable getException() { 070 return this.exception; 071 } 072 public String getMessage() { 073 return this.message; 074 } 075 } 076 077 /** 078 * List of failures 079 */ 080 private List<Failure<T>> failures = new ArrayList<Failure<T>>(); 081 /** 082 * List of successes 083 */ 084 private List<T> successes = new ArrayList<T>(); 085 086 /** 087 * Returns the list of failures 088 * @return the list of failures 089 */ 090 public List<Failure<T>> getFailures() { 091 return failures; 092 } 093 094 /** 095 * Returns the list of successes 096 * @return the list of successes 097 */ 098 public List<T> getSuccesses() { 099 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 }