/** * Most of the code in the Qalingo project is copyrighted Hoteia and licensed * under the Apache License Version 2.0 (release version 0.8.0) * http://www.apache.org/licenses/LICENSE-2.0 * * Copyright (c) Hoteia, 2012-2014 * http://www.hoteia.com - http://twitter.com/hoteia - contact@hoteia.com * */ package org.hoteia.qalingo.core.web.mvc.viewbean; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; public class StoreLocatorCityFilterBean extends AbstractViewBean { /** * */ private static final long serialVersionUID = 8286353003242432122L; private String name; private String code; private List<StoreViewBean> stores; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<StoreViewBean> getStores() { return stores; } public void addStore(StoreViewBean store) { if(this.stores == null){ this.stores = new ArrayList<StoreViewBean>(); } this.stores.add(store); } public void sortStores() { List<StoreViewBean> sortedObjects = new LinkedList<StoreViewBean>(stores); Collections.sort(sortedObjects, new Comparator<StoreViewBean>() { @Override public int compare(StoreViewBean o1, StoreViewBean o2) { if (o1 != null && o2 != null) { int compare = o1.getName().compareTo(o2.getName()); if (compare != 0) { return compare; } return o1.getName().compareTo(o2.getName()); } return 0; } }); this.stores = sortedObjects; } }