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:com.clustercontrol.accesscontrol.factory.RoleSelector.java

/**
 * ????<BR>//from  w  w  w . j a  v a2 s  .  c  o  m
 * 
 * @param objectType
 * @param objectId
 * @param roleId
 * @param objectPrivilege
 * @return ?
 * @throws HinemosUnknown
 */
public static ObjectPrivilegeInfo getObjectPrivilegeInfo(String objectType, String objectId, String roleId,
        String objectPrivilege) throws HinemosUnknown {

    ObjectPrivilegeInfo info = null;

    if (objectType != null && objectType.compareTo("") != 0 && objectId != null && objectId.compareTo("") != 0
            && roleId != null && roleId.compareTo("") != 0 && objectPrivilege != null
            && objectPrivilege.compareTo("") != 0) {
        try {
            // ??
            info = QueryUtil.getObjectPrivilegePK(objectType, objectId, roleId, objectPrivilege);
        } catch (PrivilegeNotFound e) {
            // ???
        } catch (Exception e) {
            m_log.warn("getRoleInfo() failure to get user. : userId = " + roleId, e);
            throw new HinemosUnknown(e.getMessage() + " : failure to get role.", e);
        }
    }
    return info;
}

From source file:com.envision.envservice.common.util.UserUtil.java

public static void sortByName(List<UserBo> users) {
    Collections.sort(users, new Comparator<UserBo>() {

        @Override//from  w ww  .ja  v  a  2  s  .c o m
        public int compare(UserBo u1, UserBo u2) {
            if (StringUtils.isEmpty(u1.getName())) {
                return 1;
            }
            if (StringUtils.isEmpty(u2.getName())) {
                return -1;
            }

            String u1Name = u1.getName();
            if (u1Name.contains(".")) {
                String[] names = u1Name.split("\\.");
                u1Name = names[1] + names[0];
            }

            String u2Name = u2.getName();
            if (u2Name.contains(".")) {
                String[] names = u2Name.split("\\.");
                u2Name = names[1] + names[0];
            }

            return u1Name.compareTo(u2Name);
        }
    });
}

From source file:com.github.sdbg.debug.core.internal.webkit.protocol.ChromiumTabInfo.java

static Comparator<ChromiumTabInfo> getComparator() {
    return new Comparator<ChromiumTabInfo>() {
        @Override//from www . j  ava  2 s  . c o m
        public int compare(ChromiumTabInfo o1, ChromiumTabInfo o2) {
            // Sort by the tab order.
            String url1 = o1.getWebSocketDebuggerUrl();
            String url2 = o2.getWebSocketDebuggerUrl();

            if (url1 == url2) {
                return 0;
            } else if (url1 == null) {
                return -1;
            } else if (url2 == null) {
                return 1;
            } else {
                return url1.compareTo(url2);
            }
        }
    };
}

From source file:com.clevertrail.mobile.viewtrail.Object_TrailArticle.java

public static void createFromJSON(String name, JSONObject json) {

    try {/*from  ww w. ja  v a2 s.  c o  m*/
        if (json != null) {
            //clear any existing data before loading in a new trail
            Object_TrailArticle.clearData();

            jsonSaved = json;
            sName = name;

            // get the referenced photos
            arPhotos = new ArrayList();
            JSONArray arRP = json.getJSONArray("referencedphotos");
            for (int i = 0; i < arRP.length(); i++) {
                JSONArray arJSONPhoto = arRP.getJSONArray(i);
                if (arJSONPhoto.length() >= 2) {
                    Object_TrailPhoto photo = new Object_TrailPhoto();
                    photo.mURL = arJSONPhoto.getString(0);
                    photo.mURL120px = arJSONPhoto.getString(1);
                    photo.mCaption = Object_TrailArticle.urlDecode(arJSONPhoto.getString(2));
                    photo.mSection = arJSONPhoto.getString(3);
                    arPhotos.add(photo);
                }
            }

            // get the gallery photos
            arRP = json.getJSONArray("galleryphotos");
            for (int i = 0; i < arRP.length(); i++) {
                JSONArray arJSONPhoto = arRP.getJSONArray(i);
                if (arJSONPhoto.length() >= 2) {
                    Object_TrailPhoto photo = new Object_TrailPhoto();
                    photo.mURL = arJSONPhoto.getString(0);
                    photo.mURL120px = arJSONPhoto.getString(1);
                    photo.mCaption = "";
                    photo.mSection = "";
                    arPhotos.add(photo);
                }
            }

            //load all the data from the sections
            Object_TrailArticle.sOverview = Object_TrailArticle.urlDecode(json.getString("overview"));
            Object_TrailArticle.sDirections = Object_TrailArticle.urlDecode(json.getString("directions"));
            Object_TrailArticle.sDescription = Object_TrailArticle.urlDecode(json.getString("description"));
            Object_TrailArticle.sConditions = Object_TrailArticle.urlDecode(json.getString("conditions"));
            Object_TrailArticle.sFees = Object_TrailArticle.urlDecode(json.getString("fees"));
            Object_TrailArticle.sAmenities = Object_TrailArticle.urlDecode(json.getString("amenities"));
            Object_TrailArticle.sMisc = Object_TrailArticle.urlDecode(json.getString("misc"));

            //load all the data from the stats
            Object_TrailArticle.mImage = new Object_TrailPhoto();
            Object_TrailArticle.mImage.mURL = Object_TrailArticle.urlDecode(json.getString("image"));
            Object_TrailArticle.sImageCredit = Object_TrailArticle.urlDecode(json.getString("imagecredit"));
            Object_TrailArticle.sDifficulty = Object_TrailArticle.urlDecode(json.getString("difficulty"));
            Object_TrailArticle.sDistance = Object_TrailArticle.urlDecode(json.getString("distance"));
            Object_TrailArticle.sTime = Object_TrailArticle.urlDecode(json.getString("time"));

            Object_TrailArticle.sType = Object_TrailArticle.urlDecode(json.getString("trailtype"));
            Object_TrailArticle.sElevation = Object_TrailArticle.urlDecode(json.getString("elevation"));
            Object_TrailArticle.sHighPoint = Object_TrailArticle.urlDecode(json.getString("highpoint"));
            Object_TrailArticle.sLowPoint = Object_TrailArticle.urlDecode(json.getString("lowpoint"));
            Object_TrailArticle.sBestMonth = Object_TrailArticle.urlDecode(json.getString("bestmonth"));
            Object_TrailArticle.sNearestCity = Object_TrailArticle.urlDecode(json.getString("nearestcity"));

            // in this order: hike, bicycle, handicap, swim, climb, horse,
            // camp, dog,
            // fish, family
            Object_TrailArticle.mTrailUse[0] = (json.getString("hike").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[1] = (json.getString("bicycle").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[2] = (json.getString("handicap").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[3] = (json.getString("swim").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[4] = (json.getString("climb").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[5] = (json.getString("horse").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[6] = (json.getString("camp").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[7] = (json.getString("dog").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[8] = (json.getString("fish").compareTo("1") == 0);
            Object_TrailArticle.mTrailUse[9] = (json.getString("family").compareTo("1") == 0);

            //load the map data (trailheads, pois, trail ends, zoom, center lat/lng, maptype)
            String jsonMapString = json.getString("jsonMapdata");
            if (jsonMapString.compareTo("") != 0) {
                JSONObject jsonMapData = new JSONObject(jsonMapString);

                if (jsonMapData != null) {
                    Object_TrailArticle.dCenterLat = jsonMapData.getDouble("centerLat");
                    Object_TrailArticle.dCenterLng = jsonMapData.getDouble("centerLong");
                    Object_TrailArticle.nCenterZoom = jsonMapData.getInt("zoom");
                    Object_TrailArticle.sMapType = jsonMapData.getString("mapType");

                    //load in the markers
                    JSONArray arMarkers = jsonMapData.getJSONArray("markerLats");
                    for (int i = 0; i < arMarkers.length(); i++) {
                        Object_TrailArticle.mMarkerLats[i] = arMarkers.getDouble(i);
                    }
                    arMarkers = jsonMapData.getJSONArray("markerLongs");
                    for (int i = 0; i < arMarkers.length(); i++) {
                        Object_TrailArticle.mMarkerLngs[i] = arMarkers.getDouble(i);
                    }
                    arMarkers = jsonMapData.getJSONArray("markerDescs");
                    for (int i = 0; i < arMarkers.length(); i++) {
                        Object_TrailArticle.mMarkerDescs[i] = arMarkers.getString(i);
                    }
                    arMarkers = jsonMapData.getJSONArray("markerTypes");
                    for (int i = 0; i < arMarkers.length(); i++) {
                        Object_TrailArticle.mMarkerTypes[i] = arMarkers.getString(i);
                    }
                }
            }

        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.evs.browser.utils.SimpleSearchUtils.java

public static SearchExtension.MatchAlgorithm converToMatchAlgorithm(int searchOption, String algorithm) {
    if (algorithm == null)
        return null;
    if (searchOption != BY_CODE && searchOption != BY_NAME)
        return null;
    if (searchOption == BY_NAME) {
        if (algorithm.compareTo("exactMatch") == 0) {
            return SearchExtension.MatchAlgorithm.PRESENTATION_EXACT;
        } else if (algorithm.compareTo("contains") == 0) {
            return SearchExtension.MatchAlgorithm.PRESENTATION_CONTAINS;
        } else if (algorithm.compareTo("lucene") == 0) {
            return SearchExtension.MatchAlgorithm.LUCENE;
        }//  ww w.  j a  va 2  s.c o  m
    } else if (algorithm.compareTo("exactMatch") == 0 && searchOption == BY_CODE) {
        return SearchExtension.MatchAlgorithm.CODE_EXACT;
    }
    return null;
}

From source file:com.hurence.logisland.documentation.DocGenerator.java

/**
 * Generates documentation into the work/docs dir specified from a specified set of class
 *//*from   w w w  .ja  va 2 s  .  c o  m*/
public static void generate(final File docsDirectory, final String writerType) {

    Map<String, Class> extensionClasses = new TreeMap<>();

    PluginLoader.getRegistry().forEach((className, classLoader) -> {
        try {
            extensionClasses.put(className, classLoader.loadClass(className));
        } catch (Exception e) {
            logger.error("Unable to load class " + className, e);

        }
    });

    ClassFinder.findClasses(clazz -> {
        if (!clazz.startsWith("BOOT-INF") && clazz.contains("logisland") && !clazz.contains("Mock")
                && !clazz.contains("shade")) {
            try {
                Class c = Class.forName(clazz);
                if (c.isAssignableFrom(ConfigurableComponent.class) && !Modifier.isAbstract(c.getModifiers())) {
                    extensionClasses.put(c.getSimpleName(), c);
                }
            } catch (Throwable e) {
                logger.error("Unable to load class " + clazz + " : " + e.getMessage());
            }
        }

        return true; // return false if you don't want to see any more classes
    });

    docsDirectory.mkdirs();

    // write headers for single rst file
    if (writerType.equals("rst"))

    {
        final File baseDocumenationFile = new File(docsDirectory, OUTPUT_FILE + "." + writerType);
        if (baseDocumenationFile.exists())
            baseDocumenationFile.delete();

        try (final PrintWriter writer = new PrintWriter(new FileOutputStream(baseDocumenationFile, true))) {
            writer.println("Components");
            writer.println("==========");
            writer.println(
                    "You'll find here the list of all usable Processors, Engines, Services and other components "
                            + "that can be usable out of the box in your analytics streams");
            writer.println();
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage());
        }
    } else if (writerType.equals("json"))

    {
        final File baseDocumenationFile = new File(docsDirectory, OUTPUT_FILE + "." + writerType);
        if (baseDocumenationFile.exists())
            baseDocumenationFile.delete();

        try (final PrintWriter writer = new PrintWriter(new FileOutputStream(baseDocumenationFile, true))) {
            writer.println("[");
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage());
        }
    }

    Class[] sortedExtensionsClasses = new Class[extensionClasses.size()];
    extensionClasses.values().

            toArray(sortedExtensionsClasses);

    Arrays.sort(sortedExtensionsClasses, new Comparator<Class>()

    {
        @Override
        public int compare(Class s1, Class s2) {
            // the +1 is to avoid including the '.' in the extension and to avoid exceptions
            // EDIT:
            // We first need to make sure that either both files or neither file
            // has an extension (otherwise we'll end up comparing the extension of one
            // to the start of the other, or else throwing an exception)
            final int s1Dot = s1.getName().lastIndexOf('.');
            final int s2Dot = s2.getName().lastIndexOf('.');
            if ((s1Dot == -1) == (s2Dot == -1)) { // both or neither
                String s1Name = s1.getName().substring(s1Dot + 1);
                String s2Name = s2.getName().substring(s2Dot + 1);
                return s1Name.compareTo(s2Name);
            } else if (s1Dot == -1) { // only s2 has an extension, so s1 goes first
                return -1;
            } else { // only s1 has an extension, so s1 goes second
                return 1;
            }
        }
    });

    logger.info("Generating " + writerType + " documentation for " + Arrays.stream(sortedExtensionsClasses).

            count() + " components in: " + docsDirectory);

    Arrays.stream(sortedExtensionsClasses).

            forEach(extensionClass ->

    {
                final Class componentClass = extensionClass.asSubclass(ConfigurableComponent.class);
                try {
                    document(docsDirectory, componentClass, writerType);

                } catch (Exception e) {
                    logger.error("Unexpected error for " + extensionClass, e);
                }

            });

    if (writerType.equals("json"))

    {
        final File baseDocumenationFile = new File(docsDirectory, OUTPUT_FILE + "." + writerType);
        try (final PrintWriter writer = new PrintWriter(new FileOutputStream(baseDocumenationFile, true))) {
            writer.println("]");
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage());
        }
    }

}

From source file:com.revolsys.util.JavaBeanUtil.java

public static List<Method> getMethods(final Class<?> clazz) {
    final Method[] methods = clazz.getMethods();
    Arrays.sort(methods, new Comparator<Method>() {
        @Override//w  w w.jav a  2s .  c  o  m
        public int compare(final Method method1, final Method method2) {
            final String name1 = method1.getName().replaceAll("^(set|get|is)", "").toLowerCase();
            final String name2 = method2.getName().replaceAll("^(set|get|is)", "").toLowerCase();
            final int nameCompare = name1.compareTo(name2);
            return nameCompare;
        }
    });
    return Arrays.asList(methods);
}

From source file:com.krawler.common.timezone.Timezone.java

public static String toUserDefTimezone(Connection conn, String date, String tz) throws ServiceException {
    if (tz.compareTo("") == 0)
        tz = Timezone.getSystemTimezone(conn);
    String result = "";
    String query = "select DATE_FORMAT(CONVERT_TZ('" + date + "', '+00:00' , '" + tz
            + "'),'%Y-%m-%d %H:%i:%S') " + "as time_convt; ";
    DbResults rs = DbUtil.executeQuery(conn, query);
    while (rs.next()) {
        result = rs.getString("time_convt");
    }/*from  w w w .  j a v  a 2 s  .co m*/
    return result;
}

From source file:Main.java

/**
 * Get the Card type returns the credit card type INVALID = -1; VISA = 0;
 * MASTERCARD = 1; AMERICAN_EXPRESS = 2; EN_ROUTE = 3; DINERS_CLUB = 4;
 *//*from   ww  w .  ja  v  a  2 s .  c  om*/
public static int getCardID(String number) {
    int valid = INVALID;
    String digit1 = number.substring(0, 1);
    String digit2 = number.substring(0, 2);

    if (isNumber(number)) {
        /* ----
         ** VISA  prefix=4
         ** ----  length=13 or 16
         */
        if (digit1.equals("4")) {
            if (number.length() == 13 || number.length() == 16) {
                valid = VISA;
            }
        } /* ----------
           ** MASTERCARD  prefix= 51 ... 55
           ** ----------  length= 16
           */else if (digit2.compareTo("51") >= 0 && digit2.compareTo("55") <= 0) {
            if (number.length() == 16) {
                valid = MASTERCARD;
            }
        } /* ----
           ** AMEX  prefix=34 or 37
           ** ----  length=15
          else if (digit2.equals("34") || digit2.equals("37")) {
          if (number.length() == 15) {
              valid = AMERICAN_EXPRESS;
          }
          }*/
    }
    return valid;

}

From source file:org.cocos2dx.lib.Cocos2dxBitmap.java

private static String refactorString(String str) {
    // Avoid error when content is ""
    if (str.compareTo("") == 0) {
        return " ";
    }/*  w  w w.  j  a  v a2 s. c o  m*/

    /*
     * If the font of "\n" is "" or "\n", insert " " in front of it.
     * 
     * For example:
     * "\nabc"     -> " \nabc"
     * "\nabc\n\n" -> " \nabc\n \n"
     */
    StringBuilder strBuilder = new StringBuilder(str);
    int start = 0;
    int index = strBuilder.indexOf("\n");
    while (index != -1) {
        if (index == 0 || strBuilder.charAt(index - 1) == '\n') {
            strBuilder.insert(start, " ");
            start = index + 2;
        } else {
            start = index + 1;
        }

        if (start > strBuilder.length() || index == strBuilder.length()) {
            break;
        }

        index = strBuilder.indexOf("\n", start);
    }

    return strBuilder.toString();
}