Class ElementTable

    • Constructor Detail

      • ElementTable

        public ElementTable()
        Creates an empty element table.
      • ElementTable

        public ElementTable​(String sumFormula)
                     throws ParsingException
        Creates the element table from the provided sum formula. If an empty string is passed in this will create an empty table.
        Parameters:
        sumFormula - the sum formula to parse.
        Throws:
        ParsingException - if the sum formula does not conform with the SumFormula grammar.
    • Method Detail

      • add

        public ElementTable add​(ElementTable other)
        Adds the element counts of the provided table to this one.
        Parameters:
        other - the table to add to this one.
        Returns:
        a new element table.
      • increment

        public void increment​(Element element)
        Increment the count of the provided element by one.
        Parameters:
        element - the element.
      • incrementBy

        public void incrementBy​(Element element,
                                Integer increment)
        Increment the count of the provided element by the given number.
        Parameters:
        element - the element.
        increment - the increment for the element.
      • decrement

        public void decrement​(Element element)
        Decrements the current count for element by one.
        Parameters:
        element - the element to decrement the counts for.
      • decrementBy

        public void decrementBy​(Element element,
                                Integer decrement)
        Decrement the count of the provided element by the given number.
        Parameters:
        element - the element.
        decrement - the decrement for the element.
      • negate

        public void negate​(Element element)
        Negates the count stored in the table. E.g. '5' will become '-5', '-5' would become '5'.
        Parameters:
        element - the element count to negate.
      • subtract

        public ElementTable subtract​(ElementTable elementTable)
        Subtracts all element counts in the provided element table from this table.
        Parameters:
        elementTable - the element table to subtract from this.
        Returns:
        this element table.
      • getSumFormula

        public String getSumFormula()
        Returns the sum formula for all elements in this table.
        Returns:
        the sum formula. Returns an empty string if the table is empty.
      • getMass

        public Double getMass​(Element element)
        Returns the individual total mass for the provided element.
        Parameters:
        element - the element to calculate the total mass for.
        Returns:
        the total mass for the given element, or 0.
      • getMass

        public Double getMass()
        Returns the total summed mass per number of elements.
        Returns:
        the total summed mass for this element table. Returns 0 if the table is empty.
      • copy

        public ElementTable copy()
        Returns an copy of all mappings in this table.
        Returns:
        the element table copy.