com.univocity.parsers.common
Class EntityParserSettings<S extends com.univocity.parsers.common.CommonParserSettings,L extends EntityList,C extends com.univocity.parsers.common.Context>

java.lang.Object
  extended by com.univocity.parsers.common.EntityParserSettings<S,L,C>
Type Parameters:
S - an internal configuration object that extends from CommonParserSettings, and is used to manage configuration of elements shared with univocity-parsers
L - the EntityList implementation supported by an EntityParserInterface.
C - the Context implementation which provides information about the entity parser and its execution.
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
RemoteParserSettings

public abstract class EntityParserSettings<S extends com.univocity.parsers.common.CommonParserSettings,L extends EntityList,C extends com.univocity.parsers.common.Context>
extends Object
implements Cloneable

Base configuration class of a parser that produces records for multiple entities. The settings available in an EntityParserSettings configure the parsing process and provide default configuration options that individual implementations of EntitySettings can override. Entities are managed from an EntityList implementation.

Author:
uniVocity Software Pty Ltd - dev@univocity.com

Field Summary
protected  Set<String> entitiesToRead
           
protected  Set<String> entitiesToSkip
           
protected  S globalSettings
           
 
Constructor Summary
EntityParserSettings()
          Creates a new configuration object for an implementation of EntityParserInterface, which will process an input to produce records for entities defined by an EntityList
 
Method Summary
 void addEntitiesToRead(Collection<String> entitiesToRead)
          Adds one or more entities to the existing selection of entities to read.
 void addEntitiesToRead(String... entitiesToRead)
          Adds one or more entities to the existing selection of entities to read.
 void addEntitiesToSkip(Collection<String> entitiesToSkip)
          Adds one or more entities to the existing selection of of entities to skip.
 void addEntitiesToSkip(String... entitiesToSkip)
          Adds one or more entities to the list of entities to skip.
protected  EntityParserSettings<S,L,C> clone()
           
protected static com.univocity.parsers.common.CommonParserSettings createEmptyGlobalSettings()
          Utility method to create new, empty instances of CommonParserSettings.
protected abstract  S createGlobalSettings()
          Forces concrete implementations of this class to produce an instance of CommonParserSettings, which will be used to configure elements shared with univocity-parsers
 Set<String> getEntitiesToRead()
          Returns the unmodifiable set of entities to read.
 Set<String> getEntitiesToSkip()
          Returns an unmodifiable set of names of entities to be skipped.
 int getErrorContentLength()
          Configures the parser to limit the length of displayed contents being processed in the exception message when an error occurs
 String getNullValue()
          Returns the String representation of a null value (defaults to null)
 com.univocity.parsers.common.ProcessorErrorHandler<C> getProcessorErrorHandler()
          Returns the custom error handler to be used to capture and handle errors that might happen while processing records with a Processor (i.e.
 boolean getTrimLeadingWhitespaces()
          Returns whether or not leading whitespaces from values being read should be trimmed (defaults to true)
 boolean getTrimTrailingWhitespaces()
          Returns whether or not trailing whitespaces from values being read should be trimmed (defaults to true)
 void setEntitiesToRead(Collection<String> entitiesToRead)
          Sets one or more entities as the list of entities to read.
 void setEntitiesToRead(String... entitiesToRead)
          Sets one or more entities as the list of entities to read.
 void setEntitiesToSkip(Collection<String> entitiesToSkip)
          Sets one or more entities as the list of entities to skip.
 void setEntitiesToSkip(String... entitiesToSkip)
          Sets one or more entities as the list of entities to skip.
 void setErrorContentLength(int errorContentLength)
          Configures the parser to limit the length of displayed contents being processed in the exception message when an error occurs
 void setNullValue(String nullValue)
          Defines the String representation of a null value (defaults to null)
 void setProcessorErrorHandler(com.univocity.parsers.common.ProcessorErrorHandler<C> processorErrorHandler)
          Defines a custom error handler to be used to capture and handle errors that might happen while processing records with a Processor (i.e.
 void setTrimLeadingWhitespaces(boolean trimTrailingWhitespaces)
          Defines whether or not trailing whitespaces from values being read should be trimmed (defaults to true)
 void setTrimTrailingWhitespaces(boolean trimTrailingWhitespaces)
          Defines whether or not trailing whitespaces from values being read should be trimmed (defaults to true)
 boolean shouldRead(String entityName)
          Tests whether a given entity should be processed (i.e.
 boolean shouldSkip(String entityName)
          Tests whether a given entity should be skipped, so the parser can ignore/not process its records.
 void trimValues(boolean trim)
          Configures the parser 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, toString, wait, wait, wait
 

Field Detail

entitiesToRead

protected Set<String> entitiesToRead

entitiesToSkip

protected Set<String> entitiesToSkip

globalSettings

protected S extends com.univocity.parsers.common.CommonParserSettings globalSettings
Constructor Detail

EntityParserSettings

public EntityParserSettings()
Creates a new configuration object for an implementation of EntityParserInterface, which will process an input to produce records for entities defined by an EntityList

Method Detail

createEmptyGlobalSettings

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

Returns:
a new instance of a CommonParserSettings class.

createGlobalSettings

protected abstract S createGlobalSettings()
Forces concrete implementations of this class to produce an instance of CommonParserSettings, which will be used to configure elements shared with univocity-parsers

Returns:
a new instance of some class that extends CommonParserSettings

addEntitiesToRead

public final void addEntitiesToRead(Collection<String> entitiesToRead)
Adds one or more entities to the existing selection of entities to read. The parser will will only process records for the entities in the set of entities to read. Any any other entity won't have records produced/processed for them.

Parameters:
entitiesToRead - names of the entities to be read.

addEntitiesToRead

public final void addEntitiesToRead(String... entitiesToRead)
Adds one or more entities to the existing selection of entities to read. The parser will will only process records for the entities in the set of entities to read. Any any other entity won't have records produced/processed for them.

Parameters:
entitiesToRead - names of the entities to be read.

addEntitiesToSkip

public final void addEntitiesToSkip(Collection<String> entitiesToSkip)
Adds one or more entities to the existing selection of of entities to skip. The parser will not produce any records or will simply discard records produced for a given entity.

Parameters:
entitiesToSkip - names of the entities to be skipped.

getEntitiesToRead

public final Set<String> getEntitiesToRead()
Returns the unmodifiable set of entities to read. Any previous selection will be discarded. The parser will will only process records for the given entities. Any any other entity won't have records produced/processed for them.

Returns:
set with names of entities to be read.

setEntitiesToRead

public final void setEntitiesToRead(Collection<String> entitiesToRead)
Sets one or more entities as the list of entities to read. Any previous selection will be discarded. The parser will will only process records for the given entities. Any any other entity won't have records produced/processed for them.

Parameters:
entitiesToRead - names of the entities to be read.

setEntitiesToRead

public final void setEntitiesToRead(String... entitiesToRead)
Sets one or more entities as the list of entities to read. Any previous selection will be discarded. The parser will will only process records for the given entities. Any any other entity won't have records produced/processed for them.

Parameters:
entitiesToRead - names of the entities to be read.

getEntitiesToSkip

public final Set<String> getEntitiesToSkip()
Returns an unmodifiable set of names of entities to be skipped. The parser will not produce any records or will simply discard records produced for the given entity.

Returns:
names of the entities to be skipped.

setEntitiesToSkip

public final void setEntitiesToSkip(String... entitiesToSkip)
Sets one or more entities as the list of entities to skip. Any previous selection will be discarded. The parser will not produce any records or will simply discard records produced for a given entity.

Parameters:
entitiesToSkip - names of the entities to be skipped.

addEntitiesToSkip

public final void addEntitiesToSkip(String... entitiesToSkip)
Adds one or more entities to the list of entities to skip. The parser will not produce any records or will simply records produced for a given entity.

Parameters:
entitiesToSkip - names of the entities to be skipped.

setEntitiesToSkip

public final void setEntitiesToSkip(Collection<String> entitiesToSkip)
Sets one or more entities as the list of entities to skip. Any previous selection will be discarded. The parser will not produce any records or will simply discard records produced for a given entity.

Parameters:
entitiesToSkip - names of the entities to be skipped.

shouldSkip

public final boolean shouldSkip(String entityName)
Tests whether a given entity should be skipped, so the parser can ignore/not process its records. Entities to be skipped are those that are either added to the internal set of entitiesToSkip or not in the set of entitiesToRead, if it is not empty

Parameters:
entityName - name of the entity
Returns:
true if the entity should be skipped, otherwise false

shouldRead

public final boolean shouldRead(String entityName)
Tests whether a given entity should be processed (i.e. whether or not the parser should generate records for it) Entities to be read are those that were not added to the internal set of entitiesToSkip or are in the set of entitiesToRead, if it is not empty

Parameters:
entityName - name of entity
Returns:
true if the entity should be read, otherwise false

getProcessorErrorHandler

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

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

Returns:
the callback error handler with custom code to manage occurrences of DataProcessingException.

setProcessorErrorHandler

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

The parsing process 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.

getTrimTrailingWhitespaces

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

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

setTrimTrailingWhitespaces

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

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

getTrimLeadingWhitespaces

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

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

setTrimLeadingWhitespaces

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

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

trimValues

public final void trimValues(boolean trim)
Configures the parser 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.

getErrorContentLength

public final int getErrorContentLength()
Configures the parser to limit the length of displayed contents being processed 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 content.

defaults to -1 (no limit)

.

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

setErrorContentLength

public final void setErrorContentLength(int errorContentLength)
Configures the parser to limit the length of displayed contents being processed 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 content.

defaults to -1 (no limit)

.

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

getNullValue

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

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

Returns:
the String representation of a null value

setNullValue

public final void setNullValue(String nullValue)
Defines the String representation of a null value (defaults to null)

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

Parameters:
nullValue - the String representation of a null value

clone

protected EntityParserSettings<S,L,C> clone()
Overrides:
clone in class Object


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