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:Main.java

/** Determines if value is a positive zero according to the IEEE754 standard
 * @param value the binary string of 64 bits
 * @return true if the value is  positive zero
 *//*from  w ww  .  j  a  v a 2 s. c om*/

public static boolean isPositiveZero(String value) {
    if (is64BinaryString(value)) {
        if (value.compareTo(PLUSZERO) == 0) {
            return true;
        }
    }

    return false;
}

From source file:com.shigengyu.hyperion.server.RestServer.java

private static Collection<ControllerMethod> extractControllerMethods(
        Iterable<ResourceProvider> resourceProviders) {

    TreeMap<String, ControllerMethod> controllerMethods = Maps.newTreeMap(new Comparator<String>() {

        @Override/*w ww.j  a v  a2s .  co m*/
        public int compare(String first, String second) {
            return first.compareTo(second);
        }
    });

    for (ResourceProvider resourceProvider : resourceProviders) {
        String controllerPath = resourceProvider.getResourceClass().getAnnotation(Path.class).value();
        for (Method method : resourceProvider.getResourceClass().getMethods()) {
            if (!method.isAnnotationPresent(Path.class)) {
                continue;
            }

            String methodPath = method.getAnnotation(Path.class).value();

            String httpMethod = null;
            if (method.isAnnotationPresent(GET.class)) {
                httpMethod = HttpMethods.GET;
            } else if (method.isAnnotationPresent(POST.class)) {
                httpMethod = HttpMethods.POST;
            }

            ControllerMethod controllerMethod = new ControllerMethod(httpMethod, controllerPath, methodPath);
            controllerMethods.put(controllerMethod.getUrl(), controllerMethod);
        }
    }

    return controllerMethods.values();
}

From source file:Main.java

/**
 * This method checks if the list contains the given string (case sensitive).
 * /*from   w ww  . java  2 s .  c om*/
 * @param list
 *          the list to check
 * @param string
 *          the string
 * @return true/false
 */
public static boolean contains(List<String> list, String string) {
    if (isNotEmpty(list)) {
        for (String item : list) {
            if ((item != null && string != null && item.compareTo(string) == 0)
                    || (item == null && string == null)) {
                return true;
            }
        }
    }
    return false;
}

From source file:PairTest1.java

/**
 * Gets the minimum and maximum of an array of strings.
 * @param a an array of strings/*from  w  w  w  .j av  a2 s .  c o  m*/
 * @return a pair with the min and max value, or null if a is null or empty
 */
public static Pair<String> minmax(String[] a) {
    if (a == null || a.length == 0)
        return null;
    String min = a[0];
    String max = a[0];
    for (int i = 1; i < a.length; i++) {
        if (min.compareTo(a[i]) > 0)
            min = a[i];
        if (max.compareTo(a[i]) < 0)
            max = a[i];
    }
    return new Pair<String>(min, max);
}

From source file:Main.java

/**
 * Loads an optional Boolean element value from a XML element
 *//*w ww. ja  v a  2  s . co m*/
public static boolean getBooleanNode(Element element, String name, boolean _default) {
    Element child = getSingleElement(element, name);

    if (child == null)
        return _default;

    String value = child.getTextContent();

    if (value == null)
        return _default;

    if (value.compareTo("S") == 0)
        return true;

    if (value.compareTo("N") == 0)
        return false;

    return _default;
}

From source file:Main.java

/**
 * Method compare./*from   ww w.  ja v  a 2s.  co  m*/
 * 
 * @param row1
 *            String
 * @param row2
 *            String
 * @param asc
 *            boolean
 * @return int
 */
private static int compare(String row1, String row2, boolean asc) {
    int result = row1.compareTo(row2);
    int returnVal = 0;

    if (result < 0) {
        returnVal = -1;
    } else if (result != 0) // result > 0
    {
        returnVal = 1;
    } else {
        returnVal = 0;
    }

    return asc ? -returnVal : returnVal;
}

From source file:Main.java

public static boolean parseXMLMessage(String msg, HashMap<String, String> strMap) {
    boolean bRet = true;

    // parse xml document.
    XmlPullParserFactory factory;/*from  w w  w  . j a v  a 2 s.  co  m*/
    XmlPullParser parser;

    try {
        factory = XmlPullParserFactory.newInstance();
        parser = factory.newPullParser();
        Stack eleStack = new Stack();
        int parserEvent;

        parser.setInput(new StringReader(msg));
        parserEvent = parser.getEventType();

        while (parserEvent != XmlPullParser.END_DOCUMENT) {
            switch (parserEvent) {
            case XmlPullParser.START_TAG:
                String newtag = parser.getName();
                if (newtag.compareTo("xml") != 0) {
                    eleStack.push(newtag);
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getName().compareTo("xml") != 0) {
                    eleStack.pop();
                }
                break;
            case XmlPullParser.TEXT:
                String tagkey = "";
                for (int i = 0; i < eleStack.size(); i++) {
                    tagkey += eleStack.elementAt(i);
                    if (i < eleStack.size() - 1)
                        tagkey += "_";
                }
                strMap.put(tagkey, parser.getText());
                break;
            default:
                break;
            }

            parserEvent = parser.next();
        }

        eleStack = null;
        parser = null;
        factory = null;
    } catch (Exception e) {
        e.printStackTrace();
        bRet = false;
    }

    return bRet;
}

From source file:fr.ribesg.bukkit.ncore.updater.FileDescription.java

public static SortedMap<String, FileDescription> parse(final String jsonString) {
    final SortedMap<String, FileDescription> result = new TreeMap<>(new Comparator<String>() {

        @Override//from  w w  w .j  a v a2s  .  co  m
        public int compare(final String a, final String b) {
            return -a.compareTo(b);
        }
    });
    final JSONArray array = (JSONArray) JSONValue.parse(jsonString);
    for (final Object o : array.toArray()) {
        final JSONObject object = (JSONObject) o;
        final String fileName = (String) object.get(FILENAME_KEY);
        final String version = VersionUtil.getVersion((String) object.get(VERSION_KEY));
        final String bukkitVersion = (String) object.get(BUKKIT_VERSION_KEY);
        final String type = (String) object.get(TYPE_KEY);
        final String link = (String) object.get(DOWNLOAD_URL_KEY);
        final FileDescription fileDescription = new FileDescription(fileName, version, link, type,
                bukkitVersion);
        if (VersionUtil.isRelease(version)) {
            result.put(version, fileDescription);
        }
    }
    return result;
}

From source file:Main.java

/**
 * Get the list of xml files in the bookmark export folder.
 * @return The list of xml files in the bookmark export folder.
 *//*from  w w w .  ja va2 s. c o  m*/
public static List<String> getExportedBookmarksFileList() {
    List<String> result = new ArrayList<String>();

    File folder = getBookmarksExportFolder();

    if (folder != null) {

        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                if ((pathname.isFile()) && (pathname.getPath().endsWith(".xml"))) {
                    return true;
                }
                return false;
            }
        };

        File[] files = folder.listFiles(filter);

        for (File file : files) {
            result.add(file.getName());
        }
    }

    Collections.sort(result, new Comparator<String>() {

        @Override
        public int compare(String arg0, String arg1) {
            return arg1.compareTo(arg0);
        }
    });

    return result;
}

From source file:Main.java

public static boolean getkeepaliveinfo() {
    String baseUrl = "http://10.6.8.2/cgi-bin/keeplive?";

    try {//w  w w.ja  v  a2s .  c o m
        HttpGet getMethod = new HttpGet(baseUrl);
        getMethod.addHeader("Accept", "*/*");
        //getMethod.addHeader("Accept-Language", "zh-cn");
        //getMethod.addHeader("Referer", "http://202.117.2.41/index.html");
        //getMethod.addHeader("Content-Type", "application/x-www-form-urlencoded");
        //getMethod.addHeader("Accept-Encoding", "gzip, deflate");
        //getMethod.addHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
        getMethod.addHeader("Host", "10.6.8.2");
        //getMethod.addHeader("DNT", "1");

        HttpClient httpClient = new DefaultHttpClient();

        HttpResponse response = httpClient.execute(getMethod);
        Log.i(TAG, "Sending message.....");
        HttpEntity httpEntity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 200) {
            String message = EntityUtils.toString(httpEntity);
            if (httpEntity == null || message.compareTo("error") == 0) {
                Log.i(TAG, "Get keepalive info failed!!!message=" + message);
                return false;
            } else {
                Log.i(TAG, "Get keepalive info succeed!!!message=" + message);
                return true;
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Log.i(TAG, "Get keepalive info failed!!!");
    return false;
}