com.univocity.parsers.common
Class EntitySettings<C extends com.univocity.parsers.common.Context,S extends com.univocity.parsers.common.CommonSettings,G extends EntityParserSettings>

java.lang.Object
  extended by com.univocity.parsers.common.EntitySettings<C,S,G>
Type Parameters:
C - the type of Context implementation supported by Processors of this entity.
S - internal implementation of a CommonSettings, used to manage configuration of elements shared with univocity-parsers
G - type of the global configuration class (an instance of EntityParserSettings, used to configure the parser (a concrete implementation of EntityParserInterface) and its entities.
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
RemoteEntitySettings

public abstract class EntitySettings<C extends com.univocity.parsers.common.Context,S extends com.univocity.parsers.common.CommonSettings,G extends EntityParserSettings>
extends Object
implements Cloneable

Manages configuration options for individual entities of an EntityList. Settings that also exist in the parent EntityParserSettings will be used by default but can be overridden for an individual entity.

Author:
uniVocity Software Pty Ltd - dev@univocity.com
See Also:
EntityList, EntityParserInterface, EntityParserSettings

Field Summary
protected  String name
           
protected  EntitySettings parentEntity
           
protected  G parserSettings
           
protected  com.univocity.parsers.common.processor.core.Processor<C> processor
           
 
Constructor Summary
protected EntitySettings(String name, S internalSettings, EntitySettings parentEntity)
          Internal constructor to be invoked the subclasses of EntitySettings
 
Method Summary
protected  EntitySettings<C,S,G> clone()
           
protected static com.univocity.parsers.common.CommonParserSettings createEmptyParserSettings()
          Utility method to create new, empty instances of CommonParserSettings.
 com.univocity.parsers.common.fields.FieldSet<Enum> excludeFields(Enum... columns)
          Selects columns which will not be read/written, by their names
 com.univocity.parsers.common.fields.FieldSet<String> excludeFields(String... fieldNames)
          Selects fields which will not be read/written, by their names
 com.univocity.parsers.common.fields.FieldSet<Integer> excludeIndexes(Integer... fieldIndexes)
          Selects columns which will not be read/written, by their positions
 String getEntityName()
          Returns the name of the HTMLEntity
 int getErrorContentLength()
          Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs
protected  S getInternalSettings()
          Returns the internal CommonSettings used
 String getNullValue()
          Returns the String representation of a null value.
protected  EntityList getParentEntityList()
          Returns the entity list that "owns" this entity.
 com.univocity.parsers.common.processor.core.Processor<C> getProcessor()
          Returns the current implementation of Processor to be used to process rows generated for this entity.
<T extends com.univocity.parsers.common.Context>
com.univocity.parsers.common.ProcessorErrorHandler<T>
getProcessorErrorHandler()
          Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a Processor or a RowWriterProcessor (i.e.
 boolean getTrimLeadingWhitespaces()
          Returns whether or not leading whitespaces from values being read/written should be trimmed (defaults to true)
 boolean getTrimTrailingWhitespaces()
          Returns whether or not trailing whitespaces from values being read/written should be trimmed (defaults to true)
 boolean isAutoConfigurationEnabled()
          Indicates whether this settings object can automatically derive configuration options.
 boolean isProcessorErrorHandlerDefined()
          Returns a flag indicating whether or not a ProcessorErrorHandler has been defined through the use of method setProcessorErrorHandler(ProcessorErrorHandler)
protected  void runAutomaticConfiguration()
          Run automatic configuration for the internal settings.
 com.univocity.parsers.common.fields.FieldSet<Enum> selectFields(Enum... columns)
          Selects a sequence of fields for reading/writing by their names
 com.univocity.parsers.common.fields.FieldSet<String> selectFields(String... fieldNames)
          Selects a sequence of fields for reading/writing by their names.
 com.univocity.parsers.common.fields.FieldSet<Integer> selectIndexes(Integer... fieldIndexes)
          Selects a sequence of fields for reading/writing by their positions.
 void setAutoConfigurationEnabled(boolean autoConfigurationEnabled)
          Indicates whether this settings object can automatically derive configuration options.
 void setErrorContentLength(int errorContentLength)
          Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs.
 void setNullValue(String nullValue)
          Sets the String representation of a null value.
protected  void setParent(EntityList parentEntityList)
          Used to "inherit" default settings of a parent EntityParserSettings.
 void setProcessor(com.univocity.parsers.common.processor.core.Processor<C> processor)
          Defines an implementation of Processor to be used to process rows generated for this entity.
 void setProcessorErrorHandler(com.univocity.parsers.common.ProcessorErrorHandler<? extends com.univocity.parsers.common.Context> processorErrorHandler)
          Defines a custom error handler to capture and handle errors that might happen while processing records with a Processor or a RowWriterProcessor (i.e.
 void setTrimLeadingWhitespaces(boolean trimLeadingWhitespaces)
          Defines whether or not leading whitespaces from values being read/written should be trimmed (defaults to true)
 void setTrimTrailingWhitespaces(boolean trimTrailingWhitespaces)
          Defines whether or not trailing whitespaces from values being read/written should be trimmed (defaults to true)
 String toString()
           
 void trimValues(boolean trim)
          Configures the parser/writer to trim/keep leading and trailing whitespaces around values This has the same effect as invoking both setTrimLeadingWhitespaces(boolean) and setTrimTrailingWhitespaces(boolean) with the same value.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parserSettings

protected G extends EntityParserSettings parserSettings

name

protected final String name

processor

protected com.univocity.parsers.common.processor.core.Processor<C extends com.univocity.parsers.common.Context> processor

parentEntity

protected final EntitySettings parentEntity
Constructor Detail

EntitySettings

protected EntitySettings(String name,
                         S internalSettings,
                         EntitySettings parentEntity)
Internal constructor to be invoked the subclasses of EntitySettings

Parameters:
name - the entity name, usually provided by the user
internalSettings - an internal implementation of a CommonSettings, used to manage configuration of elements shared with univocity-parsers. Not meant to be exposed/accessed directly by users.
parentEntity - parent entity to build settings on top of
Method Detail

setParent

protected final void setParent(EntityList parentEntityList)
Used to "inherit" default settings of a parent EntityParserSettings. Used internally in in the constructor of EntityParserSettings (which is the global setting object itself).

Parameters:
parentEntityList - the parent EntityList who "owns" all entities and their EntitySettings

createEmptyParserSettings

protected static final com.univocity.parsers.common.CommonParserSettings createEmptyParserSettings()
Utility method to create new, empty instances of CommonParserSettings. For internal use only.

Returns:
a new instance of a CommonParserSettings class.

getNullValue

public final String getNullValue()
Returns the String representation of a null value.

When reading, if the parser does not read any character from the input for a particular value, the nullValue is used instead of an empty String

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty String

Returns:
the String representation of a null value

setNullValue

public final void setNullValue(String nullValue)
Sets the String representation of a null value.

When reading, if the parser does not read any character from the input for a particular value, the nullValue is used instead of an empty String

When writing, if the writer has a null object to write to the output, the nullValue is used instead of an empty String

Parameters:
nullValue - the String representation of a null value

selectFields

public final com.univocity.parsers.common.fields.FieldSet<String> selectFields(String... fieldNames)
Selects a sequence of fields for reading/writing by their names.

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
fieldNames - The field names to read/write
Returns:
the (modifiable) set of selected fields

excludeFields

public final com.univocity.parsers.common.fields.FieldSet<String> excludeFields(String... fieldNames)
Selects fields which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
fieldNames - The field names to exclude from the parsing/writing process
Returns:
the (modifiable) set of ignored fields

selectIndexes

public final com.univocity.parsers.common.fields.FieldSet<Integer> selectIndexes(Integer... fieldIndexes)
Selects a sequence of fields for reading/writing by their positions.

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting indexes "2" and "0" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
fieldIndexes - The indexes to read/write
Returns:
the (modifiable) set of selected fields

excludeIndexes

public final com.univocity.parsers.common.fields.FieldSet<Integer> excludeIndexes(Integer... fieldIndexes)
Selects columns which will not be read/written, by their positions

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields by index, such as "2" and "0" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
fieldIndexes - indexes of columns to exclude from the parsing/writing process
Returns:
the (modifiable) set of ignored fields

selectFields

public final com.univocity.parsers.common.fields.FieldSet<Enum> selectFields(Enum... columns)
Selects a sequence of fields for reading/writing by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence provided represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
columns - The columns to read/write
Returns:
the (modifiable) set of selected fields

excludeFields

public final com.univocity.parsers.common.fields.FieldSet<Enum> excludeFields(Enum... columns)
Selects columns which will not be read/written, by their names

When reading, only the values of the selected columns will be parsed, and the content of the other columns ignored. The resulting rows will be returned with the selected columns only, in the order specified. If you want to obtain the original row format, with all columns included and nulls in the fields that have not been selected, set setColumnReorderingEnabled(boolean) with false if available.

When writing, the sequence of non-excluded fields represents the expected format of the input rows. For example, headers can be "H1,H2,H3", but the input data is coming with values for two columns and in a different order, such as "V_H3, V_H1". Selecting fields "H3" and "H1" will allow the writer to write values in the expected locations. Using the given example, the output row will be generated as: "V_H1,null,V_H3"

Parameters:
columns - The columns to exclude from the parsing/writing process
Returns:
the (modifiable) set of ignored fields

isAutoConfigurationEnabled

public final boolean isAutoConfigurationEnabled()
Indicates whether this settings object can automatically derive configuration options. This is used, for example, to define the headers when the user provides a BeanWriterProcessor where the bean class contains a Headers annotation, or to enable header extraction when the bean class of a BeanProcessor has attributes mapping to header names.

Defaults to true

Returns:
true if the automatic configuration feature is enabled, false otherwise

setAutoConfigurationEnabled

public final void setAutoConfigurationEnabled(boolean autoConfigurationEnabled)
Indicates whether this settings object can automatically derive configuration options. This is used, for example, to define the headers when the user provides a BeanWriterProcessor where the bean class contains a Headers annotation, or to enable header extraction when the bean class of a BeanProcessor has attributes mapping to header names.

Parameters:
autoConfigurationEnabled - a flag to turn the automatic configuration feature on/off.

getProcessorErrorHandler

public final <T extends com.univocity.parsers.common.Context> com.univocity.parsers.common.ProcessorErrorHandler<T> getProcessorErrorHandler()
Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing/writing process won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Type Parameters:
T - the Context type provided by the parser implementation.
Returns:
the callback error handler with custom code to manage occurrences of DataProcessingException.

setProcessorErrorHandler

public final void setProcessorErrorHandler(com.univocity.parsers.common.ProcessorErrorHandler<? extends com.univocity.parsers.common.Context> processorErrorHandler)
Defines a custom error handler to capture and handle errors that might happen while processing records with a Processor or a RowWriterProcessor (i.e. non-fatal DataProcessingExceptions).

The parsing parsing/writing won't stop (unless the error handler rethrows the DataProcessingException or manually stops the process).

Parameters:
processorErrorHandler - the callback error handler with custom code to manage occurrences of DataProcessingException.

isProcessorErrorHandlerDefined

public final boolean isProcessorErrorHandlerDefined()
Returns a flag indicating whether or not a ProcessorErrorHandler has been defined through the use of method setProcessorErrorHandler(ProcessorErrorHandler)

Returns:
true if the parser/writer is configured to use a ProcessorErrorHandler

getErrorContentLength

public final int getErrorContentLength()
Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs

If set to 0, then no exceptions will include the content being manipulated in their attributes, and the "<omitted>" string will appear in error messages as the parsed/written content.

defaults to -1 (no limit)

.

Returns:
the maximum length of contents displayed in exception messages in case of errors while parsing/writing.

setErrorContentLength

public final void setErrorContentLength(int errorContentLength)
Configures the parser/writer to limit the length of displayed contents being parsed/written in the exception message when an error occurs.

If set to 0, then no exceptions will include the content being manipulated in their attributes, and the "<omitted>" string will appear in error messages as the parsed/written content.

defaults to -1 (no limit)

.

Parameters:
errorContentLength - maximum length of contents displayed in exception messages in case of errors while parsing/writing.

runAutomaticConfiguration

protected final void runAutomaticConfiguration()
Run automatic configuration for the internal settings.


getInternalSettings

protected S getInternalSettings()
Returns the internal CommonSettings used

Returns:
the internal settings

getEntityName

public final String getEntityName()
Returns the name of the HTMLEntity

Returns:
the name as a String

toString

public final String toString()
Overrides:
toString in class Object

getProcessor

public final com.univocity.parsers.common.processor.core.Processor<C> getProcessor()
Returns the current implementation of Processor to be used to process rows generated for this entity. If no processor has been defined, a NoopProcessor will be returned.

Returns:
the current Processor
See Also:
com.univocity.parsers.common.processor

setProcessor

public final void setProcessor(com.univocity.parsers.common.processor.core.Processor<C> processor)
Defines an implementation of Processor to be used to process rows generated for this entity.

Parameters:
processor - the Processor implementation.
See Also:
com.univocity.parsers.common.processor

getTrimTrailingWhitespaces

public final boolean getTrimTrailingWhitespaces()
Returns whether or not trailing whitespaces from values being read/written should be trimmed (defaults to true)

Returns:
true if trailing whitespaces from values being read/written should be trimmed, false otherwise

setTrimTrailingWhitespaces

public final void setTrimTrailingWhitespaces(boolean trimTrailingWhitespaces)
Defines whether or not trailing whitespaces from values being read/written should be trimmed (defaults to true)

Parameters:
trimTrailingWhitespaces - flag indicating whether to remove trailing whitespaces from values being read/written

getTrimLeadingWhitespaces

public final boolean getTrimLeadingWhitespaces()
Returns whether or not leading whitespaces from values being read/written should be trimmed (defaults to true)

Returns:
true if leading whitespaces from values being read/written should be trimmed, false otherwise

setTrimLeadingWhitespaces

public final void setTrimLeadingWhitespaces(boolean trimLeadingWhitespaces)
Defines whether or not leading whitespaces from values being read/written should be trimmed (defaults to true)

Parameters:
trimLeadingWhitespaces - flag indicating whether to remove leading whitespaces from values being read/written

trimValues

public final void trimValues(boolean trim)
Configures the parser/writer to trim/keep leading and trailing whitespaces around values This has the same effect as invoking both setTrimLeadingWhitespaces(boolean) and setTrimTrailingWhitespaces(boolean) with the same value.

Parameters:
trim - a flag indicating whether whitespaces should be removed around values parsed/written.

getParentEntityList

protected EntityList getParentEntityList()
Returns the entity list that "owns" this entity.

Returns:
the parent entity list.

clone

protected EntitySettings<C,S,G> clone()
Overrides:
clone in class Object


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.