Package de.isas.lipidomics.domain
Class ElementTable
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.EnumMap<Element,Integer>
-
- de.isas.lipidomics.domain.ElementTable
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Element,Integer>
public final class ElementTable extends EnumMap<Element,Integer>
Accounting table for chemical element frequency. This is used to calculate sum formulas and total masses for a given chemical element distribution, e.g. in a lipid.- Author:
- nils.hoffmann
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description ElementTable()
Creates an empty element table.ElementTable(String sumFormula)
Creates the element table from the provided sum formula.ElementTable(Map<Element,? extends Integer> m)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ElementTable
add(ElementTable other)
Adds the element counts of the provided table to this one.ElementTable
copy()
Returns an copy of all mappings in this table.void
decrement(Element element)
Decrements the current count for element by one.void
decrementBy(Element element, Integer decrement)
Decrement the count of the provided element by the given number.Double
getMass()
Returns the total summed mass per number of elements.Double
getMass(Element element)
Returns the individual total mass for the provided element.String
getSumFormula()
Returns the sum formula for all elements in this table.void
increment(Element element)
Increment the count of the provided element by one.void
incrementBy(Element element, Integer increment)
Increment the count of the provided element by the given number.void
negate(Element element)
Negates the count stored in the table.ElementTable
subtract(ElementTable elementTable)
Subtracts all element counts in the provided element table from this table.-
Methods inherited from class java.util.EnumMap
clear, clone, containsKey, containsValue, entrySet, equals, get, hashCode, keySet, put, putAll, remove, size, values
-
Methods inherited from class java.util.AbstractMap
isEmpty, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
ElementTable
public ElementTable(Map<Element,? extends Integer> m)
-
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.
-
-