Search in sources :

Example 1 with FormatKey

use of eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey in project cdmlib by cybertaxonomy.

the class CategoricalDataFormatterTest method testFormat.

@Test
public void testFormat() {
    CategoricalData catData = CategoricalData.NewInstance(Feature.HABITAT());
    catData.addStateData(stateData1);
    FormatKey[] formatKey = null;
    CategoricalDataFormatter formatter = new CategoricalDataFormatter(catData, formatKey);
    String text = formatter.format(catData, formatKey);
    Assert.assertEquals("state1", text);
    catData.addStateData(stateData2);
    text = formatter.format(catData, formatKey);
    Assert.assertEquals("state1, state2", text);
    catData.addStateData(stateData3);
    text = formatter.format(catData, formatKey);
    Assert.assertEquals("state1, state2, state3", text);
// TODO test with modifiers and maybe with other basedata like timeperiod etc.
}
Also used : FormatKey(eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey) CategoricalData(eu.etaxonomy.cdm.model.description.CategoricalData) Test(org.junit.Test)

Example 2 with FormatKey

use of eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey in project cdmlib by cybertaxonomy.

the class DerivedUnitDTO method composeSpecimenShortTitle.

protected String composeSpecimenShortTitle(DerivedUnit derivedUnit) {
    FormatKey collectionKey = FormatKey.COLLECTION_CODE;
    String specimenShortTitle = CdmFormatterFactory.format(derivedUnit, collectionKey);
    if (CdmUtils.isBlank(specimenShortTitle)) {
        collectionKey = FormatKey.COLLECTION_NAME;
    }
    if (CdmUtils.isNotBlank(derivedUnit.getMostSignificantIdentifier())) {
        specimenShortTitle = CdmFormatterFactory.format(derivedUnit, new FormatKey[] { collectionKey, FormatKey.SPACE, FormatKey.MOST_SIGNIFICANT_IDENTIFIER });
        if (!specimenShortTitle.isEmpty() && derivedUnit instanceof MediaSpecimen) {
            Media media = ((MediaSpecimen) derivedUnit).getMediaSpecimen();
            if (media != null && !CdmUtils.isBlank(media.getTitleCache())) {
                if (media.getTitle() != null && !media.getTitle().getText().isEmpty()) {
                    specimenShortTitle += " (" + media.getTitle().getText() + ")";
                }
            }
        }
    }
    if (CdmUtils.isBlank(specimenShortTitle)) {
        specimenShortTitle = derivedUnit.getTitleCache();
    }
    if (CdmUtils.isBlank(specimenShortTitle)) {
        // should not be necessary as titleCache should never be empty
        specimenShortTitle = derivedUnit.getUuid().toString();
    }
    return specimenShortTitle;
}
Also used : FormatKey(eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey) MediaSpecimen(eu.etaxonomy.cdm.model.occurrence.MediaSpecimen) Media(eu.etaxonomy.cdm.model.media.Media)

Example 3 with FormatKey

use of eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey in project cdmlib by cybertaxonomy.

the class QuantitativeDataFormatterTest method testFormat.

@Test
public void testFormat() {
    QuantitativeData quantData = QuantitativeData.NewInstance(Feature.CHROMOSOME_NUMBER());
    FormatKey[] formatKey = null;
    quantData.addStatisticalValue(min1);
    quantData.addStatisticalValue(max1);
    QuantitativeDataFormatter formatter = new QuantitativeDataFormatter(quantData, formatKey);
    String text = formatter.format(quantData, formatKey);
    Assert.assertEquals("0.1-1.3", text);
    quantData.addStatisticalValue(n1);
    MeasurementUnit unit = MeasurementUnit.METER();
    quantData.setUnit(unit);
    text = formatter.format(quantData, formatKey);
    Assert.assertEquals("0.1-1.3 m [n=2]", text);
}
Also used : MeasurementUnit(eu.etaxonomy.cdm.model.description.MeasurementUnit) FormatKey(eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey) QuantitativeData(eu.etaxonomy.cdm.model.description.QuantitativeData) Test(org.junit.Test)

Aggregations

FormatKey (eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey)3 Test (org.junit.Test)2 CategoricalData (eu.etaxonomy.cdm.model.description.CategoricalData)1 MeasurementUnit (eu.etaxonomy.cdm.model.description.MeasurementUnit)1 QuantitativeData (eu.etaxonomy.cdm.model.description.QuantitativeData)1 Media (eu.etaxonomy.cdm.model.media.Media)1 MediaSpecimen (eu.etaxonomy.cdm.model.occurrence.MediaSpecimen)1