diff --git a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java index 8838a680fe05238e031fbac91a10de84a14300ed..20846241dd1e1e7b255a199f1135dde2a3c1680d 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/AbstractParserObjectFactory.java @@ -129,8 +129,8 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac } if (propertyCodes.size() > 0) { - throw new UnmatchedPropertiesException(clazz, allPropertyCodes, mandatoryPropertyCodes, - beanAnalyzer.getOptionalProperties(), propertyCodes); + throw new UnmatchedPropertiesException(mandatoryPropertyCodes, beanAnalyzer + .getOptionalProperties(), propertyCodes); } } diff --git a/common/source/java/ch/systemsx/cisd/common/parser/IndexOutOfBoundsException.java b/common/source/java/ch/systemsx/cisd/common/parser/IndexOutOfBoundsException.java index 0ca5a739e19f09fe50b8423367d9f1175125608d..cde91345126d65ea54ba80b62ec0262d36438e78 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/IndexOutOfBoundsException.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/IndexOutOfBoundsException.java @@ -28,38 +28,24 @@ import ch.systemsx.cisd.common.utilities.StringUtilities; */ public final class IndexOutOfBoundsException extends ParserException { - private static final long serialVersionUID = 1L; - - private final int column; + private static final String MESSAGE_FORMAT = + "Not enough columns available. Looking for %s column but we have only %d columns (%s)."; - private final String[] lineTokens; + private static final long serialVersionUID = 1L; public IndexOutOfBoundsException(final int index, final String[] lineTokens) { super(createMessage(index, lineTokens)); - this.column = index; - this.lineTokens = lineTokens; } private final static String createMessage(final int index, final String[] lineTokens) { assert lineTokens != null : "Line tokens can not be null."; - assert index >= lineTokens.length : "Index must be out of range (otherwise no reason to call this exception)."; - return String - .format( - "Not enough columns available. Looking for %s column but we have only %d columns (%s).", - StringUtilities.getOrdinal(index + 1), lineTokens.length, CollectionUtils - .abbreviate(lineTokens, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY)); - } - - public final int getColumn() - { - return column; - } - - public final String[] getLineTokens() - { - return lineTokens; + assert index >= lineTokens.length : "Index must be out of range (otherwise no reason " + + "to call this exception)."; + return String.format(MESSAGE_FORMAT, StringUtilities.getOrdinal(index + 1), + lineTokens.length, CollectionUtils.abbreviate(lineTokens, -1, + CollectionStyle.SINGLE_QUOTE_BOUNDARY)); } } diff --git a/common/source/java/ch/systemsx/cisd/common/parser/MandatoryPropertyMissingException.java b/common/source/java/ch/systemsx/cisd/common/parser/MandatoryPropertyMissingException.java index bde40cd002afa8c1a0bb2ee02efd56320fdb23a9..ac76b1177fcd3f9b6e9094211d77c23eb7c95753 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/MandatoryPropertyMissingException.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/MandatoryPropertyMissingException.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.common.parser; -import java.util.Collections; import java.util.Set; import ch.systemsx.cisd.common.collections.CollectionStyle; @@ -29,21 +28,15 @@ import ch.systemsx.cisd.common.collections.CollectionUtils; */ public final class MandatoryPropertyMissingException extends ParserException { - private static final long serialVersionUID = 1L; - - /** The mandatory property codes that could not be found in the parsed file. */ - private final Set<String> missingMandatoryProperties; + private static final String MESSAGE_FORMAT = + "Mandatory column(s) %s are missing (mandatory columns are %s)."; - /** The fields that are mandatory. */ - private final Set<String> mandatoryFields; + private static final long serialVersionUID = 1L; public MandatoryPropertyMissingException(final Set<String> mandatoryFields, final Set<String> missingMandatoryProperties) { super(createMessage(missingMandatoryProperties, mandatoryFields)); - assert mandatoryFields != null && mandatoryFields.size() > 0 : "Unspecified mandatory fields."; - this.mandatoryFields = mandatoryFields; - this.missingMandatoryProperties = missingMandatoryProperties; } private final static String createMessage(final Set<String> missingMandatoryProperties, @@ -51,8 +44,8 @@ public final class MandatoryPropertyMissingException extends ParserException { assert missingMandatoryProperties != null : "Missing mandatory properties can not be null."; assert missingMandatoryProperties.size() > 0 : "No reason to throw this exception."; - return String.format("Mandatory column(s) %s are missing (mandatory columns are %s).", - toString(missingMandatoryProperties), toString(mandatoryFields)); + return String.format(MESSAGE_FORMAT, toString(missingMandatoryProperties), + toString(mandatoryFields)); } final static String toString(final Set<String> set) @@ -60,13 +53,4 @@ public final class MandatoryPropertyMissingException extends ParserException return CollectionUtils.abbreviate(set, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY); } - public final Set<String> getMissingMandatoryProperties() - { - return Collections.unmodifiableSet(missingMandatoryProperties); - } - - public final Set<String> getMandatoryFields() - { - return Collections.unmodifiableSet(mandatoryFields); - } } diff --git a/common/source/java/ch/systemsx/cisd/common/parser/UnmatchedPropertiesException.java b/common/source/java/ch/systemsx/cisd/common/parser/UnmatchedPropertiesException.java index 2f2ac5e91bdeee5eb27f1b4d3f8c3e1a2fd9885c..19a37c9c429b5565e946d962e0c68fe99abf9bed 100644 --- a/common/source/java/ch/systemsx/cisd/common/parser/UnmatchedPropertiesException.java +++ b/common/source/java/ch/systemsx/cisd/common/parser/UnmatchedPropertiesException.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.common.parser; -import java.util.Collections; import java.util.Set; import ch.systemsx.cisd.common.collections.CollectionStyle; @@ -31,46 +30,19 @@ public final class UnmatchedPropertiesException extends ParserException { private static final long serialVersionUID = 1L; - /** The bean this is set during the parsing process. */ - private final Class<?> beanClass; - - /** The property codes found in the parsed file. */ - private final Set<String> allPropertyCodes; - - /** The mandatory property codes found in the bean. */ - private final Set<String> mandatoryCodes; - - /** The optional property codes found in the bean. */ - private final Set<String> optionalCodes; - - /** - * The property codes of {@link #allPropertyCodes} that can neither be found in - * {@link #mandatoryCodes} nor in {@link #optionalCodes}. - */ - private final Set<String> propertyCodes; - - public UnmatchedPropertiesException(final Class<?> beanClass, - final Set<String> allPropertyCodes, final Set<String> mandatoryCodes, - final Set<String> optionalCodes, final Set<String> propertyCodes) + public UnmatchedPropertiesException(final Set<String> mandatoryNames, + final Set<String> optionalNames, final Set<String> propertyNames) { - super(createMessage(propertyCodes, mandatoryCodes, optionalCodes)); - assert allPropertyCodes != null : "All property codes can not be null."; - assert mandatoryCodes != null : "Mandatory codes can not be null."; - assert optionalCodes != null : "Optional codes can not be null."; - this.beanClass = beanClass; - this.allPropertyCodes = allPropertyCodes; - this.mandatoryCodes = mandatoryCodes; - this.optionalCodes = optionalCodes; - this.propertyCodes = propertyCodes; + super(createMessage(propertyNames, mandatoryNames, optionalNames)); } - private final static String createMessage(Set<String> propertyCodes, + private final static String createMessage(Set<String> propertyNames, Set<String> mandatoryNames, Set<String> optionalNames) { - assert propertyCodes != null : "Property codes can not be null."; - assert propertyCodes.size() > 0 : "There is no reason to throw this exception."; + assert propertyNames != null : "Property names can not be null."; + assert propertyNames.size() > 0 : "There is no reason to throw this exception."; final StringBuilder builder = new StringBuilder(); - builder.append("Columns ").append(toString(propertyCodes)).append( + builder.append("Columns ").append(toString(propertyNames)).append( " specified in the header are not expected ("); final boolean hasMandatory = mandatoryNames.size() > 0; if (hasMandatory) @@ -97,29 +69,4 @@ public final class UnmatchedPropertiesException extends ParserException return CollectionUtils.abbreviate(set, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY); } - public final Class<?> getBeanClass() - { - return beanClass; - } - - public final Set<String> getAllPropertyCodes() - { - return Collections.unmodifiableSet(allPropertyCodes); - } - - public final Set<String> getPropertyCodes() - { - return Collections.unmodifiableSet(propertyCodes); - } - - public final Set<String> getMandatoryNames() - { - return Collections.unmodifiableSet(mandatoryCodes); - } - - public final Set<String> getOptionalNames() - { - return Collections.unmodifiableSet(optionalCodes); - } - }