Example usage for java.lang Integer compareTo

List of usage examples for java.lang Integer compareTo

Introduction

In this page you can find the example usage for java.lang Integer compareTo.

Prototype

public int compareTo(Integer anotherInteger) 

Source Link

Document

Compares two Integer objects numerically.

Usage

From source file:de.kp.ames.web.function.domain.model.JsonAccessor.java

/**
 * A helper method to retrieve the transformators
 * from a service object//from  ww w.  ja  v a 2  s .  c  o  m
 * 
 * @param service
 * @return
 * @throws JAXRException
 * @throws JSONException
 */
private JSONArray getSpecifications(ServiceImpl service) throws JAXRException, JSONException {

    Map<Integer, JSONObject> collector = new TreeMap<Integer, JSONObject>(new Comparator<Integer>() {
        public int compare(Integer seqno1, Integer seqno2) {
            return seqno1.compareTo(seqno2);
        }
    });

    /* 
      * Specifications
      */
    Collection<?> bindings = service.getServiceBindings();
    if ((bindings == null) || (bindings.size() == 0))
        return new JSONArray();

    /*
     * Take the first binding of the respective service into account
     */
    ServiceBindingImpl binding = (ServiceBindingImpl) bindings.toArray()[0];

    /* 
     * Next the specification links of the respective binding are determined
     */
    Collection<?> specs = binding.getSpecificationLinks();
    if ((specs == null) || (specs.size() == 0))
        return new JSONArray();

    Iterator<?> iterator = specs.iterator();
    while (iterator.hasNext()) {

        SpecificationLinkImpl spec = (SpecificationLinkImpl) iterator.next();

        Object[] values = spec.getSlot(JaxrConstants.SLOT_SEQNO).getValues().toArray();
        int seqNo = Integer.parseInt((String) values[0]);

        RegistryObjectImpl ro = (RegistryObjectImpl) spec.getSpecificationObject();

        JSONObject jTransformator = new JSONObject();

        jTransformator.put(JaxrConstants.RIM_ID, ro.getId());
        String name = jaxrBase.getName(ro);
        /*
         * If no matching locale string exists, get the closest match
         */
        name = (name == "") ? ro.getDisplayName() : name;

        jTransformator.put(JaxrConstants.RIM_NAME, name);

        collector.put(seqNo, jTransformator);

    }

    return new JSONArray(collector.values());

}

From source file:org.forgerock.openig.migrate.action.InlineDeclarationsAction.java

private Comparator<? super ObjectModel> byReverseIndex() {
    return new Comparator<ObjectModel>() {
        @Override// w  ww.j  ava2 s.  com
        public int compare(final ObjectModel o1, final ObjectModel o2) {
            Integer i1 = o1.getIndex();
            Integer i2 = o2.getIndex();
            return -(i1.compareTo(i2));
        }
    };
}

From source file:com.aionemu.gameserver.model.instance.instancereward.KamarBattlefieldReward.java

public List<KamarBattlefieldPlayerReward> sortPoints() {
    return sort(getInstanceRewards(), on(PvPArenaPlayerReward.class).getScorePoints(),
            new Comparator<Integer>() {
                @Override/*from ww w  .  j a va2  s. co m*/
                public int compare(Integer o1, Integer o2) {
                    return o2 != null ? o2.compareTo(o1) : -o1.compareTo(o2);
                }
            });
}

From source file:nz.co.senanque.rulesparser.AbstractRule.java

/**
 * @see java.lang.Comparable#compareTo(Object)
 * //ww w  .j  av a 2s. com
 * We need this because we sort by the number of conditions on the rule
 * The comparison is done in reverse because we want the high conditions at the top
 */
public final int compareTo(AbstractRule o) {
    Integer us = new Integer(this.getSpecificity());
    Integer them = new Integer(o.getSpecificity());
    return them.compareTo(us);
}

From source file:de.kp.ames.web.function.domain.model.JsonProductor.java

/**
 * A helper method to retrieve the transformators
 * from a service object//from   w ww .j a va 2 s  . com
 * 
 * @param service
 * @return
 * @throws JAXRException
 * @throws JSONException
 */
private JSONArray getSpecifications(ServiceImpl service) throws JAXRException, JSONException {

    Map<Integer, JSONObject> collector = new TreeMap<Integer, JSONObject>(new Comparator<Integer>() {
        public int compare(Integer seqno1, Integer seqno2) {
            return seqno1.compareTo(seqno2);
        }
    });

    /* 
      * Specifications
      */
    Collection<?> bindings = service.getServiceBindings();
    if ((bindings == null) || (bindings.size() == 0))
        return new JSONArray();

    /*
     * Take the first binding of the respective service into account
     */
    ServiceBindingImpl binding = (ServiceBindingImpl) bindings.toArray()[0];

    /* 
     * Next the specification links of the respective binding are determined
     */
    Collection<?> specs = binding.getSpecificationLinks();
    if ((specs == null) || (specs.size() == 0))
        return new JSONArray();

    Iterator<?> iterator = specs.iterator();
    while (iterator.hasNext()) {

        SpecificationLinkImpl spec = (SpecificationLinkImpl) iterator.next();

        Object[] values = spec.getSlot(JaxrConstants.SLOT_SEQNO).getValues().toArray();
        int seqNo = Integer.parseInt((String) values[0]);

        RegistryObjectImpl ro = (RegistryObjectImpl) spec.getSpecificationObject();

        JSONObject jTransformator = new JSONObject();

        jTransformator.put(JaxrConstants.RIM_SEQNO, (new Integer(seqNo)).toString());

        jTransformator.put(JaxrConstants.RIM_ID, ro.getId());
        String name = jaxrBase.getName(ro);
        /*
         * If no matching locale string exists, get the closest match
         */
        name = (name == "") ? ro.getDisplayName() : name;

        jTransformator.put(JaxrConstants.RIM_NAME, name);

        collector.put(seqNo, jTransformator);

    }

    return new JSONArray(collector.values());

}

From source file:com.aionemu.gameserver.model.instance.instancereward.IdgelDomeReward.java

public List<IdgelDomePlayerReward> sortPoints() {
    return sort(getInstanceRewards(), on(PvPArenaPlayerReward.class).getScorePoints(),
            new Comparator<Integer>() {
                @Override/*from   w  w  w  .  j  av a 2 s  .com*/
                public int compare(Integer o1, Integer o2) {
                    return o2 != null ? o2.compareTo(o1) : -o1.compareTo(o2);
                }
            });
}

From source file:org.mitre.secretsharing.cli.cmd.RootCommand.java

@Override
public void showHelp(PrintStream out) {
    super.showHelp(out);

    out.println();/*  w  ww . j  av  a 2  s.co  m*/

    Options cmds = new Options();
    for (Command c : Commands.subCommands()) {
        cmds.addOption(null, c.getName(), false, c.getDescription());
    }

    HelpFormatter h = new HelpFormatter();
    h.setSyntaxPrefix("");
    h.setLongOptPrefix("");
    h.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option o1, Option o2) {
            Integer p1 = Commands.names().indexOf(o1.getLongOpt());
            Integer p2 = Commands.names().indexOf(o2.getLongOpt());
            return p1.compareTo(p2);
        }
    });
    h.printHelp(new PrintWriter(out, true), 80, "Valid Commands:", "", cmds, 12, 12, getActualHelpFooter());
    out.flush();
}

From source file:org.theospi.portfolio.presentation.model.PresentationPage.java

public int compareTo(Object o) {
    PresentationPage other = (PresentationPage) o;
    Integer seq = Integer.valueOf(getSequence());
    Integer seqOther = Integer.valueOf(other.getSequence());
    return seq.compareTo(seqOther);
}

From source file:net.sourceforge.fenixedu.domain.curriculum.Grade.java

@Override
public int compareTo(IGrade o) {
    if (this.getGradeType() == o.getGradeType()) {
        if (this.getGradeType() == GradeType.GRADEFIVE || this.getGradeType() == GradeType.GRADETWENTY) {
            Integer grade1 = (Integer) this.getGradeValue();
            Integer grade2 = (Integer) o.getGradeValue();
            return grade1.compareTo(grade2);
        } else {//  ww w.j  av  a 2s .co  m
            return 0;
        }
    }
    if (this.getGradeType() == GradeType.GRADENA || this.getGradeType() == GradeType.GRADERE) {
        return 1;
    }
    if (o.getGradeType() == GradeType.GRADENA || o.getGradeType() == GradeType.GRADERE) {
        return -1;
    }

    throw new DomainException("error.grade.different.grade.types");
}

From source file:com.openshift.internal.restclient.model.Service.java

private List<IServicePort> getPorts(boolean modifiable) {
    List<IServicePort> ports = new ArrayList<>();
    if (!get(SERVICE_PORT).isDefined())
        return ports;
    for (ModelNode node : get(SERVICE_PORT).asList()) {
        ports.add(new ServicePort(node));
    }//from  w  w  w  .  j a  v  a 2  s .c  o m
    Collections.sort(ports, new Comparator<IServicePort>() {
        @Override
        public int compare(IServicePort first, IServicePort second) {
            Integer port0 = first.getPort();
            Integer port1 = second.getPort();
            return port0.compareTo(port1);
        }
    });
    return modifiable ? ports : Collections.unmodifiableList(ports);
}