Example usage for java.lang String compareTo

List of usage examples for java.lang String compareTo

Introduction

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

Prototype

public int compareTo(String anotherString) 

Source Link

Document

Compares two strings lexicographically.

Usage

From source file:it.fub.jardin.server.Upload.java

/**
 * Processa i valori ricevuti dalla form. I nomi dei campi vengono dalle
 * propriet statiche dal dialog di upload (dove sono preceduti dala stringa
 * "FIELD_")//from   www.ja  v a  2  s  . c  o  m
 * 
 * @param item
 *          il singolo campo ricevuto dal dialog di upload
 */
private void processFormField(final FileItem item) {
    String name = item.getFieldName();
    String value = item.getString();
    if (name.compareTo(UploadDialog.FIELD_TYPE) == 0) {
        this.type = value;
        //      Log.debug("TYPE: " + this.type);
    } else if (name.compareTo(UploadDialog.FIELD_RESULTSET) == 0) {
        this.resultset = Integer.parseInt(value);
        //      Log.debug("RESULTSET: " + this.resultset);
    } else if (name.compareTo(UploadDialog.FIELD_CREDENTIALS) == 0) {
        this.credentials = Credentials.parseCredentials(value);
        // Log.debug("USER: " + this.credentials.getUsername() + "; PASS: "
        // + this.credentials.getPassword());
    } else if (name.compareTo("textSep") == 0) {
        this.ts = value;
    } else if (name.compareTo("fieldSep") == 0) {
        this.fs = value;
    } else if (name.compareTo("limit") == 0) {
        this.tipologia = name;
    } else if (name.compareTo("fix") == 0) {
        this.tipologia = name;
    } else if (name.compareTo("condition") == 0) {
        this.condition = value;
    } else {
        //      Log.debug("attenzione campo non riconosciuto: " + name + "--->" + value);
    }
}

From source file:com.parse.PushHistory.java

/**
 * Attempts to insert a push into history. The push is ignored if we have already seen it
 * recently. Otherwise, the push is inserted into history. If the length of the history exceeds
 * the maximum length, then the history is trimmed by removing the oldest pushes until it no
 * longer exceeds the maximum length./*from w w  w . j av  a2  s .com*/
 * 
 * @return Returns whether or not the push was inserted into history.  
 */
public boolean tryInsertPush(String pushId, String timestamp) {
    if (timestamp == null) {
        throw new IllegalArgumentException("Can't insert null pushId or timestamp into history");
    }

    if (lastTime == null || timestamp.compareTo(lastTime) > 0) {
        lastTime = timestamp;
    }

    if (pushIds.contains(pushId)) {
        PLog.e(TAG, "Ignored duplicate push " + pushId);
        return false;
    }

    entries.add(new Entry(pushId, timestamp));
    pushIds.add(pushId);

    while (entries.size() > maxHistoryLength) {
        Entry head = entries.remove();
        pushIds.remove(head.pushId);
    }

    return true;
}

From source file:no.dusken.barweb.admin.InvoiceController.java

@RequestMapping(value = "/invoices/list.do", method = RequestMethod.GET)
public String listInvoices(@RequestParam(value = "gjengID", defaultValue = "0") Long gjengID, Model m) {
    List<Invoice> invoices;
    if (gjengID != 0) {
        Gjeng gjeng = gjengService.findOne(gjengID);
        invoices = invoiceService.getByGjengOrderByTimeCreatedDesc(gjeng);
        m.addAttribute("gjeng", gjeng);
    } else {/*from ww  w . j a v  a2  s .  c  o  m*/
        invoices = invoiceService.getByHidden(false);

        Comparator<Invoice> c = new Comparator<Invoice>() {
            public int compare(Invoice i1, Invoice i2) {
                Gjeng g1 = i1.getGjeng();
                Gjeng g2 = i2.getGjeng();
                if (g1 == null || g2 == null) {
                    if (g1 == null && g2 != null)
                        return -1;
                    if (g1 != null && g2 == null)
                        return 1;
                    else
                        return 0;
                }
                String g1name = g1.getName();
                String g2name = g2.getName();

                return g1name.compareTo(g2name);
            }
        };
        Collections.sort(invoices, c);

    }
    m.addAttribute("invoices", invoices);
    return "no/dusken/barweb/admin/invoice/list";
}

From source file:com.comcast.video.dawg.controller.house.MetaStbPropComparator.java

/**
 * {@inheritDoc}/*w  w  w  .j  av a 2s  . co m*/
 */
@Override
public int compare(String o1, String o2) {

    int order1 = ArrayUtils.indexOf(orderedProps, o1);
    int order2 = ArrayUtils.indexOf(orderedProps, o2);
    if (order1 < 0) {
        if (order2 < 0) {
            // none have a specified order, order alphabetically
            return o1.compareTo(o2);
        } else {
            // o1 is not ordered but o2 is, o2 should go first
            return 1;
        }
    } else {
        if (order2 < 0) {
            // o1 is  ordered but o2 is not, o1 should go first
            return -1;
        } else {
            // both are ordered, so order by the order...
            return order1 - order2;
        }
    }
}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.IdentifiableImpl.java

/**
 * Compares two registries objects. Consider adding Comparable to
 * RegistryObject in JAXR 2.0??/*from  w  ww.  j  a v  a 2  s  .  c  om*/
 * 
 * @return 0 (equal) is the id of the objects matches this objects id.
 *         Otherwise return -1 (this object is less than arg o).
 */
public int compareTo(Object o) {
    int result = -1;

    if (o instanceof IdentifiableImpl) {
        try {
            // Need class match otherwise RegistryObjectRef and
            // IdentifiableImpl
            // with same id will match when they should not.
            if (o.getClass() == this.getClass()) {
                String myId = getId();
                String otherId = ((IdentifiableImpl) o).getKey().getId();
                result = myId.compareTo(otherId);
            }
        } catch (JAXRException e) {
            e.printStackTrace();
        }
    }

    return result;
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.AddBookingRoomViewParamsController.java

@Override
public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
    Map map = new HashMap<String, Object>();

    int filterGroup = Integer.parseInt(request.getParameter("filterGroup"));
    String filterDate = request.getParameter("filterDate");
    if (filterDate.compareTo("") == 0)
        filterDate = null;/*from   w ww  . j a  va2s  .  c  o m*/
    int repType = Integer.parseInt(request.getParameter("repType"));
    int repCount = Integer.parseInt(request.getParameter("repCount"));

    String date = request.getParameter("date");
    String startStr = request.getParameter("startTime");
    String endStr = request.getParameter("endTime");

    GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr);
    boolean collisions = false;

    //reservations in not visible time period
    if (repCount > 0) {
        GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr);
        GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr);

        List<Reservation> coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS,
                nextE);

        map.put("collisionsInNext", coll);
        map.put("collisionsInNextCount", coll.size());
        if (coll.size() > 0)
            collisions = true;
    }

    //reservations in currently visible time period
    cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00");

    GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone();
    weekEnd.add(Calendar.DAY_OF_YEAR, 7);
    weekEnd.add(Calendar.SECOND, -1);

    map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup));
    map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - "
            + BookingRoomUtils.getHoursAndMinutes(endStr));

    String displayed = String.format(
            messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)),
            BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd));

    boolean filtered = false;

    if (filterDate != null) {//filter of date
        filtered = true;
        displayed = messageSource.getMessage("bookRoom.displayed.day", null,
                RequestContextUtils.getLocale(request)) + " " + filterDate;
    }

    if (filterGroup > 0) {
        filtered = true;
        displayed += (filterDate == null ? "," : " and") + " "
                + messageSource.getMessage("bookRoom.displayed.group", null,
                        RequestContextUtils.getLocale(request))
                + " " + getResearchGroup(filterGroup).getTitle();
    }

    if (filtered) {//we must verify that there are no reservations in selected range
        GregorianCalendar start = BookingRoomUtils.getCalendar(startStr);
        GregorianCalendar end = BookingRoomUtils.getCalendar(endStr);
        List<Reservation> coll = reservationDao.getReservationsBetween(start, end);
        if (coll.size() > 0) {
            //if the collision exists
            collisions = true;
            map.put("collisions", coll);
            map.put("collisionsCount", coll.size());
        }
    }

    map.put("displayed", displayed);

    map.put("collisionsExist", (collisions) ? "1" : "0");

    /*
    -- JSP can get this from params object --
    map.put("repCount", repCount);
    map.put("repType", repType);
    map.put("group", group);
    map.put("date", date);*/
    map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", ""));
    map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", ""));
    map.put("loggedUser", personDao.getLoggedPerson());
    GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson());

    return map;
}

From source file:fi.nls.fileservice.web.admin.controller.DatasetAdminController.java

@RequestMapping(value = "/tuotteet", method = RequestMethod.GET)
public String datasetList(HttpServletRequest request, Model model) {
    List<Dataset> datasets = datasetService.getAllDatasets();

    // sort alphabetically by title
    Collections.sort(datasets, new Comparator<Dataset>() {

        @Override//from   w  w w. j a va2s  .  c o  m
        public int compare(Dataset d1, Dataset d2) {
            String d1Title = d1.getTranslatedTitles().get("fi");
            String d2Title = d2.getTranslatedTitles().get("fi");
            if (d1Title != null && d2Title != null) {
                return d1Title.compareTo(d2Title);
            }

            return 0;
        }

    });

    model.addAttribute("datasets", datasets); // auto gen would give JCRNodeDatasetList
    return "admin/datasets";
}

From source file:eurecom.web.service.SWOTWS.java

/**
 * get senml sensor data in a textarea and convert them into RDF
 * Web service used in http://sensormeasurement.appspot.com/?p=senml_converter
 * @param senmlData/*w  w w .j  a  v a2  s  .  c  o  m*/
 * @return
 */
@GET
@Path("/convert_senml_to_rdf/")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public Response getSenmlTextAndConvert(@QueryParam(value = "data") String senmlData,
        @QueryParam(value = "format") String format) {
    String msg = "No results";
    System.out.println(format + " " + senmlData);
    try {

        if (format.compareTo("xml") == 0) {
            ConvertSensorDataToM3 m3 = new ConvertSensorDataToM3();
            msg = m3.convertXMLSenMLIntoRDF(senmlData, "featureOfInterest",
                    "featureOfInterest" + "Measurement");
            System.out.println("if: " + format + " " + msg);
        }
        /*   else if (format.compareTo("json")==0){         
              ConvertRaspberrySensorData m3 = new ConvertRaspberrySensorData();
              Model model = m3.convertRaspberrySensorDataToRDF(senmlData, Var.RULE_M3_NEW_TYPE);
              msg = model.toString();
              System.out.println("else if: " + format + " " +msg);
           }*/
    } catch (IOException | JAXBException e) {
        // TODO Auto-generated catch block
        msg = e.getMessage();
    } // base name sensor

    return Response.status(200).entity(msg).build();
}

From source file:StringArray.java

/**
 * Make sure passed-in array contains values that are in order and without
 * duplicate values.//  ww w . j  a v a  2 s.  c o  m
 * 
 * @param list
 */
private void validateArray(String[] list) {
    if (list.length > 0) {
        String last = list[0];
        int index = 0;
        while (++index < list.length) {
            String comp = list[index];
            int diff = last.compareTo(comp);
            if (diff > 0) {
                throw new IllegalArgumentException("Array values are not ordered");
            } else if (diff < 0) {
                last = comp;
            } else {
                throw new IllegalArgumentException("Duplicate values in array");
            }
        }
    }
}

From source file:com.diversityarrays.kdxplore.curate.StatsData.java

public void sortTraitInstances() {
    Comparator<TraitInstance> comparator = new Comparator<TraitInstance>() {
        @Override//from  w w w .j av  a 2 s  . c om
        public int compare(TraitInstance t1, TraitInstance t2) {
            SimpleStatistics<?> s1 = statsByTraitInstance.get(t1);
            SimpleStatistics<?> s2 = statsByTraitInstance.get(t2);

            Boolean has1 = s1 != null && (s1.getValidCount() > 0);
            Boolean has2 = s2 != null && (s2.getValidCount() > 0);

            // Those WITH come before those WITHOUT
            int diff = has2.compareTo(has1);

            if (diff == 0) {
                String n1 = statsNameByTi.get(t1);
                String n2 = statsNameByTi.get(t2);
                diff = n1.compareTo(n2);
            }
            return diff;
        }
    };
    Collections.sort(traitInstances, comparator);
}