Search in sources :

Example 1 with CMLArray

use of org.xmlcml.cml.element.CMLArray in project cdk by cdk.

the class QSARCustomizer method createScalar.

private Element createScalar(IDescriptorResult value) {
    Element scalar;
    if (value instanceof DoubleResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:double"));
        scalar.appendChild("" + ((DoubleResult) value).doubleValue());
    } else if (value instanceof IntegerResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:int"));
        scalar.appendChild("" + ((IntegerResult) value).intValue());
    } else if (value instanceof BooleanResult) {
        scalar = new CMLScalar();
        scalar.addAttribute(new Attribute("dataType", "xsd:boolean"));
        scalar.appendChild("" + ((BooleanResult) value).booleanValue());
    } else if (value instanceof IntegerArrayResult) {
        IntegerArrayResult result = (IntegerArrayResult) value;
        scalar = new CMLArray();
        scalar.addAttribute(new Attribute("dataType", "xsd:int"));
        scalar.addAttribute(new Attribute("size", "" + result.length()));
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < result.length(); i++) {
            buffer.append(result.get(i) + " ");
        }
        scalar.appendChild(buffer.toString());
    } else if (value instanceof DoubleArrayResult) {
        DoubleArrayResult result = (DoubleArrayResult) value;
        scalar = new CMLArray();
        scalar.addAttribute(new Attribute("dataType", "xsd:double"));
        scalar.addAttribute(new Attribute("size", "" + result.length()));
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < result.length(); i++) {
            buffer.append(result.get(i) + " ");
        }
        scalar.appendChild(buffer.toString());
    } else {
        // logger.error("Could not convert this object to a scalar element: ", value);
        scalar = new CMLScalar();
        scalar.appendChild(value.toString());
    }
    return scalar;
}
Also used : BooleanResult(org.openscience.cdk.qsar.result.BooleanResult) Attribute(nu.xom.Attribute) Element(nu.xom.Element) IntegerArrayResult(org.openscience.cdk.qsar.result.IntegerArrayResult) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) CMLScalar(org.xmlcml.cml.element.CMLScalar) IntegerResult(org.openscience.cdk.qsar.result.IntegerResult) CMLArray(org.xmlcml.cml.element.CMLArray)

Aggregations

Attribute (nu.xom.Attribute)1 Element (nu.xom.Element)1 BooleanResult (org.openscience.cdk.qsar.result.BooleanResult)1 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)1 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)1 IntegerArrayResult (org.openscience.cdk.qsar.result.IntegerArrayResult)1 IntegerResult (org.openscience.cdk.qsar.result.IntegerResult)1 CMLArray (org.xmlcml.cml.element.CMLArray)1 CMLScalar (org.xmlcml.cml.element.CMLScalar)1