Skip to content
Snippets Groups Projects
Commit edc59b90 authored by izabel's avatar izabel
Browse files

[SE-33] code refactoring: properties (small changes)

property name => property code
getIsFlag => isFlag
PropertyType.userLabel => PropertyType.label
Remove @deprecated

SVN: 6089
parent b6cc812a
No related branches found
No related tags found
No related merge requests found
......@@ -85,12 +85,12 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac
return converterPool.convert(value, type);
}
/** For given property name returns corresponding <code>IPropertyModel</code>. */
private final IPropertyModel tryGetPropertyModel(final String name)
/** For given property code returns corresponding <code>IPropertyModel</code>. */
private final IPropertyModel tryGetPropertyModel(final String code)
{
if (propertyMapper.containsPropertyName(name))
if (propertyMapper.containsPropertyCode(code))
{
return propertyMapper.getPropertyModel(name);
return propertyMapper.getPropertyModel(code);
}
return null;
}
......@@ -107,31 +107,30 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac
private final void checkPropertyMapper(final Class<E> clazz, final IPropertyMapper propMapper)
throws ParserException
{
final Set<String> allPropertyNames = propMapper.getAllPropertyNames();
final Set<String> propertyNames = new LinkedHashSet<String>(allPropertyNames);
final Set<String> allPropertyCodes = propMapper.getAllPropertyCodes();
final Set<String> propertyCodes = new LinkedHashSet<String>(allPropertyCodes);
final Set<String> missingProperties = new LinkedHashSet<String>();
final Set<String> fieldNames = beanAnalyzer.getLabelToWriteMethods().keySet();
for (final String fieldName : fieldNames)
{
final String fieldNameInLowerCase = fieldName.toLowerCase();
if (propertyNames.contains(fieldNameInLowerCase))
if (propertyCodes.contains(fieldNameInLowerCase))
{
propertyNames.remove(fieldNameInLowerCase);
propertyCodes.remove(fieldNameInLowerCase);
} else if (beanAnalyzer.isMandatory(fieldName))
{
missingProperties.add(fieldName);
}
}
final Set<String> mandatoryPropertyNames =
beanAnalyzer.getMandatoryProperties();
final Set<String> mandatoryPropertyCodes = beanAnalyzer.getMandatoryProperties();
if (missingProperties.size() > 0)
{
throw new MandatoryPropertyMissingException(mandatoryPropertyNames, missingProperties);
throw new MandatoryPropertyMissingException(mandatoryPropertyCodes, missingProperties);
}
if (propertyNames.size() > 0)
if (propertyCodes.size() > 0)
{
throw new UnmatchedPropertiesException(clazz, allPropertyNames, mandatoryPropertyNames,
beanAnalyzer.getOptionalProperties(), propertyNames);
throw new UnmatchedPropertiesException(clazz, allPropertyCodes, mandatoryPropertyCodes,
beanAnalyzer.getOptionalProperties(), propertyCodes);
}
}
......
......@@ -48,7 +48,7 @@ public class DefaultPropertyMapper implements IPropertyMapper
public final String getKey(final IPropertyModel e)
{
return e.getName().toLowerCase();
return e.getCode().toLowerCase();
}
});
tokensToMap(properties);
......@@ -74,24 +74,24 @@ public class DefaultPropertyMapper implements IPropertyMapper
// IPropertyMapper
//
public final boolean containsPropertyName(final String propertyName)
public final boolean containsPropertyCode(final String propertyCode)
{
return propertyModels.tryGet(propertyName.toLowerCase()) != null;
return propertyModels.tryGet(propertyCode.toLowerCase()) != null;
}
public final Set<String> getAllPropertyNames()
public final Set<String> getAllPropertyCodes()
{
return new TreeSet<String>(propertyModels.keySet());
}
public final IPropertyModel getPropertyModel(final String propertyName)
public final IPropertyModel getPropertyModel(final String propertyCode)
throws IllegalArgumentException
{
if (containsPropertyName(propertyName) == false)
if (containsPropertyCode(propertyCode) == false)
{
throw new IllegalArgumentException(String.format(
"Given property name '%s' does not exist.", propertyName));
throw new IllegalArgumentException(String.format("Given property '%s' does not exist.",
propertyCode));
}
return propertyModels.tryGet(propertyName.toLowerCase());
return propertyModels.tryGet(propertyCode.toLowerCase());
}
}
......@@ -20,7 +20,7 @@ import java.util.Set;
/**
* The job of <code>PropertyMapper</code> is to return mapping informations regarding a given
* property name.
* property code.
*
* @author Christian Ribeaud
*/
......@@ -28,23 +28,23 @@ public interface IPropertyMapper
{
/**
* Returns an <code>IPropertyModel</code> for a given property name.
* Returns an <code>IPropertyModel</code> for a given property code.
*
* @throws IllegalArgumentException if given <var>propertyName</var> does not exist.
* @throws IllegalArgumentException if given <var>propertyCode</var> does not exist.
*/
public IPropertyModel getPropertyModel(final String propertyName)
public IPropertyModel getPropertyModel(final String propertyCode)
throws IllegalArgumentException;
/**
* Returns a set of all property names.
* Returns a set of all property codes.
* <p>
* Note that changes applied to returned <code>Set</code> are not reflected in the backed
* collection.
* </p>
*/
public Set<String> getAllPropertyNames();
public Set<String> getAllPropertyCodes();
/** Whether there is a property with given <var>propertyName</var>. */
public boolean containsPropertyName(final String propertyName);
/** Whether there is a property with given <var>propertyCode</var>. */
public boolean containsPropertyCode(final String propertyCode);
}
\ No newline at end of file
......@@ -30,8 +30,8 @@ public interface IPropertyModel
/** Returns the column number where the information regarding this property could be found. */
public int getColumn();
/** Returns the property name as it has been found in the parsed file. */
public String getName();
/** Returns the property code as it has been found in the parsed file. */
public String getCode();
/**
* Returns the format of this property.
......
......@@ -31,7 +31,7 @@ public final class MandatoryPropertyMissingException extends ParserException
{
private static final long serialVersionUID = 1L;
/** The mandatory property names that could not be found in the parsed file. */
/** The mandatory property codes that could not be found in the parsed file. */
private final Set<String> missingMandatoryProperties;
/** The fields that are mandatory. */
......
......@@ -60,7 +60,7 @@ final class MappedProperty implements IPropertyModel
return column;
}
public final String getName()
public final String getCode()
{
return name;
}
......
......@@ -34,43 +34,43 @@ public final class UnmatchedPropertiesException extends ParserException
/** The bean this is set during the parsing process. */
private final Class<?> beanClass;
/** The property names found in the parsed file. */
private final Set<String> allPropertyNames;
/** The property codes found in the parsed file. */
private final Set<String> allPropertyCodes;
/** The mandatory property names found in the bean. */
private final Set<String> mandatoryNames;
/** The mandatory property codes found in the bean. */
private final Set<String> mandatoryCodes;
/** The optional property names found in the bean. */
private final Set<String> optionalNames;
/** The optional property codes found in the bean. */
private final Set<String> optionalCodes;
/**
* The property names of {@link #allPropertyNames} that can neither be found in
* {@link #mandatoryNames} nor in {@link #optionalNames}.
* The property codes of {@link #allPropertyCodes} that can neither be found in
* {@link #mandatoryCodes} nor in {@link #optionalCodes}.
*/
private final Set<String> propertyNames;
private final Set<String> propertyCodes;
public UnmatchedPropertiesException(final Class<?> beanClass,
final Set<String> allPropertyNames, final Set<String> mandatoryNames,
final Set<String> optionalNames, final Set<String> propertyNames)
final Set<String> allPropertyCodes, final Set<String> mandatoryCodes,
final Set<String> optionalCodes, final Set<String> propertyCodes)
{
super(createMessage(propertyNames, mandatoryNames, optionalNames));
assert allPropertyNames != null : "All property names can not be null.";
assert mandatoryNames != null : "Mandatory names can not be null.";
assert optionalNames != null : "Optional names can not be null.";
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.allPropertyNames = allPropertyNames;
this.mandatoryNames = mandatoryNames;
this.optionalNames = optionalNames;
this.propertyNames = propertyNames;
this.allPropertyCodes = allPropertyCodes;
this.mandatoryCodes = mandatoryCodes;
this.optionalCodes = optionalCodes;
this.propertyCodes = propertyCodes;
}
private final static String createMessage(Set<String> propertyNames,
private final static String createMessage(Set<String> propertyCodes,
Set<String> mandatoryNames, Set<String> optionalNames)
{
assert propertyNames != null : "Property names can not be null.";
assert propertyNames.size() > 0 : "There is no reason to throw this exception.";
assert propertyCodes != null : "Property codes can not be null.";
assert propertyCodes.size() > 0 : "There is no reason to throw this exception.";
final StringBuilder builder = new StringBuilder();
builder.append("Columns ").append(toString(propertyNames)).append(
builder.append("Columns ").append(toString(propertyCodes)).append(
" specified in the header are not expected (");
final boolean hasMandatory = mandatoryNames.size() > 0;
if (hasMandatory)
......@@ -102,24 +102,24 @@ public final class UnmatchedPropertiesException extends ParserException
return beanClass;
}
public final Set<String> getAllPropertyNames()
public final Set<String> getAllPropertyCodes()
{
return Collections.unmodifiableSet(allPropertyNames);
return Collections.unmodifiableSet(allPropertyCodes);
}
public final Set<String> getPropertyNames()
public final Set<String> getPropertyCodes()
{
return Collections.unmodifiableSet(propertyNames);
return Collections.unmodifiableSet(propertyCodes);
}
public final Set<String> getMandatoryNames()
{
return Collections.unmodifiableSet(mandatoryNames);
return Collections.unmodifiableSet(mandatoryCodes);
}
public final Set<String> getOptionalNames()
{
return Collections.unmodifiableSet(optionalNames);
return Collections.unmodifiableSet(optionalCodes);
}
}
......@@ -101,7 +101,7 @@ public final class AbstractParserObjectFactoryTest
final String[] lineTokens = new String[]
{ "1. experiment" };
beanFactory.createObject(lineTokens);
fail("Field/Property name 'name' is mandatory.");
fail("Field/Property code 'name' is mandatory.");
} catch (final MandatoryPropertyMissingException ex)
{
AssertJUnit.assertTrue(ex.getMessage().indexOf("name") > 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment