List of usage examples for java.util Comparator Comparator
Comparator
From source file:com.eincs.athens.android.OlympusFeedActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_feed); mContext = this; mBtnWrite = (TextView) findViewById(R.id.btn_write); mData = new TreeMap<Integer, Post>(new Comparator<Integer>() { @Override/*from w ww .j a va2 s . c o m*/ public int compare(Integer object1, Integer object2) { return object2 - object1; } }); mDataArray = new ArrayList<Post>(); mAdapter = new PostAdapter(this, R.layout.item_post, mDataArray); setListAdapter(mAdapter); mBtnWrite.setOnClickListener(this); getTimeline(null, null); }
From source file:com.github.fauu.natrank.model.entity.City.java
@JsonIgnore public CityCountryAssoc getLastCityCountryAssoc() { List<CityCountryAssoc> cityCountryAssocsSortedByFromDate = new LinkedList<>(cityCountryAssocs); // TODO: Verify that this is the correct order! Collections.sort(cityCountryAssocsSortedByFromDate, new Comparator<CityCountryAssoc>() { @Override// w ww. ja va 2 s .c o m public int compare(CityCountryAssoc cityCountryAssoc1, CityCountryAssoc cityCountryAssoc2) { return cityCountryAssoc1.getPeriod().getFromDate() .compareTo(cityCountryAssoc2.getPeriod().getFromDate()); } }); return cityCountryAssocsSortedByFromDate.get(cityCountryAssocsSortedByFromDate.size() - 1); }
From source file:de.digiway.rapidbreeze.server.infrastructure.objectstorage.migration.ObjectStorageMigrate.java
private List<Class<MigrateScript>> getScripts(String packageName) { try {/*w w w.j a v a 2 s .c o m*/ List<Class<MigrateScript>> newScripts = new ArrayList<>(); for (Class clazz : getClasses(packageName)) { if (MigrateScript.class.isAssignableFrom(clazz) && !clazz.isInterface()) { newScripts.add(clazz); } } Collections.sort(newScripts, new Comparator<Class<MigrateScript>>() { @Override public int compare(Class<MigrateScript> o1, Class<MigrateScript> o2) { return o1.getSimpleName().compareTo(o2.getSimpleName()); } }); return newScripts; } catch (ClassNotFoundException | IOException ex) { throw new IllegalArgumentException("Cannot read migration scripts.", ex); } }
From source file:de.tsystems.mms.apm.performancesignature.util.PerfSigUtils.java
private static ListBoxModel sortListBoxModel(final ListBoxModel list) { Collections.sort(list, new Comparator<ListBoxModel.Option>() { @Override//from w w w. j av a2 s . co m public int compare(final ListBoxModel.Option o1, final ListBoxModel.Option o2) { return o1.name.compareToIgnoreCase(o2.name); } }); return list; }
From source file:eu.project.ttc.utils.TermSuiteUtils.java
public static <T> LinkedHashMap<T, Integer> getCounters(Iterable<T> list) { Comparator<Entry<T, MutableInt>> comparator = new Comparator<Entry<T, MutableInt>>() { public int compare(Entry<T, MutableInt> o1, Entry<T, MutableInt> o2) { return ComparisonChain.start().compare(o2.getValue(), o1.getValue()).result(); };// ww w.j a v a2 s . c o m }; Map<T, MutableInt> map = Maps.newHashMap(); for (T e : list) { MutableInt counter = map.get(e); if (counter == null) { counter = new MutableInt(0); map.put(e, counter); } counter.increment(); } List<Entry<T, MutableInt>> entries = Lists.newArrayList(map.entrySet()); Collections.sort(entries, comparator); LinkedHashMap<T, Integer> counters = Maps.newLinkedHashMap(); for (Entry<T, MutableInt> e : entries) counters.put(e.getKey(), e.getValue().intValue()); return counters; }
From source file:org.openmrs.module.emrapi.encounter.mapper.OrderMapper1_10.java
private void sortByOrderNumber(List<EncounterTransaction.DrugOrder> orders) { Collections.sort(orders, new Comparator<EncounterTransaction.DrugOrder>() { @Override//from w w w. j a v a 2 s . c o m public int compare(EncounterTransaction.DrugOrder drugOrder1, EncounterTransaction.DrugOrder drugOrder2) { return drugOrder1.getOrderNumber().compareTo(drugOrder2.getOrderNumber()); } }); }
From source file:com.github.fge.jsonschema.keyword.digest.draftv3.DraftV3DependenciesDigester.java
private static JsonNode sortedSet(final JsonNode node) { final SortedSet<JsonNode> set = Sets.newTreeSet(new Comparator<JsonNode>() { @Override/*w ww . j a v a2 s . c o m*/ public int compare(final JsonNode o1, final JsonNode o2) { return o1.textValue().compareTo(o2.textValue()); } }); set.addAll(Sets.newHashSet(node)); final ArrayNode ret = FACTORY.arrayNode(); ret.addAll(set); return ret; }
From source file:com.appeligo.search.actions.ProgramRemindersPageAction.java
public String execute() throws Exception { //sort programs alphabetically and by programId programAlerts = new LinkedList<ProgramAlert>(getUser().getLiveProgramAlerts()); Collections.sort(programAlerts, new Comparator<ProgramAlert>() { public int compare(ProgramAlert left, ProgramAlert right) { String leftStr = left.getProgram().getLabel(); String rightStr = right.getProgram().getLabel(); int rtn = leftStr.compareTo(rightStr); if (rtn == 0 && left.getProgramId() != null && right.getProgramId() != null) { rtn = left.getProgramId().compareTo(right.getProgramId()); }/*from w ww.ja v a 2 s .c o m*/ return rtn; } }); //ensure that programAlerts on matching programs are clustered together LinkedList<ProgramAlert> newlist = new LinkedList<ProgramAlert>(); while (programAlerts.size() > 0) { ProgramAlert alert = programAlerts.remove(0); newlist.add(alert); String targetId = alert.getProgramId(); int j = 0; while (j < programAlerts.size()) { if (programAlerts.get(j).getProgramId().equals(targetId)) { newlist.add(programAlerts.remove(j)); } else { j++; } } } programAlerts = newlist; AlertManager alertManager = AlertManager.getInstance(); EPGProvider epgProvider = alertManager.getEpg(); String lineup = getUser().getLineupId(); nextAiringList = new LinkedList<ScheduledProgram>(); String previousTargetId = null; for (ProgramAlert programAlert : programAlerts) { String targetId = programAlert.getProgramId(); if (!targetId.equals(previousTargetId)) { ScheduledProgram nextAiring = null; if (programAlert.isNewEpisodes()) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), true, true); } if (nextAiring == null) { nextAiring = epgProvider.getNextShowing(lineup, programAlert.getProgramId(), false, true); } nextAiringList.add(nextAiring); previousTargetId = targetId; } else { nextAiringList.add(null); } } return SUCCESS; }
From source file:springfox.documentation.spi.service.contexts.Orderings.java
public static Comparator<ResourceGroup> resourceGroupComparator() { return new Comparator<ResourceGroup>() { @Override//from w w w. j a va2s .c om public int compare(ResourceGroup first, ResourceGroup second) { return first.getGroupName().compareTo(second.getGroupName()); } }; }
From source file:com.haulmont.cuba.gui.data.impl.HierarchicalPropertyDatasourceImpl.java
@Override public Collection<K> getChildren(K itemId) { if (hierarchyPropertyName != null) { final Entity item = getItem(itemId); if (item == null) return Collections.emptyList(); List<K> res = new ArrayList<>(); Collection<K> ids = getItemIds(); for (K id : ids) { Entity<K> currentItem = getItem(id); Object parentItem = currentItem.getValue(hierarchyPropertyName); if (parentItem != null && parentItem.equals(item)) res.add(currentItem.getId()); }//from w ww.jav a 2 s. com if (StringUtils.isNotBlank(sortPropertyName)) { Collections.sort(res, new Comparator<K>() { @Override public int compare(K o1, K o2) { Entity item1 = getItem(o1); Entity item2 = getItem(o2); Object value1 = item1.getValue(sortPropertyName); Object value2 = item2.getValue(sortPropertyName); if ((value1 instanceof Comparable) && (value2 instanceof Comparable)) return ((Comparable) value1).compareTo(value2); return 0; } }); } return res; } return Collections.emptyList(); }