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.
}
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;
}
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);
}
Aggregations