com.univocity.parsers.common
Class EntityList<E extends EntitySettings>

java.lang.Object
  extended by com.univocity.parsers.common.EntityList<E>
Type Parameters:
E - the type of EntitySettings managed by this list.
All Implemented Interfaces:
Iterable<E>
Direct Known Subclasses:
RemoteEntityList

public abstract class EntityList<E extends EntitySettings>
extends Object
implements Iterable<E>

A list of entities to be parsed by some implementation of EntityParserInterface, and their specific configurations. The configuration applied over individual EntitySettings elements override their counterparts in the global parser settings, usually a subclass of EntityParserSettings

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

Field Summary
protected  Map<String,E> entities
           
protected  Map<String,String> originalEntityNames
           
 
Constructor Summary
protected EntityList(EntityParserSettings globalSettings)
          Creates a new, empty EntityList, applying the global configuration object, used by the EntityParserInterface implementation, to all entity-specific settings in this list.
 
Method Summary
protected  E addEntitySettings(E settings)
          Associates an entity setting configuration to a given entity.
 E configureEntity(String entityName)
          Returns the configuration object associated with the given entityName.
protected  E configureEntity(String entityName, E parentEntity)
          Returns the configuration object associated with the given entityName.
 Collection<E> getEntities()
          Returns all the entity configurations stored in this EntityList as a unmodifiable Collection
 E getEntity(String entityName)
          Returns the configuration of a an existing entity or null if there's no entity with the given name.
 Set<String> getEntityNames()
          Returns the entity names stored in the EntityList as a set of Strings.
 EntityParserSettings getParserSettings()
          Returns the global parser settings whose configuration may provide defaults for all entities defined in this list.
 Iterator<E> iterator()
          Iterates over the entity configurations managed by this EntityList.
protected abstract  E newEntity(String entityName, E parentEntity)
          Creates a new configuration object for the given entity name
protected abstract  EntityList newInstance()
          Creates a new instance of EntityList using properties from this instance.
 void removeEntity(E entity)
          Removes an entity from this EntityList.
 void removeEntity(String entityName)
          Removes an entity from this EntityList.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entities

protected Map<String,E extends EntitySettings> entities

originalEntityNames

protected Map<String,String> originalEntityNames
Constructor Detail

EntityList

protected EntityList(EntityParserSettings globalSettings)
Creates a new, empty EntityList, applying the global configuration object, used by the EntityParserInterface implementation, to all entity-specific settings in this list.

Parameters:
globalSettings - the global parser settings whose configuration may provide defaults for all entities defined in this list.
Method Detail

configureEntity

public final E configureEntity(String entityName)
Returns the configuration object associated with the given entityName. If there is no entity with that name, a new configuration will be created and returned. The global settings made for the parser will be used by default. You can configure your entity to use different settings if required.

Parameters:
entityName - name of the entity whose configuration that will be returned.
Returns:
an existing or new entity configuration associated with the given entity name

configureEntity

protected E configureEntity(String entityName,
                            E parentEntity)
Returns the configuration object associated with the given entityName. If there is no entity with that name, a new configuration will be created and returned. The global settings made for the parser will be used by default. You can configure your entity to use different settings if required.

Parameters:
entityName - name of the entity whose configuration that will be returned.
parentEntity - the "parent" entity (which can be null), whose settings will be passed on to the new entity.
Returns:
an existing or new entity configuration associated with the given entity name

newEntity

protected abstract E newEntity(String entityName,
                               E parentEntity)
Creates a new configuration object for the given entity name

Parameters:
entityName - name of the new entity
parentEntity - the "parent" entity (which can be null), whose settings will be passed on to the new entity.
Returns:
new configuration object to be used by the new entity.

getEntityNames

public final Set<String> getEntityNames()
Returns the entity names stored in the EntityList as a set of Strings. Returns an empty set if no entities configured.

Returns:
all entity names in a set.

getEntities

public final Collection<E> getEntities()
Returns all the entity configurations stored in this EntityList as a unmodifiable Collection

Returns:
the collection of all entity settings currently in use.

getEntity

public final E getEntity(String entityName)
Returns the configuration of a an existing entity or null if there's no entity with the given name.

Parameters:
entityName - name of the entity whose configuration will be returned
Returns:
an instance of EntitySettings which manages the configuration of the given entity, or null if no such entity exist.

removeEntity

public final void removeEntity(String entityName)
Removes an entity from this EntityList. A removed entity will not be used by the parser and any fields/configuration made for the removed entity configuration will be lost.

Parameters:
entityName - name of the entity that will be removed.

removeEntity

public final void removeEntity(E entity)
Removes an entity from this EntityList. A removed entity will not be used by the parser and any fields/configuration made for the removed entity configuration will be lost.

Parameters:
entity - the entity object that should be be removed

iterator

public final Iterator<E> iterator()
Iterates over the entity configurations managed by this EntityList.

Specified by:
iterator in interface Iterable<E extends EntitySettings>
Returns:
a new Iterator of EntitySettings objects stored in this EntityList.

addEntitySettings

protected E addEntitySettings(E settings)
Associates an entity setting configuration to a given entity. If the entity does not exist, it will be created. The general settings will be copied into a new configuration object, while any input-specific setting will be lost.

Parameters:
settings - the configuration to be associated with the given entity.
Returns:
the new configuration object

getParserSettings

public EntityParserSettings getParserSettings()
Returns the global parser settings whose configuration may provide defaults for all entities defined in this list.

Returns:
the parent parser settings object.

newInstance

protected abstract EntityList newInstance()
Creates a new instance of EntityList using properties from this instance.

Returns:
the new EntityList


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