Class MCRMerger

java.lang.Object
org.mycore.mods.merger.MCRMerger
Direct Known Subclasses:
MCRAbstractMerger, MCRCategoryMerger, MCRExtentMerger, MCRIdentifierMerger, MCRNameMerger, MCRRelatedItemMerger, MCRTitleInfoMerger, MCRUniqueMerger, MCRUniqueTypeMerger

public class MCRMerger extends Object
MCRMerger is the main and default implementation for comparing and merging MODS elements that are semantically the same. Each MODS element is wrapped by an instance of MCRMerger or one of its subclasses. It contains methods to decide whether the two MODS elements are equal, or probably represent the information maybe with different granularity. If so, the text, elements and attributes are merged so that the "better" information/representation wins. This is done recursively for all child elements, too.
Author:
Frank Lützenkirchen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Element
    The MODS element wrapped and compared by this merger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Two mergers are equal if they wrap elements that are deep equals.
    protected List<Element>
    Helper method to lookup child elements by XPath.
    boolean
    Returns true, if the element wrapped by this merger probably represents the same information as the other.
    protected void
    Copies those attributes from the other's element into this' element that do not exist in this' element.
    protected void
    Merges all child elements of this with that from other.
    void
    Merges the contents of the element wrapped by the other merger into the contents of the element wrapped by this merger.
    void
    Sets the MODS element wrapped and compared by this merger

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • element

      protected Element element
      The MODS element wrapped and compared by this merger
  • Constructor Details

    • MCRMerger

      public MCRMerger()
  • Method Details

    • setElement

      public void setElement(Element element)
      Sets the MODS element wrapped and compared by this merger
    • isProbablySameAs

      public boolean isProbablySameAs(MCRMerger other)
      Returns true, if the element wrapped by this merger probably represents the same information as the other. The default implementation returns false and may be overwritten by subclasses implementing logic for specific MODS elements.
    • equals

      public boolean equals(Object obj)
      Two mergers are equal if they wrap elements that are deep equals.
      Overrides:
      equals in class Object
    • mergeFrom

      public void mergeFrom(MCRMerger other)
      Merges the contents of the element wrapped by the other merger into the contents of the element wrapped by this merger. Should only be called if this.isProbablySameAs(other). The default implementation copies all attributes from the other into this if they do not exist in this element. Afterwards it recursively builds mergers for all child elements and compares and eventually merges them too.
    • mergeAttributes

      protected void mergeAttributes(MCRMerger other)
      Copies those attributes from the other's element into this' element that do not exist in this' element.
    • mergeElements

      protected void mergeElements(MCRMerger other)
      Merges all child elements of this with that from other. This is done by building MCRMerger instances for each child element and comparing them.
    • getNodes

      protected List<Element> getNodes(String xPath)
      Helper method to lookup child elements by XPath.
      Parameters:
      xPath - XPath expression relative to the element wrapped by this merger.
      Returns:
      a list of elements matching the given XPath