Example usage for java.util Comparator Comparator

List of usage examples for java.util Comparator Comparator

Introduction

In this page you can find the example usage for java.util Comparator Comparator.

Prototype

Comparator

Source Link

Usage

From source file:com.github.nmorel.gwtjackson.client.mapper.ErrorGwtTest.java

public void testSerialization() {
    // Using a class inside java.* package to test we don't generate the mapper inside it because it is prohibited by java.
    ComparatorIntegerMapper.INSTANCE.write(new Comparator<Integer>() {
        @Override/* w ww.  j av a  2  s  .  c o m*/
        public int compare(Integer o1, Integer o2) {
            return 0;
        }
    });
}

From source file:org.openmrs.web.controller.observation.PersonObsFormController.java

@Override
protected CommandObject formBackingObject(HttpServletRequest request) throws Exception {
    if (!Context.isAuthenticated()) {
        return new CommandObject();
    }/* w  w w. j ava 2  s  .c om*/

    Person person = Context.getPersonService().getPerson(Integer.valueOf(request.getParameter("personId")));
    List<Concept> concepts = null;
    Concept concept = null;
    if (request.getParameter("conceptId") != null) {
        concept = Context.getConceptService().getConcept(Integer.valueOf(request.getParameter("conceptId")));
        concepts = Collections.singletonList(concept);
    }

    ObsService os = Context.getObsService();
    List<Obs> ret = os.getObservations(Collections.singletonList(person), null, concepts, null, null, null,
            null, null, null, null, null, true);
    Collections.sort(ret, new Comparator<Obs>() {

        public int compare(Obs left, Obs right) {
            int temp = left.getConcept().getName().getName().compareTo(right.getConcept().getName().getName());
            if (temp == 0) {
                temp = OpenmrsUtil.compareWithNullAsGreatest(left.getVoided(), right.getVoided());
            }
            if (temp == 0) {
                temp = OpenmrsUtil.compareWithNullAsLatest(left.getObsDatetime(), right.getObsDatetime());
            }
            return temp;
        }

    });
    return new CommandObject(person, concept, ret);
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.PropertiesChainedRegexURLRequestMapperDAO.java

/** @see URLRequestMapperDAO#load() */
public final URLRequestMapper load() {
    final Properties p = provider.getProperties();
    final List<Entry<Object, Object>> l = new ArrayList<Entry<Object, Object>>(p.entrySet());

    Collections.sort(l, new Comparator<Entry<Object, Object>>() {
        public int compare(final Entry<Object, Object> o1, final Entry<Object, Object> o2) {
            final Long i1 = Long.parseLong(o1.getKey().toString());
            final Long i2 = Long.parseLong(o2.getKey().toString());
            return i1.compareTo(i2);
        }/*w w  w.  j  a  v  a 2s .co m*/
    });

    final StringBuffer sb = new StringBuffer();
    for (final Entry<Object, Object> entry : l) {
        sb.append(entry.getValue());
        sb.append('\n');
    }
    final URLRequestMapperEditor propertyEditor = new URLRequestMapperEditor();
    propertyEditor.setStripContextPath(stripContextPath);
    propertyEditor.setStripServletPath(stripServletPath);
    propertyEditor.setAsText(sb.toString());
    return (URLRequestMapper) propertyEditor.getValue();
}

From source file:com.anrisoftware.simplerest.oanda.core.Granularities.java

private List<Granularity> getGranularities(Set<String> granularites) {
    Set<Granularity> sorted = new TreeSet<Granularity>(new Comparator<Granularity>() {

        @Override//  w ww.j a  v  a2  s  .  com
        public int compare(Granularity o1, Granularity o2) {
            return o1.getDuration().compareTo(o2.getDuration());
        }
    });
    for (String name : granularites) {
        sorted.add(Granularity.valueOf(name));
    }
    List<Granularity> result = new ArrayList<Granularity>(sorted.size());
    for (Granularity granularity : sorted) {
        result.add(granularity);
    }
    return Collections.unmodifiableList(result);
}

From source file:net.anthonypoon.fintech.assignment.one.part2.Portfolio.java

public void sortByExReturnOverBeta() {
    Collections.sort(stockList, new Comparator<Stock>() {
        @Override//from w ww  .  ja  va2 s  . c o m
        public int compare(Stock o1, Stock o2) {
            return o2.getExReturnToBeta().compareTo(o1.getExReturnToBeta());
        }
    });
}

From source file:com.googlecode.logVisualizer.chart.SkillMPCostBarChart.java

@Override
protected CategoryDataset createDataset() {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    final String seriesName = "MP cost of Skills";

    // Create new list to not destroy the sorting of the old one.
    final List<Skill> skills = Lists.newArrayList(getLogData().getAllSkillsCast());

    // Sort from highest MP cost to lowest MP cost.
    Collections.sort(skills, new Comparator<Skill>() {

        public int compare(final Skill o1, final Skill o2) {
            return o2.getMpCost() - o1.getMpCost();
        }//  ww w. jav  a  2s .co m
    });

    // Add skills to dataset.
    for (final Skill s : skills) {
        if (s.getMpCost() > 0)
            dataset.addValue(s.getMpCost(), seriesName, s.getName());

        // The chart isn't readable anymore with too many entries
        if (dataset.getColumnCount() > 45)
            break;
    }

    return dataset;
}

From source file:mt.Tracking.java

public static ArrayList<FLSobject> loadMTStat(final File file) {
    final ArrayList<FLSobject> points = new ArrayList<FLSobject>();

    try {/* ww w.j  av a 2s . c o m*/
        BufferedReader in = Util.openFileRead(file);

        while (in.ready()) {
            String line = in.readLine().trim();

            while (line.contains("\t\t"))
                line = line.replaceAll("\t\t", "\t");

            if (line.length() >= 3 && line.matches("[0-9].*")) {
                final String[] split = line.trim().split("\t");

                final int frame = (int) Double.parseDouble(split[0]);
                final double length = Double.parseDouble(split[2]);
                final int seedID = (int) Double.parseDouble(split[3]);

                FLSobject statobject = new FLSobject(frame, seedID, length);
                points.add(statobject);
            }
        }
    } catch (Exception e) {

    }

    Collections.sort(points, new Comparator<FLSobject>() {
        @Override
        public int compare(final FLSobject o1, final FLSobject o2) {

            final int t1 = o1.Framenumber;
            final int t2 = o2.Framenumber;

            if (t1 < t2)
                return -1;
            else if (t1 == t2)
                return 0;
            else
                return 1;
        }
    });

    if (points.size() > 0)
        return points;

    else
        return null;
}

From source file:org.mifos.androidclient.util.listadapters.SimpleExpandableListAdapter.java

public SimpleExpandableListAdapter(Context context, Map<SimpleListItem, List<SimpleListItem>> items) {
    mContext = context;//from w  ww  .j a v  a2s.  co  m
    mItems = new TreeMap<SimpleListItem, List<SimpleListItem>>(new Comparator<SimpleListItem>() {
        @Override
        public int compare(SimpleListItem simpleListItem1, SimpleListItem simpleListItem2) {
            return simpleListItem1.getListLabel().compareToIgnoreCase(simpleListItem2.getListLabel());
        }
    });
    mItems.putAll(items);
    mExpandGroups = false;
    splitItems(items);
}

From source file:com.clustercontrol.infra.factory.SelectInfraManagement.java

/**
 * ????/*  w  w  w. j  a  va 2 s.  c o m*/
 * <p>
 */
public InfraManagementInfo get(String infraManagementId, ObjectPrivilegeMode mode)
        throws InfraManagementNotFound, InvalidRole, HinemosUnknown {
    InfraManagementInfo info = QueryUtil.getInfraManagementInfoPK(infraManagementId, mode);

    // ??
    if (info.getModuleList() != null) {
        for (InfraModuleInfo<?> infraModuleInfo : info.getModuleList()) {
            infraModuleInfo = QueryUtil.getInfraModuleInfoPK(infraModuleInfo.getId());
        }
    }

    // ?
    info.setNotifyRelationList(new NotifyControllerBean().getNotifyRelation(info.getNotifyGroupId()));

    // FIXME:
    Collections.sort(info.getModuleList(), new Comparator<InfraModuleInfo<?>>() {
        @Override
        public int compare(InfraModuleInfo<?> o1, InfraModuleInfo<?> o2) {
            return o1.getOrderNo().compareTo(o2.getOrderNo());
        }
    });

    return info;
}