Class AbstractSingleEntityMergeStrategy<T>

java.lang.Object
org.onebusaway.gtfs_merge.strategies.AbstractEntityMergeStrategy
org.onebusaway.gtfs_merge.strategies.AbstractSingleEntityMergeStrategy<T>
Type Parameters:
T - the type of the GTFS entity that this merge strategy handles
All Implemented Interfaces:
EntityMergeStrategy
Direct Known Subclasses:
AbstractIdentifiableSingleEntityMergeStrategy, AbstractNonIdentifiableSingleEntityMergeStrategy

public abstract class AbstractSingleEntityMergeStrategy<T> extends AbstractEntityMergeStrategy
Abstract base class that defines common methods and properties for merging single GTFS entities. As opposed to collection-like entities (see AbstractCollectionEntityMergeStrategy, single entities usually stand alone, with one identifier usually corresponding to a single entity. The majority of GTFS entities are single entities.

Of course, not all single entities actually have identifiers. For example, entities like Frequency and Transfer do not have an explicit ids in a GTFS feed. Non-identifiable entities such as these are handled by the AbstractNonIdentifiableSingleEntityMergeStrategy sub-class. Entities with explicit ids, like Stop and Trip, are handled by the AbstractIdentifiableSingleEntityMergeStrategy sub-class.

This class contains methods and properties common to both identifiable and non-identifiable single entities.

Author:
bdferris
  • Field Details

    • _entityType

      protected final Class<?> _entityType
  • Constructor Details

    • AbstractSingleEntityMergeStrategy

      public AbstractSingleEntityMergeStrategy(Class<T> entityType)
  • Method Details

    • getEntityTypes

      public void getEntityTypes(Collection<Class<?>> entityTypes)
      Description copied from interface: EntityMergeStrategy
      Determine the list of entity types handled by this merge strategy.
      Parameters:
      entityTypes - the handled types should be added to this output collection.
    • merge

      public void merge(GtfsMergeContext context)
      Description copied from interface: EntityMergeStrategy
      Perform a merge operation for the entities specified in the GtfsMergeContext. This method will be called repeated by the GtfsMerger, once for each input feed.
      Parameters:
      context - the merge state for the current merge operation
    • mergeEntity

      protected void mergeEntity(GtfsMergeContext context, org.onebusaway.gtfs.model.IdentityBean<?> entity)
      Protected Methods
    • getIdentityDuplicate

      protected abstract org.onebusaway.gtfs.model.IdentityBean<?> getIdentityDuplicate(GtfsMergeContext context, org.onebusaway.gtfs.model.IdentityBean<?> entity)
      Use EDuplicateDetectionStrategy.IDENTITY based duplication-detection to find a duplicate in the output merged feed for the specified entity.
      Parameters:
      context -
      entity -
      Returns:
      a duplicate entity with the specified id or null if none exists.
    • getFuzzyDuplicate

      protected org.onebusaway.gtfs.model.IdentityBean<?> getFuzzyDuplicate(GtfsMergeContext context, org.onebusaway.gtfs.model.IdentityBean<?> entity)
      Use EDuplicateDetectionStrategy.FUZZY based duplication-detection to find a duplicate in the output merged feed for the specified entity.
      Parameters:
      context -
      entity -
      Returns:
      a duplicate entity that fuzzily matches the specified entity or null if none exists.
    • rejectDuplicateOverDifferences

      protected boolean rejectDuplicateOverDifferences(GtfsMergeContext context, T sourceEntity, T targetDuplicate)
      For some entity types, we may detect that two entities are duplicates in the source feed and the target merged feed, but the entities might have slight differences that prevent them from being represented as one merged entity in the output feed. Sub-classes can override this method to provide entity-specific logic for determining if two entities cannot be properly merged.
      Parameters:
      context -
      sourceEntity -
      targetDuplicate -
      Returns:
    • replaceDuplicateEntry

      protected abstract void replaceDuplicateEntry(GtfsMergeContext context, T oldEntity, T newEntity)
      If we've detected a duplicate for an entity in the source feed with some entity in the merged output feed, we want to replace all references to the old entity with the new merged entity. Sub-classes will override this method to provide logic specific to particular entity types, as it relates to updating entity references.
      Parameters:
      context -
      oldEntity - the old entity in the source feed that should be replaced
      newEntity - the new entity in the output merged feed that duplicates the old entity
    • save

      protected void save(GtfsMergeContext context, org.onebusaway.gtfs.model.IdentityBean<?> entity)
      Saves the specified entity to the merged output feed.
      Parameters:
      context -
      entity -
    • getDescription

      protected String getDescription()
      Specified by:
      getDescription in class AbstractEntityMergeStrategy
      Returns:
      a string description of the current entity merge strategy, typically identifying the entity-type to be merged