| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ProcessingResult |
|
| 1.0;1 | ||||
| ProcessingResult$Failure |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2007-2008 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 | 0 | 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 | 0 | public Failure(T item) { |
| 36 | 0 | this.item = item; |
| 37 | 0 | } |
| 38 | ||
| 39 | public Failure(String message) { | |
| 40 | 0 | this(null, null, message); |
| 41 | 0 | } |
| 42 | ||
| 43 | public Failure(Throwable exception) { | |
| 44 | 0 | this(null, exception, null); |
| 45 | 0 | } |
| 46 | ||
| 47 | public Failure(Throwable exception, String message) { | |
| 48 | 0 | this(null, exception, message); |
| 49 | 0 | } |
| 50 | ||
| 51 | ||
| 52 | public Failure(T item, Throwable exception) { | |
| 53 | 0 | this(item, exception, null); |
| 54 | 0 | } |
| 55 | ||
| 56 | public Failure(T item, String message) { | |
| 57 | 0 | this(item, null, message); |
| 58 | 0 | } |
| 59 | ||
| 60 | 0 | public Failure(T item, Throwable exception, String message) { |
| 61 | 0 | this.item = item; |
| 62 | 0 | this.exception = exception; |
| 63 | 0 | this.message = message; |
| 64 | 0 | } |
| 65 | ||
| 66 | public T getItem() { | |
| 67 | 0 | return this.item; |
| 68 | } | |
| 69 | public Throwable getException() { | |
| 70 | 0 | return this.exception; |
| 71 | } | |
| 72 | public String getMessage() { | |
| 73 | 0 | return this.message; |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * List of failures | |
| 79 | */ | |
| 80 | 0 | private List<Failure<T>> failures = new ArrayList<Failure<T>>(); |
| 81 | /** | |
| 82 | * List of successes | |
| 83 | */ | |
| 84 | 0 | 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 | 0 | return failures; |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * Returns the list of successes | |
| 96 | * @return the list of successes | |
| 97 | */ | |
| 98 | public List<T> getSuccesses() { | |
| 99 | 0 | 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 | 0 | failures.add(o); |
| 108 | 0 | } |
| 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 | 0 | failures.addAll(c); |
| 116 | 0 | } |
| 117 | ||
| 118 | /** | |
| 119 | * Adds a success | |
| 120 | * @param o an object representing a success | |
| 121 | */ | |
| 122 | public void addSuccess(T o) { | |
| 123 | 0 | successes.add(o); |
| 124 | 0 | } |
| 125 | ||
| 126 | /** | |
| 127 | * Adds a collectin of successes | |
| 128 | * @param Collection a collection of successes | |
| 129 | */ | |
| 130 | public void addAllSuccesses(Collection<T> c) { | |
| 131 | 0 | successes.addAll(c); |
| 132 | 0 | } |
| 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 | 0 | failures.addAll(result.getFailures()); |
| 140 | 0 | successes.addAll(result.getSuccesses()); |
| 141 | 0 | } |
| 142 | ||
| 143 | /** | |
| 144 | * Returns a string representation of this ProcessingResults object | |
| 145 | * @see java.lang.Object#toString() | |
| 146 | */ | |
| 147 | public String toString() { | |
| 148 | 0 | return "[ProcessingResults: successes(" + successes.size() + ")=" + successes + |
| 149 | ", failures(" + failures.size() + ")=" + failures + "]"; | |
| 150 | } | |
| 151 | } |