Skip to content

Commit

Permalink
Added the option to specify element order as a parameter of getHTML()
Browse files Browse the repository at this point in the history
Change-Id: Id4e37bb3ce2f30971ee3a533ad802ba4fb43e9e0
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
tomas-pluskal authored and egonw committed Jul 1, 2012
1 parent 76d32b9 commit 6df66fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -336,12 +336,33 @@ public static String getHTML(IMolecularFormula formula) {
*/
@TestMethod("testGetHTML_IMolecularFormula_boolean_boolean")
public static String getHTML(IMolecularFormula formula, boolean chargeB, boolean isotopeB) {
String htmlString = "";
String[] orderElements;
if (containsElement(formula, formula.getBuilder().newInstance(IElement.class,"C")))
orderElements = generateOrderEle_Hill_WithCarbons();
else
orderElements = generateOrderEle_Hill_NoCarbons();
return getHTML(formula, orderElements, chargeB, isotopeB);
}

/**
* Returns the string representation of the molecule formula with numbers
* wrapped in &lt;sub&gt;&lt;/sub&gt; tags and the isotope of each Element
* in &lt;sup&gt;&lt;/sup&gt; tags and the total charge of IMolecularFormula
* in &lt;sup&gt;&lt;/sup&gt; tags. Useful for displaying formulae in Swing
* components or on the web.
*
*
* @param formula The IMolecularFormula object
* @param orderElements The order of Elements
* @param chargeB True, If it has to show the charge
* @param isotopeB True, If it has to show the Isotope mass
* @return A HTML representation of the molecular formula
* @see #getHTML(IMolecularFormula)
*
*/
@TestMethod("testGetHTML_IMolecularFormula_arrayString_boolean_boolean")
public static String getHTML(IMolecularFormula formula, String[] orderElements, boolean chargeB, boolean isotopeB) {
String htmlString = "";
for (String orderElement : orderElements) {
IElement element = formula.getBuilder().newInstance(IElement.class,orderElement);
if (containsElement(formula, element)) {
Expand Down
Expand Up @@ -549,6 +549,18 @@ public void testGetHTML_IMolecularFormula_boolean_boolean() {
Assert.assertEquals("C<sub>10</sub><sup>1-</sup>", MolecularFormulaManipulator.getHTML(formula,true,false));
}
@Test
public void testGetHTML_IMolecularFormula_arrayString_boolean_boolean() {
IMolecularFormula formula = new MolecularFormula();
formula.addIsotope(builder.newInstance(IIsotope.class,"C"), 2);
formula.addIsotope(builder.newInstance(IIsotope.class,"H"), 2);

String[] newOrder = new String[2];
newOrder[0] = "H";
newOrder[1] = "C";

Assert.assertEquals("H<sub>2</sub>C<sub>2</sub>", MolecularFormulaManipulator.getHTML(formula, newOrder, false, false));
}
@Test
public void testGetHTML_IMolecularFormulaWhitIsotope() {
MolecularFormula formula = new MolecularFormula();
formula.addIsotope(ifac.getMajorIsotope("C"),2);
Expand Down

0 comments on commit 6df66fb

Please sign in to comment.