Commit bf1d17f4 authored by Matija Obreza's avatar Matija Obreza
Browse files

TaxonomyDatabase#listSpecies

parent a04ecafa
......@@ -367,4 +367,16 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
// to String or null
.map(speciesRow -> speciesRow.getSubtaxaAuthority()).orElse(null);
}
/* (non-Javadoc)
* @see org.genesys2.gringlobal.taxonomy.component.TaxonomyDatabase#listSpecies(java.lang.String, java.lang.String, int)
*/
@Override
public List<SpeciesRow> listSpecies(String genus, String species, int maxSize) {
return getAllGenusSpecies(genus).stream()
// keep rows with matching species
.filter(speciesRow -> species.equals(speciesRow.getSpeciesName()))
// limit results to maxSize
.limit(maxSize).collect(Collectors.toList());
}
}
......@@ -18,6 +18,8 @@ package org.genesys2.gringlobal.taxonomy.component;
import java.util.List;
import org.genesys2.gringlobal.taxonomy.model.SpeciesRow;
/**
* Defines searches possible against a database of taxonomic data.
*/
......@@ -99,4 +101,13 @@ public interface TaxonomyDatabase {
*/
String getSubtaxaAuthority(String genus, String species, String subtaxa);
/**
* Return all subtaxa for genus and species
* @param genus valid genus
* @param species valid species
* @param maxSize maximum number of rows to return
* @return
*/
List<SpeciesRow> listSpecies(String genus, String species, int maxSize);
}
......@@ -1034,6 +1034,26 @@ public class SpeciesRow implements Serializable {
return "subsp. " + subspeciesName;
}
return null;
// StringBuilder sb = new StringBuilder();
// if (subspeciesName != null) {
// sb.append("subsp. ").append(subspeciesName);
// }
// if (varietyName != null) {
// if (sb.length() > 0)
// sb.append(" ");
// sb.append("var. ").append(varietyName);
// }
// if (subvarietyName != null) {
// if (sb.length() > 0)
// sb.append(" ");
// sb.append("subvar. ").append(subvarietyName);
// }
// if (formaName != null) {
// if (sb.length() > 0)
// sb.append(" ");
// sb.append("f. ").append(formaName);
// }
// return sb.length() == 0 ? null : sb.toString();
}
/**
......
......@@ -111,4 +111,32 @@ public class InMemoryDatabaseTest {
assertThat(DATABASE.containsGenus("Triticosecale"), equalTo(true));
}
@Test
public void testCucumisMeloAgrestis() {
if (DATABASE == null) {
return;
}
assertThat(DATABASE.containsGenus("Cucumis"), equalTo(true));
assertThat(DATABASE.containsSpecies("Cucumis", "melo"), equalTo(true));
// Cucumis melo subsp. agrestis
for (SpeciesRow speciesRow : DATABASE.listSpecies("Cucumis", "melo", 100)) {
if ("agrestis".equals(speciesRow.getSubspeciesName())) {
// System.err.println(speciesRow);
// System.err.println("\tsubsp. " + speciesRow.getSubspeciesName());
// System.err.println("\tvar. " + speciesRow.getVarietyName());
// System.err.println("\tNAME=" + speciesRow.getName());
}
}
for (SpeciesRow speciesRow : DATABASE.listSpecies("Vigna", "unguiculata", 100)) {
if ("protracta".equals(speciesRow.getVarietyName())) {
// System.err.println(speciesRow);
// System.err.println("\tsubsp. " + speciesRow.getSubspeciesName());
// System.err.println("\tvar. " + speciesRow.getVarietyName());
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment