Search in sources :

Example 1 with TaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.TaxonComparator in project cdmlib by cybertaxonomy.

the class HomotypicalGroupComparator method compare.

@Override
public int compare(HomotypicalGroup group1, HomotypicalGroup group2) {
    TaxonBase<?> firstTypified1 = null;
    TaxonBase<?> firstTypified2 = null;
    if (group1.equals(group2)) {
        return 0;
    }
    TaxonComparator taxComparator = new HomotypicGroupTaxonComparator(null);
    Set<TaxonName> typifiedNames1 = group1.getTypifiedNames();
    List<TaxonBase> taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames1) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified1 = taxonBasesOfTypifiedNames.get(0);
    Set<TaxonName> typifiedNames2 = group2.getTypifiedNames();
    taxonBasesOfTypifiedNames = new ArrayList<>();
    for (TaxonName typifiedName : typifiedNames2) {
        if (!typifiedName.getTaxonBases().isEmpty()) {
            taxonBasesOfTypifiedNames.add(typifiedName.getTaxonBases().iterator().next());
        }
    }
    Collections.sort(taxonBasesOfTypifiedNames, taxComparator);
    firstTypified2 = taxonBasesOfTypifiedNames.get(0);
    return taxComparator.compare(firstTypified1, firstTypified2);
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 2 with TaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.TaxonComparator in project cdmlib by cybertaxonomy.

the class TaxonServiceImpl method findByTitleWithRestrictions.

@Transactional(readOnly = true)
@Override
public <S extends TaxonBase> Pager<S> findByTitleWithRestrictions(Class<S> clazz, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
    long numberOfResults = dao.countByTitleWithRestrictions(clazz, queryString, matchmode, restrictions);
    long numberOfResults_doubtful = dao.countByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions);
    List<S> results = new ArrayList<>();
    if (numberOfResults > 0 || numberOfResults_doubtful > 0) {
        // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
        results = dao.findByTitleWithRestrictions(clazz, queryString, matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths);
        results.addAll(dao.findByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths));
    }
    Collections.sort(results, new TaxonComparator());
    return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with TaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.TaxonComparator in project cdmlib by cybertaxonomy.

the class TaxonServiceImpl method findByTitle.

@Transactional(readOnly = true)
@Override
public <S extends TaxonBase> Pager<S> findByTitle(Class<S> clazz, String queryString, MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
    long numberOfResults = dao.countByTitle(clazz, queryString, matchmode, criteria);
    // check whether there are doubtful taxa matching
    long numberOfResults_doubtful = dao.countByTitle(clazz, "?".concat(queryString), matchmode, criteria);
    List<S> results = new ArrayList<>();
    if (numberOfResults > 0 || numberOfResults_doubtful > 0) {
        // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
        if (numberOfResults > 0) {
            results = dao.findByTitle(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
        } else {
            results = new ArrayList<>();
        }
        if (numberOfResults_doubtful > 0) {
            results.addAll(dao.findByTitle(clazz, "?".concat(queryString), matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths));
        }
    }
    Collections.sort(results, new TaxonComparator());
    return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with TaxonComparator

use of eu.etaxonomy.cdm.compare.taxon.TaxonComparator in project cdmlib by cybertaxonomy.

the class TaxonComparatorTest method testCompare.

/**
 ****************** TESTS ****************************************************
 */
@Test
public void testCompare() {
    List<TaxonBase<?>> list = createTestData();
    Collections.sort(list, new TaxonComparator());
    // Order should be
    // 4: 1823
    // 3: 1943
    // 1: 1945
    // 2:
    Assert.assertEquals(list.get(0).getId(), 3);
    Assert.assertEquals(getYear(list.get(0)), "1759");
    Assert.assertEquals(list.get(1).getId(), 1);
    Assert.assertEquals(getYear(list.get(1)), "1759");
    Assert.assertEquals(list.get(2).getId(), 5);
    Assert.assertEquals(getYear(list.get(2)), "1823");
    Assert.assertEquals(list.get(3).getId(), 4);
    Assert.assertEquals(getYear(list.get(3)), "1943");
    Assert.assertEquals(list.get(4).getId(), 2);
    Assert.assertEquals(getYear(list.get(4)), "");
}
Also used : TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) Test(org.junit.Test)

Aggregations

TaxonComparator (eu.etaxonomy.cdm.compare.taxon.TaxonComparator)4 HomotypicGroupTaxonComparator (eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator)3 ArrayList (java.util.ArrayList)3 DefaultPagerImpl (eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl)2 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)2 Transactional (org.springframework.transaction.annotation.Transactional)2 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)1 Test (org.junit.Test)1