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:org.eclipse.swt.examples.graphics.CustomFontTab.java

public CustomFontTab(GraphicsExample example) {
    super(example);

    // create list of fonts for this platform
    FontData[] fontData = Display.getCurrent().getFontList(null, true);
    fontNames = new ArrayList<>();
    for (FontData element : fontData) {
        // remove duplicates and sort
        String nextName = element.getName();
        if (!fontNames.contains(nextName)) {
            int j = 0;
            while (j < fontNames.size() && nextName.compareTo(fontNames.get(j)) > 0) {
                j++;// w w  w.  ja va2  s .c o  m
            }
            fontNames.add(j, nextName);
        }
    }
    fontStyles = new String[] { GraphicsExample.getResourceString("Regular"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Italic"), //$NON-NLS-1$
            GraphicsExample.getResourceString("Bold"), //$NON-NLS-1$
            GraphicsExample.getResourceString("BoldItalic") //$NON-NLS-1$
    };
    styleValues = new int[] { SWT.NORMAL, SWT.ITALIC, SWT.BOLD, SWT.BOLD | SWT.ITALIC };
}

From source file:com.gamewin.weixin.web.api.ApiListController.java

/**
 * ?URL// w ww.ja v  a 2s  . c  om
 * 
 * @author morning
 * @date 2015217 ?10:53:07
 * @param request
 * @param response
 * @return String
 */
private String access(HttpServletRequest request, HttpServletResponse response) {
    // ?URL
    System.out.println("?access");
    String signature = request.getParameter("signature");// ??
    String timestamp = request.getParameter("timestamp");// 
    String nonce = request.getParameter("nonce");// ?
    String echostr = request.getParameter("echostr");// ?
    List<String> params = new ArrayList<String>();
    params.add(Token);
    params.add(timestamp);
    params.add(nonce);
    // 1. token?timestamp?nonce???
    Collections.sort(params, new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    // 2. ??sha1
    String temp = SHA1.encode(params.get(0) + params.get(1) + params.get(2));
    if (temp.equals(signature)) {
        try {
            response.getWriter().write(echostr);
            System.out.println("? echostr" + echostr);
            return echostr;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.out.println(" ?");
    return null;
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9MeasurementRepo.java

private List<Measurements> measurementsList(Series series, List<String> groupBy, String offsetStr, int limit) {
    List<Measurements> measurementsList = new LinkedList<>();

    if (!series.isEmpty()) {

        int offsetId = 0;
        String offsetTimestamp = "1970-01-01T00:00:00.000Z";

        if (offsetStr != null) {
            List<String> offsets = influxV9Utils.parseMultiOffset(offsetStr);
            if (offsets.size() > 1) {
                offsetId = Integer.parseInt(offsets.get(0));
                offsetTimestamp = offsets.get(1);
            } else {
                offsetId = 0;/*  w ww. ja  va2 s. com*/
                offsetTimestamp = offsets.get(0);
            }
        }

        int remaining_limit = limit;
        int index = 0;
        for (Serie serie : series.getSeries()) {
            if (index < offsetId || remaining_limit <= 0) {
                index++;
                continue;
            }

            Measurements lastMeasurements = null;
            Measurements measurements = null;

            if (!groupBy.isEmpty()) {
                Map<String, String> dimensions = influxV9Utils
                        .filterGroupByTags(influxV9Utils.filterPrivateTags(serie.getTags()), groupBy);

                lastMeasurements = measurementsList.size() > 0
                        ? measurementsList.get(measurementsList.size() - 1)
                        : null;

                if (lastMeasurements != null && lastMeasurements.getDimensions().equals(dimensions))
                    measurements = measurementsList.get(measurementsList.size() - 1);

            }

            if (measurements == null) {
                measurements = new Measurements(serie.getName(),
                        influxV9Utils.filterPrivateTags(serie.getTags()));

                measurements.setId(Integer.toString(index));
            }

            for (String[] values : serie.getValues()) {
                if (remaining_limit <= 0) {
                    break;
                }

                final String timestamp = influxV9Utils.threeDigitMillisTimestamp(values[0]);
                if (timestamp.compareTo(offsetTimestamp) > 0 || index > offsetId) {
                    measurements.addMeasurement(
                            Arrays.asList(timestamp, Double.parseDouble(values[1]), getValueMeta(values)));
                    remaining_limit--;
                }
            }

            if (measurements != lastMeasurements && measurements.getMeasurements().size() > 0) {
                measurementsList.add(measurements);
            }
            index++;
        }
    }

    return measurementsList;

}

From source file:com.orange.oidc.secproxy_service.Token.java

void setField(String name, Object object) {
    if (name == null || name.length() == 0)
        return;/*from   w w w  .  j a v  a 2 s .c  om*/

    if (name.compareTo("iss") == 0) {
        iss = (String) object;
    } else if (name.compareTo("sub") == 0) {
        sub = (String) object;
    } else if (name.compareTo("aud") == 0) {
        JSONArray jArray = (JSONArray) object;
        aud = "";
        for (int i = 0; i < jArray.length(); i++) {
            try {
                aud += jArray.getString(i) + " ";
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (name.compareTo("jti") == 0) {
        jti = (String) object;
    } else if (name.compareTo("exp") == 0) {
        exp = getIntAsString(object);
    } else if (name.compareTo("iat") == 0) {
        iat = getIntAsString(object);
    } else if (name.compareTo("auth_time") == 0) {
        auth_time = getIntAsString(object);
    } else if (name.compareTo("nonce") == 0) {
        nonce = (String) object;
    } else if (name.compareTo("at_hash") == 0) {
        at_hash = (String) object;
    } else if (name.compareTo("acr") == 0) {
        acr = (String) object;
    } else if (name.compareTo("amr") == 0) {
        amr = (String) object;
    } else if (name.compareTo("azp") == 0) {
        azp = (String) object;
    } else if (name.compareTo("tim_app_key") == 0) {
        tak = (String) object;
    }
}

From source file:Person.java

public int compare(Object person, Object anotherPerson) {
    String lastName1 = ((Person) person).getLastName().toUpperCase();
    String firstName1 = ((Person) person).getFirstName().toUpperCase();
    String lastName2 = ((Person) anotherPerson).getLastName().toUpperCase();
    String firstName2 = ((Person) anotherPerson).getFirstName().toUpperCase();

    if (lastName1.equals(lastName2)) {
        return firstName1.compareTo(firstName2);
    } else {/*from   w ww.  j  a v a2s  .c om*/
        return lastName1.compareTo(lastName2);
    }
}

From source file:org.nekorp.workflow.desktop.servicio.imp.CobranzaMetadataCalculatorImp.java

private void calculaWanrLevel(String status, MonedaVB saldo, CobranzaMetadata cobranzaMetadata,
        DatosCobranzaVB cobranza) {/*  w  ww  .  j a  v a 2 s. c o  m*/
    CobranzaWarningLevel warningLevel = CobranzaWarningLevel.info;
    if (saldo.doubleValue() <= 0 || status.compareTo("Terminado") == 0) {
        cobranzaMetadata.setWarningLevel(warningLevel);
        cobranzaMetadata.setDiasUltimoPago(0);
        return;
    }
    DateTime ultimoPago = new DateTime(cobranza.getInicio());
    for (PagoCobranzaVB pago : cobranza.getPagos()) {
        DateTime fechaPago = new DateTime(pago.getFecha());
        if (ultimoPago.isBefore(fechaPago)) {
            ultimoPago = fechaPago;
        }
    }
    if (ultimoPago.plusDays(diasWarn).isBeforeNow()) {
        warningLevel = CobranzaWarningLevel.warn;
    }
    if (ultimoPago.plusDays(diasUrgent).isBeforeNow()) {
        warningLevel = CobranzaWarningLevel.urgent;
    }
    int dias = Days.daysBetween(ultimoPago.toLocalDate(), DateTime.now().toLocalDate()).getDays();
    cobranzaMetadata.setDiasUltimoPago(dias);
    cobranzaMetadata.setWarningLevel(warningLevel);
}

From source file:com.trellmor.berrytube.ChatMessage.java

/**
 * Constructs a <code>ChatMessage</code> from an <code>JSONObject</code>
 * /*  www.ja va2 s . c om*/
 * @param message
 *            <code>JSONObject<code> containing all the required fields to form a chat message
 * @throws JSONException
 */
public ChatMessage(JSONObject message) throws JSONException {
    mNick = message.getString("nick");
    mMsg = message.getString("msg");
    mMulti = message.getInt("multi");
    mType = message.getInt("type");

    // check emote
    if (message.has("emote") && message.get("emote") instanceof String) {
        String emote = message.getString("emote");
        if (emote.compareTo("rcv") == 0)
            this.mEmote = EMOTE_RCV;
        else if (emote.compareTo("sweetiebot") == 0)
            this.mEmote = EMOTE_SWEETIEBOT;
        else if (emote.compareTo("spoiler") == 0)
            this.mEmote = EMOTE_SPOILER;
        else if (emote.compareTo("act") == 0)
            this.mEmote = EMOTE_ACT;
        else if (emote.compareTo("request") == 0)
            this.mEmote = EMOTE_REQUEST;
        else if (emote.compareTo("poll") == 0)
            this.mEmote = EMOTE_POLL;
        else if (emote.compareTo("drink") == 0)
            this.mEmote = EMOTE_DRINK;
    } else
        mEmote = 0;

    JSONObject metadata = message.getJSONObject("metadata");
    mFlair = metadata.optInt("flair");
    mFlaunt = metadata.optBoolean("nameflaunt");

    try {
        this.mTimeStamp = TIMESTAMP_FORMAT.parse(message.getString("timestamp")).getTime();
    } catch (ParseException pe) {
        Log.w(TAG, "Error parsing timestamp string");
        this.mTimeStamp = System.currentTimeMillis();
    }
    this.mHidden = (this.mEmote == EMOTE_SPOILER);
}

From source file:com.activecq.tools.errorpagehandler.impl.StringLengthComparator.java

@Override
public int compare(String s1, String s2) {
    s1 = StringUtils.stripToEmpty(s1);//from   w  w  w  .j  a v  a2 s . c  om
    s2 = StringUtils.stripToEmpty(s2);

    if (s1.length() > s2.length()) {
        return -1;
    } else if (s1.length() < s2.length()) {
        return 1;
    } else {
        // Compare alphabeticaly if the same length
        return s1.compareTo(s2);
    }
}

From source file:importer.handler.post.stages.SAXSplitter.java

int compare(JSONObject a, JSONObject b) {
    String stra = (String) a.get("path");
    String strb = (String) b.get("path");
    return stra.compareTo(strb);
}

From source file:com.linkedin.helix.examples.BootstrapProcess.java

@Override
public void onReplyMessage(Message message) {
    String time = message.getResultMap().get("BOOTSTRAP_TIME");
    if (bootstrapTime == null || time.compareTo(bootstrapTime) > -1) {
        bootstrapTime = message.getResultMap().get("BOOTSTRAP_TIME");
        bootstrapUrl = message.getResultMap().get("BOOTSTRAP_URL");
    }// w  w  w .j a  v  a 2s  .  co  m
}