com.ibm.commerce.marketing.promotion.runtime

Class AssociatedOrderItem

  • java.lang.Object
    • com.ibm.commerce.marketing.promotion.runtime.AssociatedOrderItem
  • All Implemented Interfaces:
    XMLizable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable


    public class AssociatedOrderItem
    extends java.lang.Object
    implements XMLizable, java.lang.Comparable, java.lang.Cloneable
    This class represents a line item used during promotion evaluation. It encapsulates information such as an order item and its quantity. Since a promotion might take into consideration only a subset of an order item's quantity, an AssociatedOrderItem has an additional parameter called StartIndex which indicates the starting position in the quantity of this order item. Using the StartIndex and the Quantity of an order item, one can define a subset of the quantity of the order item.

    XML Snippet for AssociatedOrderItem:

        <AssociatedOrderItem impl="com.ibm.commerce.marketing.promotion.runtime.AssociatedOrderItem" >
        <OrderItemKey>
            <OrderItemId>1234</OrderItemId>
        </OrderItemKey>
        <StartIndex>2</StartIndex>
        <Quantity>4</Quantity>
        </AssociatedOrderItem>
     
    See Also:
    Serialized Form
    • Constructor Detail

      • AssociatedOrderItem

        public AssociatedOrderItem()
        Default constructor for creating an AssociatedOrderItem.
    • Method Detail

      • canMerge

        public boolean canMerge(AssociatedOrderItem item)
        Checks if this AssociatedOrderItem can be merged with the operand AssociatedOrderItem. Two AssociatedOrderItems can be merged if and only if they refer to the same order item. And the quantity subsets of the two AssociatedOrderItems is either joining or overlapping.
        Parameters:
        item - the other AssociatedOrderItem to be merged with the current one.
        Returns:
        true when the two AssociatedOrderItem can be merged, false otherwise.
      • merge

        public AssociatedOrderItem merge(AssociatedOrderItem item)
        Merges two AssociatedOrderItems into one AssociatedOrderItem. Merging may be used to produce a single AssociatedOrderItem if possible, for example when adding AssociatedOrderItems to a LineItemSet(see method addLineItem(AssociatedOrderItem).
        Parameters:
        item - the other AssociatedOrderItem to be merged with the current one.
        Returns:
        AssociatedOrderItem The merged AssociatedOrderItem, this is a new object, the two original objects are not modified. Returns null when the two items can not be merged.
      • hasCrossSection

        public boolean hasCrossSection(AssociatedOrderItem item)
        Checks to see if the current AssociatedOrderItem has cross-section with another AssociatedOrderItem or not. For two AssociatedOrderItems to have a cross-section, the order item keys must be the same and quantity subsets of the two AssociatedOrderItems must either join or overlap.
        Parameters:
        item - AssociatedOrderItem the other item
        Returns:
        true when there is a cross section; otherwise, it returns false.
      • markCommonSection

        public int[] markCommonSection(AssociatedOrderItem item,
                                       AssociatedOrderItem[] sections)
        Seeks out the common sections between this AssociatedOrderItem and the operand AssociatedOrderItem. If these two items have no cross section, a null is returned. If these two have cross section, an array of integers will be returned. Values in the array are the three integers indicating SECTION_FROM_THIS_ITEM, SECTION_IS_COMMON, SECTION_FROM_OTHER_ITEM respectively. At the same time, the input parameter "sections" is modified and set with the three sections (three AssociatedOrderItems determined by the above definition of sections). It is possible that the first or the last AssociatedOrderItem's quantity is zero, which means either this order item or the operand order item starts (or ends) in the same position.
        Parameters:
        item - the operand AssociatedOrderItem to be used for creating sections.
        sections - an array of three AssociatedOrderItem. CAUTION: it is the output parameter and the result of three sections will be set in the array.
        Returns:
        an int array indicating where each section in the sections array starts from. If this order item and the operand order item (first input parameter) have no cross section, then a null will be returned.
      • split

        public AssociatedOrderItem[] split(java.math.BigDecimal _quantity)
        Splits the current AssociatedOrderItem into one or two AssociatedOrderItems based on quantity. When the parameter quantity is bigger than the quantity attribute of this AssociatedOrderItem, a PromotionRuntimeException is thrown. If the parameter quantity equals to the quantity attribute of this AssociatedOrderItem, a new AssociatedOrderItem that equals to this AssociatedOrderItem is returned. If the parameter quantity is smaller than the quantity attribute of this AssociatedOrderItem, two AssociatedOrderItems are returned. And the first one has a quantity attribute equal to the parameter quantity. The second one has a quantity attribute, which is the difference of the parameter quantity and the quantity of the first AssociatedOrderItem.
        Parameters:
        _quantity - BigDecimal the quantity to split
        Returns:
        AssociatedOrderItem[] one or two AssociatedOrderItem depends on the parameter quantity
      • split

        public AssociatedOrderItem[] split(java.math.BigDecimal[] quantities)
        Splits the current AssociatedOrderItem into a number of smaller AssociatedOrderItems. Each of the AssociatedOrderItems has the same quantities as specified by the quantities[] parameter with the only exception of the last one. The last one could have any quantity. It is based on the difference between the quantity attribute in this AssociatedOrderItem and the total of all values in the quantities[] parameter.
        Parameters:
        quantities - BigDecimal[] the quantities used to split the current AssociatedOrderItem
        Returns:
        AssociatedOrderItem[] the split results
      • splitEndToStart

        public AssociatedOrderItem[] splitEndToStart(java.math.BigDecimal _quantity)
        Splits the current AssociatedOrderItem into one or two AssociatedOrderItems based on quantity, starting from the end of the current AssociatedOrderItems instead of the start. When the parameter quantity is bigger than the quantity attribute of this AssociatedOrderItem, a PromotionRuntimeException is thrown. If the parameter quantity equals to the quantity attribute of this AssociatedOrderItem, a new AssociatedOrderItem that equals to this AssociatedOrderItem is returned. If the parameter quantity is smaller than the quantity attribute of this AssociatedOrderItem, two AssociatedOrderItems are returned. And the first one has a quantity attribute equal to the parameter quantity. The second one has a quantity attribute, which is the difference of the parameter quantity and the quantity of the first AssociatedOrderItem.
        Parameters:
        _quantity - BigDecimal the quantity to split
        Returns:
        AssociatedOrderItem[] one or two AssociatedOrderItem depends on the parameter quantity
      • splitEndToStart

        public AssociatedOrderItem[] splitEndToStart(java.math.BigDecimal[] quantities)
        Splits the current AssociatedOrderItem into a number of smaller AssociatedOrderItems, starting from the end of the current AssociatedOrderItem intead of the start. Each of the AssociatedOrderItems has the same quantities as specified by the quantities[] parameter with the only exception of the last one. The last one could have any quantity. It is based on the difference between the quantity attribute in this AssociatedOrderItem and the total of all values in the quantities[] parameter.
        Parameters:
        quantities - BigDecimal[] the quantities used to split the current AssociatedOrderItem
        Returns:
        AssociatedOrderItem[] the split results
      • difference

        public AssociatedOrderItem[] difference(AssociatedOrderItem item)
        Calculates the difference between this associated order item and the parameter item.
        Parameters:
        item - parameter associated order item
        Returns:
        the difference between this associated order item and the parameter item, result could be an array of 1 or 2 elements. Only when this item completely contains the parameter item and no boundaries overlap, two elements will be returned.
      • fromXML

        public void fromXML(org.w3c.dom.Node node)
                     throws DeXMLizationException
        Builds an AssociatedOrderItem objects based on an XML fragment
        Specified by:
        fromXML in interface XMLizable
        Parameters:
        node - Node the XML fragment
        Throws:
        DeXMLizationException - when parsing of the XML fragment fails.
      • equals

        public boolean equals(java.lang.Object obj)
        Checks to see if two AssociatedOrderItem objects are equal or not.
        Overrides:
        equals in class java.lang.Object
        See Also:
        java.lang.Object.equals(Object obj)
      • hashCode

        public int hashCode()
        Generates a hash code for the AssociatedOrderItem.
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        java.lang.Object.hashCode()
      • getOrderItem

        public OrderItem getOrderItem()
        Returns the order item
        Returns:
        order item with which this associated order item is associated with
      • getQuantity

        public java.math.BigDecimal getQuantity()
        Returns the quantity. Each order item has a quantity associated with it.
        Returns:
        BigDecimal the quantity.
      • getStartsAt

        public java.math.BigDecimal getStartsAt()
        Returns the StartIndex node value of the order item. Each order item has a quantity associated with it. A line item may only refer to a sub set of that quantity. This sub set is indicated by the start index and the quantity attributes of the AssociatedOrderItem.
        Returns:
        BigDecimal the starts at quantity of the AssociatedOrderItem.
      • compareTo

        public int compareTo(java.lang.Object obj)
        Compares two AssociatedOrderItem objects.
        Specified by:
        compareTo in interface java.lang.Comparable
        See Also:
        Comparable.compareTo(Object)
      • getOrderItemKey

        public OrderItemKey getOrderItemKey()
        Returns the key of the order item with which this AssociatedOrderItem is associated with
        Returns:
        order item key
      • refersToSameOrderItem

        public boolean refersToSameOrderItem(AssociatedOrderItem item)
        Tests if two AssociatedOrderItems are referring to the same order item.
        Parameters:
        item - the other associated order item
        Returns:
        true if both are referring to the same order item, false otherwise
      • clone

        public java.lang.Object clone()
        Returns null if the CloneNotSupportedException is thrown.
        Overrides:
        clone in class java.lang.Object
        See Also:
        java.lang.Object.clone()
      • toString

        public java.lang.String toString()
        Returns a string representation of the AssociatedOrderItem.
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()