| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ValidationResult |
|
| 1.0769230769230769;1.077 |
| 1 | package us.daveread.utility.formatcheck.format; | |
| 2 | ||
| 3 | import java.util.*; | |
| 4 | ||
| 5 | /** | |
| 6 | * <p>Title: ValidationResult | |
| 7 | * <p>Description: Holds the results of a validation | |
| 8 | * <p>Copyright: Copyright (c) 2005 | |
| 9 | * <p>This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * <p>This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * <p>You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | * </p> | |
| 21 | * | |
| 22 | * @author David Read | |
| 23 | * @version $Id: ValidationResult.java,v 1.1.1.1 2006/05/22 02:14:09 daveread Exp $ | |
| 24 | */ | |
| 25 | public class ValidationResult { | |
| 26 | ||
| 27 | /** Number of opportunities */ | |
| 28 | private int numOpportunities; | |
| 29 | ||
| 30 | /** Collection of defect messages - one per defect */ | |
| 31 | private List defectMessages; | |
| 32 | ||
| 33 | /** Matchlock setting */ | |
| 34 | private boolean matchLock; | |
| 35 | ||
| 36 | /** Matched record type identifier */ | |
| 37 | private int matchedRecordTypeId; | |
| 38 | ||
| 39 | /** | |
| 40 | * Sets up a validation container with no opportunities and defects. | |
| 41 | */ | |
| 42 | 29 | public ValidationResult() { |
| 43 | 29 | setNumOpportunities(0); |
| 44 | 29 | defectMessages = new ArrayList(); |
| 45 | 29 | } |
| 46 | ||
| 47 | /** | |
| 48 | * Sets the number of opportunities. | |
| 49 | * | |
| 50 | * @param aNumOpportunities int The number of opportunities | |
| 51 | */ | |
| 52 | private void setNumOpportunities(int aNumOpportunities) { | |
| 53 | 29 | numOpportunities = aNumOpportunities; |
| 54 | 29 | } |
| 55 | ||
| 56 | /** | |
| 57 | * Add one to the count of opportunities for this validation result. | |
| 58 | */ | |
| 59 | public void addOpportunity() { | |
| 60 | 13 | numOpportunities++; |
| 61 | 13 | } |
| 62 | ||
| 63 | /** | |
| 64 | * Add a given number of opportunities to this validation result. The number | |
| 65 | * must be a positive integer. | |
| 66 | * | |
| 67 | * @param aNumToAdd int The number of opportunities to add | |
| 68 | */ | |
| 69 | public void addOpportunities(int aNumToAdd) { | |
| 70 | 21 | if (aNumToAdd > 0) { |
| 71 | 14 | numOpportunities += aNumToAdd; |
| 72 | } | |
| 73 | 21 | } |
| 74 | ||
| 75 | /** | |
| 76 | * Gets the number of opportuinities for this validation result. | |
| 77 | * | |
| 78 | * @return int The number of opportuinities | |
| 79 | */ | |
| 80 | public int getNumOpportunities() { | |
| 81 | 7 | return numOpportunities; |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Adds a defect to the validation result. Defects are set as strings which | |
| 86 | * should explain the nature of the defect. | |
| 87 | * | |
| 88 | * @param aDefectMessage String The definition of the defect | |
| 89 | */ | |
| 90 | public void addDefectMessage(String aDefectMessage) { | |
| 91 | 13 | defectMessages.add(aDefectMessage); |
| 92 | 13 | } |
| 93 | ||
| 94 | /** | |
| 95 | * Gets the number of defects for this validation result. | |
| 96 | * | |
| 97 | * @return int The number of defects | |
| 98 | */ | |
| 99 | public int getNumDefects() { | |
| 100 | 19 | return defectMessages.size(); |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * Gets a specific defect message at the index requested. | |
| 105 | * | |
| 106 | * @param aIndex int The index of the requested defect message | |
| 107 | * | |
| 108 | * @return String The defect message | |
| 109 | */ | |
| 110 | public String getDefectMessage(int aIndex) { | |
| 111 | 2 | return (String) defectMessages.get(aIndex); |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Returns the status of the validation result based on whether any | |
| 116 | * defects were identified. If the number of defecxts is 0, this method | |
| 117 | * returns true. Otherwise it returns false. | |
| 118 | * | |
| 119 | * @return boolean True if no defects were found | |
| 120 | */ | |
| 121 | public boolean isValid() { | |
| 122 | 10 | return defectMessages.size() == 0; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Sets the matchlock condition for this validation result. This is used | |
| 127 | * to lock the comparison to the current definition. | |
| 128 | * | |
| 129 | * @param aMatchLock boolean The matchlock setting | |
| 130 | */ | |
| 131 | public void setMatchLock(boolean aMatchLock) { | |
| 132 | 7 | matchLock = aMatchLock; |
| 133 | 7 | } |
| 134 | ||
| 135 | /** | |
| 136 | * Gets the matchlock setting for this validation result. If the matchlock | |
| 137 | * is set the method will return true. | |
| 138 | * | |
| 139 | * @return boolean True if the matchlock is set, false otherwise | |
| 140 | */ | |
| 141 | public boolean isMatchLock() { | |
| 142 | 20 | return matchLock; |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * Sets the definition id of the match for this validation result. | |
| 147 | * | |
| 148 | * @param aRecordTypeId int The definition id of the match | |
| 149 | */ | |
| 150 | public void setMatchedRecordTypeId(int aRecordTypeId) { | |
| 151 | 5 | matchedRecordTypeId = aRecordTypeId; |
| 152 | 5 | } |
| 153 | ||
| 154 | /** | |
| 155 | * Gets the definition id of the match for this validation result. | |
| 156 | * | |
| 157 | * @return int The definition id of the match | |
| 158 | */ | |
| 159 | public int getMatchedRecordTypeId() { | |
| 160 | 0 | return matchedRecordTypeId; |
| 161 | } | |
| 162 | } |