Skip to content

Commit

Permalink
Refactored periodic table element to be a standalone class, so indepe…
Browse files Browse the repository at this point in the history
…ndent of the data module. This is OK, since the class is really just a struct to hold PT data for a given element. As opposed to being a basis of an elemental representation. Also, this class is entirely private to this package, so it doesn't really matter what it is. Updated associated unit tests
  • Loading branch information
rajarshi authored and egonw committed Nov 28, 2009
1 parent a0439ab commit 27fc004
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 41 deletions.
Expand Up @@ -26,7 +26,6 @@
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IElement;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;

Expand Down Expand Up @@ -172,21 +171,7 @@ public PeriodicTableElement configure(PeriodicTableElement element) throws CDKEx
element.setCASid(elementInt.getCASid());
element.setPaulingEneg(elementInt.getPaulingEneg());
return element;
}
/**
* Configures a IElement given a PeridicTableElement.
*
*@param elementPT The element of the Periodic Table to be configure
*@return element The configured element
*/
@TestMethod("testConfigureE_PeriodicTableElement")
public IElement configureE(PeriodicTableElement elementPT)
{
IElement element = elementPT.getBuilder().newElement(elementPT.getSymbol());
element.setSymbol(elementPT.getSymbol());
element.setAtomicNumber(elementPT.getAtomicNumber());
return element;
}
}

/**
* Gets the atomic number of this element in the periodic table.
Expand Down
Expand Up @@ -25,7 +25,6 @@
package org.openscience.cdk.tools.periodictable;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Element;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand Down Expand Up @@ -56,7 +55,7 @@
* @cdk.githash
*/
@TestClass("org.openscience.cdk.tools.periodictable.PeriodicTableElementTest")
class PeriodicTableElement extends Element
class PeriodicTableElement implements Cloneable
{

/**
Expand All @@ -72,7 +71,9 @@ class PeriodicTableElement extends Element
private static ILoggingTool logger =
LoggingToolFactory.createLoggingTool(PeriodicTableElement.class);

/** The name for this element. */
/**
* The name for this element.
*/
protected String name;

/** The chemical series for this element.
Expand Down Expand Up @@ -125,6 +126,16 @@ class PeriodicTableElement extends Element
*/
protected Double paulingEneg = (Double) CDKConstants.UNSET;

/**
* The atomic number of the element.
*/
private Integer atomicNumber = (Integer) CDKConstants.UNSET;

/**
* Symbol for the element.
*/
private String symbol;

/**
* Constructor for the PeriodicTableElement object.
*
Expand All @@ -135,7 +146,39 @@ public PeriodicTableElement(String symbol)
{
this.symbol = symbol;
}
/**

/**
* Constructor for the PeriodicTableElement object.
*
* @param symbol The symbol of the element
*/
@TestMethod("testConstructor")
public PeriodicTableElement(String symbol, Integer atomicNumber) {
this.symbol = symbol;
this.atomicNumber = atomicNumber;
}

/**
* Get this elements symbol.
*
* @return the symbol
*/
@TestMethod("testGetSymbol")
public String getSymbol() {
return symbol;
}

/**
* Set the symbol of the element.
*
* @param symbol the symbol
*/
@TestMethod("testSetSymbol")
public void setSymbol(String symbol) {
this.symbol = symbol;
}

/**
* Returns the name of this element.
*
* @return The name of this element. Null if unset.
Expand All @@ -159,7 +202,6 @@ public String getName()
public void setName(String name)
{
this.name=name;
notifyChanged();
}

/**
Expand All @@ -186,7 +228,6 @@ public String getChemicalSerie()
public void setChemicalSerie(String chemicalSerie)
{
this.chemicalSerie = chemicalSerie;
notifyChanged();
}

/**
Expand All @@ -213,7 +254,6 @@ public Integer getPeriod()
public void setPeriod(Integer period)
{
this.period = period;
notifyChanged();
}

/**
Expand Down Expand Up @@ -241,7 +281,6 @@ public Integer getGroup()
public void setGroup(Integer group) throws CDKException {
if (group < 1 || group > 18) throw new CDKException("Invalid group number specified. Must be between 1 and 18");
this.group = group;
notifyChanged();
}

/**
Expand Down Expand Up @@ -269,7 +308,6 @@ public String getPhase()
public void setPhase(String phase)
{
this.phase = phase;
notifyChanged();
}

/**
Expand All @@ -296,7 +334,6 @@ public String getCASid()
public void setCASid(String casId)
{
this.casId = casId;
notifyChanged();
}

/**
Expand Down Expand Up @@ -366,15 +403,46 @@ public void setPaulingEneg(Double paulingEneg) {
*/
@TestMethod("testClone")
public Object clone() throws CloneNotSupportedException {
Object clone = null;
PeriodicTableElement clone = null;
try {
clone = super.clone();
clone = (PeriodicTableElement) super.clone();
clone.setSymbol(symbol);
clone.setAtomicNumber(atomicNumber);
clone.setChemicalSerie(chemicalSerie);
clone.setCASid(casId);
clone.setCovalentRadius(covalentRadius);
clone.setGroup(group);
clone.setName(name);
clone.setPaulingEneg(paulingEneg);
clone.setPeriod(period);
clone.setPhase(phase);
clone.setVdwRadius(vdwRadius);
} catch (Exception exception) {
logger.debug(exception);
}
return clone;
}


/**
* Get the atomic number for this element.
*
* @return the atomic number
*/
@TestMethod("testGetSetAtomicNumber")
public Integer getAtomicNumber() {
return atomicNumber;
}

/**
* Set the atomic number for this element.
*
* @param atomicNumber the atomic number
*/
@TestMethod("testGetSetAtomicNumber")
public void setAtomicNumber(Integer atomicNumber) {
this.atomicNumber = atomicNumber;
}

/**
*
*@return resultString String
Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.interfaces.IElement;

/**
* Checks the functionality of the ElementPTFactory
Expand Down Expand Up @@ -67,14 +66,7 @@ public void testConfigure_PeriodicTableElement() throws Exception {
ElementPTFactory elefac = ElementPTFactory.getInstance();
PeriodicTableElement pte = elefac.configure(new org.openscience.cdk.tools.periodictable.PeriodicTableElement("H"));
Assert.assertNotNull(pte);
}

@Test
public void testConfigureE_PeriodicTableElement() throws Exception {
ElementPTFactory elefac = ElementPTFactory.getInstance();
IElement element = elefac.configureE(new PeriodicTableElement("H"));
Assert.assertNotNull(element);
}
}

@Test public void testGetAtomicNumber_PeriodicTableElement() throws Exception {
ElementPTFactory elefac = ElementPTFactory.getInstance();
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.junit.Test;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.tools.diff.ElementDiff;

/**
* @cdk.module test-standard
Expand All @@ -40,6 +39,9 @@ public static void setUp() {
public void testConstructor() {
PeriodicTableElement pte = new PeriodicTableElement("C");
Assert.assertNotNull(pte);

pte = new PeriodicTableElement("C", 12);
Assert.assertNotNull(pte);
}
@Test
public void testGetName() {
Expand All @@ -54,6 +56,32 @@ public void testSetName() {
Assert.assertEquals("carbon", pte.getName());
}

@Test
public void testGetSymbol() {
PeriodicTableElement pte = new PeriodicTableElement("C");
Assert.assertNotNull(pte.getSymbol());
Assert.assertEquals("C", pte.getSymbol());
}

@Test
public void testSetSymbol() {
PeriodicTableElement pte = new PeriodicTableElement("C");
pte.setSymbol("B");
Assert.assertEquals("B", pte.getSymbol());
}

@Test
public void testGetSetAtomicNumber() {
PeriodicTableElement pte = new PeriodicTableElement("C");
Assert.assertNull(pte.getAtomicNumber());
pte.setAtomicNumber(6);
Assert.assertEquals(new Integer(6), pte.getAtomicNumber());

pte = new PeriodicTableElement("N", 7);
Assert.assertEquals(new Integer(7), pte.getAtomicNumber());
}


@Test
public void testGetCASid() {
PeriodicTableElement pte = new PeriodicTableElement("C");
Expand Down Expand Up @@ -168,9 +196,12 @@ public void testSetPeriod() {
@Test
public void testClone() throws CloneNotSupportedException {
PeriodicTableElement pte = new PeriodicTableElement("C");
pte.setPhase("liquid");
PeriodicTableElement cloneElement = (PeriodicTableElement) pte.clone();
String diff = ElementDiff.diff(pte, cloneElement);
Assert.assertEquals("", diff);
Assert.assertNotNull(cloneElement);

Assert.assertEquals(pte.getSymbol(), cloneElement.getSymbol());
Assert.assertEquals(pte.getPhase(), cloneElement.getPhase());
}

@Test
Expand Down

0 comments on commit 27fc004

Please sign in to comment.