Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using modern Java APIs #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/org/beanio/BeanReaderErrorHandlerSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public BeanReaderErrorHandlerSupport() { }
* @throws Exception if the BeanReaderException is rethrown or this error
* handler throws a new Exception
*/
@Override
public final void handleError(BeanReaderException ex) throws Exception {
if (ex instanceof InvalidRecordException) {
invalidRecord((InvalidRecordException)ex);
Expand Down
1 change: 1 addition & 0 deletions src/org/beanio/Marshaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public interface Marshaller extends Debuggable {
* @return the record text
* @throws BeanWriterException if a fatal error occurs
*/
@Override
public String toString() throws BeanWriterException;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/builder/CsvParserBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CsvParserBuilder alwaysQuote() throws BeanIOConfigurationException {

@Override
public BeanConfig<RecordParserFactory> build() {
BeanConfig<RecordParserFactory> config = new BeanConfig<RecordParserFactory>();
BeanConfig<RecordParserFactory> config = new BeanConfig<>();
config.setInstance(parser);
return config;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/builder/DelimitedParserBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DelimitedParserBuilder enableComments(String... comments) {

@Override
public BeanConfig<RecordParserFactory> build() {
BeanConfig<RecordParserFactory> config = new BeanConfig<RecordParserFactory>();
BeanConfig<RecordParserFactory> config = new BeanConfig<>();
config.setInstance(parser);
return config;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/builder/FixedLengthParserBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public FixedLengthParserBuilder enableComments(String... comments) {

@Override
public BeanConfig<RecordParserFactory> build() {
BeanConfig<RecordParserFactory> config = new BeanConfig<RecordParserFactory>();
BeanConfig<RecordParserFactory> config = new BeanConfig<>();
config.setInstance(parser);
return config;
}
Expand Down
1 change: 1 addition & 0 deletions src/org/beanio/builder/SegmentBuilderSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class SegmentBuilderSupport<T extends SegmentBuilderSupport<T>>

SegmentBuilderSupport() { }

@Override
protected abstract SegmentConfig getConfig();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/builder/StreamBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public StreamBuilder format(String format) {
* @return this
*/
public StreamBuilder parser(RecordParserFactory parser) {
BeanConfig<RecordParserFactory> bc = new BeanConfig<RecordParserFactory>();
BeanConfig<RecordParserFactory> bc = new BeanConfig<>();
bc.setInstance(parser);
config.setParserFactory(bc);
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/builder/XmlParserBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public XmlParserBuilder lineSeparator(String sep) {

@Override
public BeanConfig<RecordParserFactory> build() {
BeanConfig<RecordParserFactory> config = new BeanConfig<RecordParserFactory>();
BeanConfig<RecordParserFactory> config = new BeanConfig<>();
config.setInstance(parser);
return config;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/internal/DefaultStreamFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class DefaultStreamFactory extends StreamFactory {

private StreamCompiler compiler;
private Map<String, Stream> contextMap = new ConcurrentHashMap<String, Stream>();
private Map<String, Stream> contextMap = new ConcurrentHashMap<>();

/**
* Constructs a new <tt>DefaultStreamFactory</tt>.
Expand Down
14 changes: 9 additions & 5 deletions src/org/beanio/internal/compiler/ParserFactorySupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public abstract class ParserFactorySupport extends ProcessorSupport implements P
private PropertyAccessorFactory accessorFactory;
private ClassLoader classLoader;

private LinkedList<Component> parserStack = new LinkedList<Component>();
private LinkedList<Component> propertyStack = new LinkedList<Component>();
private LinkedList<Component> parserStack = new LinkedList<>();
private LinkedList<Component> propertyStack = new LinkedList<>();

/**
* Constructs a new <tt>ParserFactory</tt>.
Expand All @@ -76,6 +76,7 @@ public ParserFactorySupport() { }
* @return the new {@link Stream}
* @throws BeanIOConfigurationException if the configuration is invalid
*/
@Override
public Stream createStream(StreamConfig config) throws BeanIOConfigurationException {
if (config.getName() == null) {
throw new BeanIOConfigurationException("stream name not configured");
Expand Down Expand Up @@ -232,7 +233,7 @@ protected void updateConstructor(Bean bean) {

if (property.getAccessor().isConstructorArgument()) {
if (args == null) {
args = new ArrayList<Property>();
args = new ArrayList<>();
}
args.add(property);
}
Expand All @@ -245,6 +246,7 @@ protected void updateConstructor(Bean bean) {

// sort arguments by constructor index
Collections.sort(args, new Comparator<Property>() {
@Override
public int compare(Property o1, Property o2) {
return o1.getAccessor().getConstructorArgumentIndex() -
o2.getAccessor().getConstructorArgumentIndex();
Expand Down Expand Up @@ -1527,7 +1529,7 @@ protected Property createProperty(PropertyConfig config) {
if (config.getComponentType() == ComponentConfig.SEGMENT) {
required = config.getMinOccurs() > 0 && !config.isNillable();
}
boolean matchNull = !required && new Integer(0).equals(config.getMinOccurs());
boolean matchNull = !required && Integer.valueOf(0).equals(config.getMinOccurs());

CollectionBean collection = new CollectionBean();
collection.setName(config.getName());
Expand All @@ -1538,7 +1540,7 @@ protected Property createProperty(PropertyConfig config) {
}
else {
boolean required = propertyStack.isEmpty();
boolean matchNull = !required && new Integer(0).equals(config.getMinOccurs());
boolean matchNull = !required && Integer.valueOf(0).equals(config.getMinOccurs());

Bean bean = new Bean();
bean.setName(config.getName());
Expand Down Expand Up @@ -1652,6 +1654,7 @@ protected Object parseDefaultValue(Field field, String text) {
* @param typeHandlerFactory the <tt>TypeHandlerFactory</tt> to use to
* create the stream definition
*/
@Override
public void setTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory) {
this.typeHandlerFactory = typeHandlerFactory;
}
Expand Down Expand Up @@ -1721,6 +1724,7 @@ else if (parserFactoryBean.getInstance() != null) {
* (non-Javadoc)
* @see org.beanio.factory.ParserFactory#setClassLoader(java.lang.ClassLoader)
*/
@Override
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
Expand Down
11 changes: 11 additions & 0 deletions src/org/beanio/internal/compiler/Preprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Preprocessor(StreamConfig stream) {
* Initializes a stream configuration before its children have been processed.
* @param stream the stream configuration to process
*/
@Override
protected void initializeStream(StreamConfig stream) throws BeanIOConfigurationException {
if (stream.getMinOccurs() == null) {
stream.setMinOccurs(0);
Expand All @@ -68,6 +69,7 @@ protected void initializeStream(StreamConfig stream) throws BeanIOConfigurationE
* Finalizes a stream configuration after its children have been processed.
* @param stream the stream configuration to finalize
*/
@Override
protected void finalizeStream(StreamConfig stream) throws BeanIOConfigurationException {
finalizeGroup(stream);

Expand All @@ -78,6 +80,7 @@ protected void finalizeStream(StreamConfig stream) throws BeanIOConfigurationExc

if (sorted) {
stream.sort(new Comparator<ComponentConfig>() {
@Override
public int compare(ComponentConfig c1, ComponentConfig c2) {
Integer p1 = getPosition(c1);
Integer p2 = getPosition(c2);
Expand Down Expand Up @@ -125,6 +128,7 @@ private Integer getPosition(ComponentConfig c) {
* Initializes a group configuration before its children have been processed.
* @param group the group configuration to process
*/
@Override
protected void initializeGroup(GroupConfig group) throws BeanIOConfigurationException {

if (group.getMinOccurs() == null) {
Expand Down Expand Up @@ -171,6 +175,7 @@ protected void initializeGroup(GroupConfig group) throws BeanIOConfigurationExce
* Finalizes a group configuration after its children have been processed.
* @param group the group configuration to finalize
*/
@Override
protected void finalizeGroup(GroupConfig group) throws BeanIOConfigurationException {

// order must be set for all group children, or for none of them
Expand Down Expand Up @@ -225,6 +230,7 @@ else if (orderSet ^ (child.getOrder() != null)) {
* Initializes a record configuration before its children have been processed.
* @param record the record configuration to process
*/
@Override
protected void initializeRecord(RecordConfig record) throws BeanIOConfigurationException {

// a record is ignored if a 'class' was not set and the property root is null
Expand Down Expand Up @@ -262,6 +268,7 @@ protected void initializeRecord(RecordConfig record) throws BeanIOConfigurationE
* Finalizes a record configuration after its children have been processed.
* @param record the record configuration to process
*/
@Override
protected void finalizeRecord(RecordConfig record) throws BeanIOConfigurationException {
finalizeSegment(record);

Expand All @@ -274,6 +281,7 @@ protected void finalizeRecord(RecordConfig record) throws BeanIOConfigurationExc
* Initializes a segment configuration before its children have been processed.
* @param segment the segment configuration to process
*/
@Override
protected void initializeSegment(SegmentConfig segment) throws BeanIOConfigurationException {

if (segment.getName() == null) {
Expand Down Expand Up @@ -339,6 +347,7 @@ protected void initializeSegment(SegmentConfig segment) throws BeanIOConfigurati
* Finalizes a segment configuration after its children have been processed.
* @param segment the segment configuration to process
*/
@Override
protected void finalizeSegment(SegmentConfig segment) throws BeanIOConfigurationException {
for (PropertyConfig child : segment.getPropertyList()) {
if (child.isIdentifier()) {
Expand All @@ -352,6 +361,7 @@ protected void finalizeSegment(SegmentConfig segment) throws BeanIOConfiguration
* Processes a field configuration.
* @param field the field configuration to process
*/
@Override
protected void handleField(FieldConfig field) throws BeanIOConfigurationException {
// ignore fields that belong to ignored records
if (recordIgnored) {
Expand Down Expand Up @@ -418,6 +428,7 @@ protected void handleField(FieldConfig field) throws BeanIOConfigurationExceptio
* Processes a constant configuration.
* @param constant the constant configuration to process
*/
@Override
protected void handleConstant(ConstantConfig constant) throws BeanIOConfigurationException {
constant.setBound(true);

Expand Down
2 changes: 1 addition & 1 deletion src/org/beanio/internal/compiler/ProcessorSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public abstract class ProcessorSupport {

private LinkedList<ComponentConfig> configStack = new LinkedList<ComponentConfig>();
private LinkedList<ComponentConfig> configStack = new LinkedList<>();

/**
* Constructs a new <tt>ProcessorSupport</tt>.
Expand Down
6 changes: 3 additions & 3 deletions src/org/beanio/internal/compiler/StreamCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Collection<Stream> loadMapping(InputStream in, Properties properties) thr
}

// check for duplicate stream names...
HashSet<String> set = new HashSet<String>();
HashSet<String> set = new HashSet<>();
for (BeanIOConfig config : configList) {
for (StreamConfig streamConfig : config.getStreamList()) {
if (!set.add(streamConfig.getName())) {
Expand All @@ -103,7 +103,7 @@ public Collection<Stream> loadMapping(InputStream in, Properties properties) thr
return createStreamDefinitions(configList.iterator().next());
}
else {
List<Stream> list = new ArrayList<Stream>();
List<Stream> list = new ArrayList<>();
for (BeanIOConfig config : configList) {
list.addAll(createStreamDefinitions(config));
}
Expand Down Expand Up @@ -135,7 +135,7 @@ protected Collection<Stream> createStreamDefinitions(BeanIOConfig config)
config.getTypeHandlerList());

Collection<StreamConfig> streamConfigList = config.getStreamList();
Collection<Stream> streamDefinitionList = new ArrayList<Stream>(streamConfigList.size());
Collection<Stream> streamDefinitionList = new ArrayList<>(streamConfigList.size());

for (StreamConfig streamConfig : streamConfigList) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ReflectionAccessorFactory implements PropertyAccessorFactory {
* (non-Javadoc)
* @see org.beanio.internal.compiler.PropertyAccessorFactory#getPropertyAccessor(java.lang.Class, java.beans.PropertyDescriptor, int)
*/
@Override
public PropertyAccessor getPropertyAccessor(
Class<?> parent, PropertyDescriptor descriptor, int carg) {

Expand All @@ -31,6 +32,7 @@ public PropertyAccessor getPropertyAccessor(
* (non-Javadoc)
* @see org.beanio.internal.compiler.PropertyAccessorFactory#getPropertyAccessor(java.lang.Class, java.lang.reflect.Field, int)
*/
@Override
public PropertyAccessor getPropertyAccessor(
Class<?> parent, Field field, int carg) {

Expand Down
3 changes: 2 additions & 1 deletion src/org/beanio/internal/compiler/flat/FlatParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ protected void finalizeRecord(RecordConfig config, Record record) {
@SuppressWarnings("unused")
private static class NodeComparator implements Comparator<Component> {

private IdentityHashMap<Component, Integer> cache = new IdentityHashMap<Component, Integer>();
private IdentityHashMap<Component, Integer> cache = new IdentityHashMap<>();

/*
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Component o1, Component o2) {
return getPosition(o1).compareTo(getPosition(o2));
}
Expand Down
8 changes: 4 additions & 4 deletions src/org/beanio/internal/compiler/flat/FlatPreprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class FlatPreprocessor extends Preprocessor {
// the component that immediately follows the unbounded component
private PropertyConfig unboundedComponentFollower = null;
// the list of components at the end of the record following the unbounded component
private List<PropertyConfig> endComponents = new ArrayList<PropertyConfig>();
private List<PropertyConfig> endComponents = new ArrayList<>();
/* stack of non-record segments */
private LinkedList<SegmentConfig> segmentStack = new LinkedList<SegmentConfig>();
private LinkedList<SegmentConfig> segmentStack = new LinkedList<>();
/* list of field components belonging to a record, used for validating dynamic occurrences */
private List<FieldConfig> fieldComponents = new ArrayList<FieldConfig>();
private List<FieldConfig> fieldComponents = new ArrayList<>();

/**
* Constructs a new <tt>FlatPreprocessor</tt>.
Expand Down Expand Up @@ -360,7 +360,7 @@ else if (field.getLength() == null) {
}
}
else {
if (new Integer(-1).equals(field.getLength())) {
if (Integer.valueOf(-1).equals(field.getLength())) {
field.setLength(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected FieldFormat createFieldFormat(FieldConfig config, Class<?> type) {
format.setJsonName(config.getJsonName());
format.setJsonArray(config.isJsonArray());
format.setJsonArrayIndex(config.getJsonArrayIndex());
format.setLazy(config.getMinOccurs() != null && new Integer(0).equals(config.getMinOccurs()));
format.setLazy(config.getMinOccurs() != null && Integer.valueOf(0).equals(config.getMinOccurs()));
format.setNillable(true); // for now, allow any JSON field to be nullable

// default the JSON type based on the property type
Expand Down
4 changes: 2 additions & 2 deletions src/org/beanio/internal/config/BeanIOConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
public class BeanIOConfig implements Cloneable {

private String source;
private List<StreamConfig> streamList = new ArrayList<StreamConfig>();
private List<TypeHandlerConfig> handlerList = new ArrayList<TypeHandlerConfig>();
private List<StreamConfig> streamList = new ArrayList<>();
private List<TypeHandlerConfig> handlerList = new ArrayList<>();

/**
* Constructs a new <tt>BeanIOConfig</tt>.
Expand Down
3 changes: 3 additions & 0 deletions src/org/beanio/internal/config/GroupConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public char getComponentType() {
* number may appear in any order.
* @return the order of this record
*/
@Override
public Integer getOrder() {
return order;
}
Expand All @@ -58,6 +59,7 @@ public Integer getOrder() {
* number may appear in any order.
* @param order the order of this record
*/
@Override
public void setOrder(Integer order) {
this.order = order;
}
Expand All @@ -67,6 +69,7 @@ public void setOrder(Integer order) {
* Map key when <tt>collection</tt> is set to <tt>map</tt>.
* @return the key property name
*/
@Override
public String getKey() {
return key;
}
Expand Down
2 changes: 2 additions & 0 deletions src/org/beanio/internal/config/RecordConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void setMaxMatchLength(Integer maxMatchLength) {
* number may appear in any order.
* @return the order of this record
*/
@Override
public Integer getOrder() {
return order;
}
Expand All @@ -129,6 +130,7 @@ public Integer getOrder() {
* number may appear in any order.
* @param order the order of this record
*/
@Override
public void setOrder(Integer order) {
this.order = order;
}
Expand Down
Loading