Example usage for org.springframework.beans.support PropertyComparator PropertyComparator

List of usage examples for org.springframework.beans.support PropertyComparator PropertyComparator

Introduction

In this page you can find the example usage for org.springframework.beans.support PropertyComparator PropertyComparator.

Prototype

public PropertyComparator(String property, boolean ignoreCase, boolean ascending) 

Source Link

Document

Create a PropertyComparator for the given settings.

Usage

From source file:org.domdrides.repository.RepositoryTestCase.java

@SuppressWarnings("unchecked")
private List<Person> createSortedPersonList(Collection<Person> people) {
    final List<Person> list = new ArrayList<Person>(people);
    Collections.sort(list, new PropertyComparator("ssn", true, true));
    return list;/*from   w  w w. j  av  a2  s  . com*/
}

From source file:com.qrmedia.commons.persistence.hibernate.clone.HibernateEntityGraphClonerWorkflowItest.java

@SuppressWarnings("unchecked")
@Test//from w  w w  . j a  v  a  2 s .  com
public void clone_updateOriginal_modifiedAssociatedEntities() {
    // use get rather than load to get associated collections
    Pet garfield = (Pet) session.get(Pet.class, garfieldId);
    Pet garfieldClone = entityGraphCloner.clone(garfield, true);
    session.evict(garfield);

    // modify an associated object
    int newNumChewMarks = 7;
    Set<Toy> garfieldCloneToys = garfieldClone.getToys();
    garfieldCloneToys.iterator().next().setNumChewMarks(newNumChewMarks);

    String newToyProductName = "Paddington Bear";
    Toy cuddlyBear = new Toy(newToyProductName, 0);
    garfieldCloneToys.add(cuddlyBear);

    session.update(garfieldClone);
    flushAndEvict(garfieldClone);

    // load the persisted object and compare
    Pet updatedGarfield = loadEntity(Pet.class, garfieldId);
    assertEquals(garfield, updatedGarfield);

    // check that one new associated object was added and an existing one modified
    List<Toy> updatedToys = new ArrayList<Toy>(updatedGarfield.getToys());
    Collections.sort(updatedToys, new PropertyComparator("numChewMarks", false, true));
    assertEquals(garfield.getToys().size() + 1, updatedToys.size());
    assertEquals(newToyProductName, updatedToys.get(0).getProductName());
    assertEquals(newNumChewMarks, updatedToys.get(1).getNumChewMarks());

    // check that no duplicate object has been created
    assertEquals(1, session.createQuery("from Pet where species = ?").setParameter(0, garfield.getSpecies())
            .list().size());
}

From source file:net.micwin.openspace.view.BasePageView.java

public void sort(List<? extends OpenSpaceEntity> nanites) {
    String sortProperty = getSortProperty();
    boolean sortPropertyAsc = getSortAscending();

    if (sortProperty != null) {

        PropertyComparator pc = new PropertyComparator(sortProperty, true, sortPropertyAsc);
        Collections.sort(nanites, pc);
    }//  w  ww  .  j a v a  2s  . com
}

From source file:net.tenorite.web.TempoController.java

@RequestMapping("/t/{tempo}/channels")
public DeferredResult<ModelAndView> channels(@PathVariable("tempo") Tempo tempo) {
    DeferredResult<ModelAndView> deferred = new DeferredResult<>();

    channelsRegistry.listChannels(tempo).whenComplete((channels, throwable) -> {
        if (throwable != null) {
            deferred.setErrorResult(throwable);
        } else {/*from w  ww .j av  a2  s .c om*/
            List<Channel> sorted = channels.stream().sorted(new PropertyComparator<>("name", true, true))
                    .collect(toList());

            ModelAndView mav = new ModelAndView("channels").addObject("tempo", tempo)
                    .addObject("gameModes", gameModes).addObject("channels", sorted);

            deferred.setResult(mav);
        }
    });

    return deferred;
}

From source file:nl.strohalm.cyclos.services.customization.BaseCustomFieldServiceImpl.java

@Override
@SuppressWarnings("unchecked")
public void setOrder(final List<Long> ids) {
    int order = 0;
    for (Long id : ids) {
        CF field = loadChecked(id);//from ww  w  .jav  a  2  s.  c o  m
        field.setOrder(++order);
        List<CustomField> children = new ArrayList<CustomField>(field.getChildren());
        if (CollectionUtils.isNotEmpty(children)) {
            Collections.sort(children, new PropertyComparator("name", true, true));
            for (CustomField child : children) {
                child.setOrder(++order);
            }
        }
    }
    getCache().clear();
}