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:gov.nih.nci.evs.browser.utils.SimpleSearchUtils.java

public static boolean searchAllSources(String source) {
    if (source != null && source.compareTo("ALL") != 0)
        return false;
    return true;/*from w w w  .  ja va 2s .  c o m*/
}

From source file:com.autburst.picture.Utilities.java

public static Comparator<String> getAlbumNameComparator() {
    return new Comparator<String>() {
        @Override//w ww .j a  v a 2 s.co  m
        public int compare(String arg0, String arg1) {
            String decodeName0 = new String(Base64.decodeBase64(arg0.getBytes()));
            String decodeName1 = new String(Base64.decodeBase64(arg1.getBytes()));
            return decodeName0.compareTo(decodeName1);
        }
    };
}

From source file:com.clustercontrol.repository.factory.NodeProperty.java

/**
 * ??ID???????<BR>// ww  w  .  java2  s. c  om
 *
 * @param facilityId ID
 * @param mode ????
 * @return 
 * @throws FacilityNotFound
 */
public static NodeInfo getProperty(String facilityId) throws FacilityNotFound {
    m_log.debug("getProperty() : facilityId = " + facilityId);

    if (facilityId == null || facilityId.compareTo("") == 0) {
        return new NodeInfo();
    }

    {
        // ?????????????????????????
        // (ConcurrentHashMap???????????????)
        ConcurrentHashMap<String, NodeInfo> cache = getCache();

        NodeInfo nodeInfo = cache.get(facilityId);
        if (nodeInfo != null) {
            if (!facilityId.equals(nodeInfo.getFacilityId())) {
                // ??????????????
                m_log.error("cache is broken." + facilityId + "," + nodeInfo.getFacilityId());
            }
            return nodeInfo;
        }
    }

    try {
        _lock.writeLock();

        ConcurrentHashMap<String, NodeInfo> cache = getCache();

        NodeInfo facilityEntity = QueryUtil.getNodePK(facilityId);
        cache.put(facilityId, facilityEntity);
        storeCache(cache);

        return facilityEntity;
    } finally {
        _lock.writeUnlock();
    }
}

From source file:com.sfs.whichdoctor.formatter.GroupFormatter.java

public static String getField(final GroupBean group, final String field, final String format) {

    String value = "";
    if (group == null || field == null) {
        return value;
    }/*from w ww .j  a v  a 2  s .c  o  m*/

    if (field.compareTo("Tags") == 0) {
        value = OutputFormatter.toTagList(group.getTags());
    }

    if (field.compareTo("GUID") == 0) {
        if (group.getGUID() > 0) {
            value = String.valueOf(group.getGUID());
        }
    }

    if (field.compareTo("GroupId") == 0) {
        if (group.getId() > 0) {
            value = String.valueOf(group.getId());
        }
    }
    if (field.compareTo("Group Name") == 0) {
        value = group.getName();
    }
    if (field.compareTo("Group Description") == 0) {
        value = StringUtils.replace(group.getDescription(), "\n", "<br />");
    }
    if (field.compareTo("Group Type") == 0) {
        value = group.getType();
    }
    if (field.compareTo("Created By") == 0) {
        value = group.getCreatedBy();
    }
    if (field.compareTo("Date Created") == 0) {
        if (group.getCreatedDate() != null) {
            value = Formatter.conventionalDate(group.getCreatedDate());
        }
    }
    if (field.compareTo("Modified By") == 0) {
        value = group.getModifiedBy();
    }
    if (field.compareTo("Date Modified") == 0) {
        if (group.getModifiedDate() != null) {
            value = Formatter.conventionalDate(group.getModifiedDate());
        }
    }
    if (value == null) {
        value = "";
    }
    return value;
}

From source file:control.Functions.java

/**
 * Returns a String denoting the range of a list of barcodes as used in QBiC
 * /*from   ww w.j a va2s. co  m*/
 * @param ids List of code strings
 * @return String denoting a range of the barcodes
 */
public static String getBarcodeRange(List<String> ids) {
    String head = getProjectPrefix(ids.get(0));
    String min = ids.get(0).substring(5, 8);
    String max = min;
    for (String id : ids) {
        String num = id.substring(5, 8);
        if (num.compareTo(min) < 0)
            min = num;
        if (num.compareTo(max) > 0)
            max = num;
    }
    return head + min + "-" + max;
}

From source file:com.streak.logging.utils.AnalysisUtility.java

public static void fetchCloudStorageUris(String bucketName, String startKey, String endKey,
        HttpRequestFactory requestFactory, List<String> urisToProcess, boolean readSchemas) throws IOException {
    String bucketUri = "http://commondatastorage.googleapis.com/" + bucketName;
    HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(bucketUri + "?marker=" + startKey));
    HttpResponse response = request.execute();

    try {/*  w  ww  .  j a va 2  s . c om*/
        Document responseDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(response.getContent());
        XPath xPath = XPathFactory.newInstance().newXPath();
        NodeList nodes = (NodeList) xPath.evaluate("//Contents/Key/text()", responseDoc,
                XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            String key = nodes.item(i).getNodeValue();
            if (key.compareTo(endKey) >= 0) {
                break;
            }
            if (key.endsWith(".schema") ^ readSchemas) {
                continue;
            }
            if (readSchemas) {
                key = key.substring(0, key.length() - ".schema".length());
            }
            urisToProcess.add("gs://" + bucketName + "/" + key);
        }
    } catch (SAXException e) {
        throw new IOException("Error parsing cloud storage response", e);
    } catch (ParserConfigurationException e) {
        throw new IOException("Error configuring cloud storage parser", e);
    } catch (XPathExpressionException e) {
        throw new IOException("Error finding keys", e);
    }
}

From source file:net.firejack.platform.service.registry.helper.PackageVersionHelper.java

public static FileInfo[] sortingByName(FileInfo[] files, boolean desc) {
    Arrays.sort(files, new Comparator() {
        public int compare(final Object o1, final Object o2) {
            String s1 = ((FileInfo) o1).getFilename().toLowerCase();
            String s2 = ((FileInfo) o2).getFilename().toLowerCase();
            return s1.compareTo(s2);
        }//from w  w  w.java 2 s.c  om
    });
    if (desc) {
        org.apache.commons.lang.ArrayUtils.reverse(files);
    }
    return files;
}

From source file:com.conversantmedia.mapreduce.tool.RunJob.java

@SuppressWarnings("unchecked")
protected static Map<String, DriverMeta> findAllDrivers(Reflections reflections) {
    Map<String, DriverMeta> idMap = new TreeMap<>(new Comparator<String>() {
        @Override/*from  w  w  w.j a va 2  s.co m*/
        public int compare(String s1, String s2) {
            return s1.compareTo(s2);
        }
    });

    for (Class<?> c : reflections.getTypesAnnotatedWith(Driver.class)) {
        Driver d = AnnotationUtils.findAnnotation(c, Driver.class);
        String version = versionForDriverClass(c, d.version());
        String driverId = d.value();
        if (StringUtils.isBlank(driverId)) {
            driverId = MaraAnnotationUtil.INSTANCE.defaultDriverIdForClass(c);
        }
        DriverMeta meta = new DriverMeta(driverId, d.description(), version, c, d.listener());
        idMap.put(driverId, meta);

        if (c.isAnnotationPresent(Hidden.class)) {
            meta.hidden = true;
        }
    }
    // Have to do this 2x - a second time for Tool
    for (Class<?> c : reflections.getTypesAnnotatedWith(Tool.class)) {
        Tool t = AnnotationUtils.findAnnotation(c, Tool.class);
        String version = versionForDriverClass(c, t.version());
        String toolId = t.value();
        if (StringUtils.isBlank(toolId)) {
            toolId = MaraAnnotationUtil.INSTANCE.defaultDriverIdForClass(c);
        }
        DriverMeta meta = new DriverMeta(toolId, t.description(), version, c, t.listener());
        idMap.put(toolId, meta);

        if (c.isAnnotationPresent(Hidden.class)) {
            meta.hidden = true;
        }
    }
    return idMap;
}

From source file:info.magnolia.cms.beans.config.Bootstrapper.java

/**
 * Repositories appears to be empty and the <code>"magnolia.bootstrap.dir</code> directory is configured in
 * web.xml. Loops over all the repositories and try to load any xml file found in a subdirectory with the same name
 * of the repository. For example the <code>config</code> repository will be initialized using all the
 * <code>*.xml</code> files found in <code>"magnolia.bootstrap.dir</code><strong>/config</strong> directory.
 * @param bootdirs bootstrap dir//from  ww  w  . java  2  s.  com
 */
protected static void bootstrapRepositories(String[] bootdirs) {

    if (log.isInfoEnabled()) {
        log.info("-----------------------------------------------------------------"); //$NON-NLS-1$
        log.info("Trying to initialize repositories from:");
        for (int i = 0; i < bootdirs.length; i++) {
            log.info(bootdirs[i]);
        }
        log.info("-----------------------------------------------------------------"); //$NON-NLS-1$
    }

    MgnlContext.setInstance(MgnlContext.getSystemContext());

    Iterator repositoryNames = ContentRepository.getAllRepositoryNames();
    while (repositoryNames.hasNext()) {
        String repository = (String) repositoryNames.next();

        Set xmlfileset = new TreeSet(new Comparator() {

            // remove file with the same name in different dirs
            public int compare(Object file1obj, Object file2obj) {
                File file1 = (File) file1obj;
                File file2 = (File) file2obj;
                String fn1 = file1.getParentFile().getName() + '/' + file1.getName();
                String fn2 = file2.getParentFile().getName() + '/' + file2.getName();
                return fn1.compareTo(fn2);
            }
        });

        for (int j = 0; j < bootdirs.length; j++) {
            String bootdir = bootdirs[j];
            File xmldir = new File(bootdir, repository);
            if (!xmldir.exists() || !xmldir.isDirectory()) {
                continue;
            }

            File[] files = xmldir.listFiles(new FilenameFilter() {

                public boolean accept(File dir, String name) {
                    return name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.ZIP)
                            || name.endsWith(DataTransporter.GZ); //$NON-NLS-1$
                }
            });

            xmlfileset.addAll(Arrays.asList(files));

        }

        if (xmlfileset.isEmpty()) {
            log.info("No bootstrap files found in directory [{}], skipping...", repository); //$NON-NLS-1$
            continue;
        }

        log.info("Trying to import content from {} files into repository [{}]", //$NON-NLS-1$
                Integer.toString(xmlfileset.size()), repository);

        File[] files = (File[]) xmlfileset.toArray(new File[xmlfileset.size()]);
        Arrays.sort(files, new Comparator() {

            public int compare(Object file1, Object file2) {
                String name1 = StringUtils.substringBeforeLast(((File) file1).getName(), "."); //$NON-NLS-1$
                String name2 = StringUtils.substringBeforeLast(((File) file2).getName(), "."); //$NON-NLS-1$
                // a simple way to detect nested nodes
                return name1.length() - name2.length();
            }
        });

        try {
            for (int k = 0; k < files.length; k++) {

                File xmlfile = files[k];
                DataTransporter.executeBootstrapImport(xmlfile, repository);
            }

        } catch (IOException ioe) {
            log.error(ioe.getMessage(), ioe);
        } catch (OutOfMemoryError e) {
            int maxMem = (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024);
            int needed = Math.max(256, maxMem + 128);
            log.error("Unable to complete bootstrapping: out of memory.\n" //$NON-NLS-1$
                    + "{} MB were not enough, try to increase the amount of memory available by adding the -Xmx{}m parameter to the server startup script.\n" //$NON-NLS-1$
                    + "You will need to completely remove the magnolia webapp before trying again", //$NON-NLS-1$
                    Integer.toString(maxMem), Integer.toString(needed));
            break;
        }

        log.info("Repository [{}] has been initialized.", repository); //$NON-NLS-1$

    }
}

From source file:com.krawler.common.util.SchedulingUtilities.java

public static String[] getCompHolidays(Connection conn, String companyId) {
    String[] holidayArr = new String[1];
    try {/*from   w w  w  .j  a  va2s. c o  m*/
        String Holidays = getCmpHolidaydays(conn, companyId);
        holidayArr[0] = "";
        if (Holidays.compareTo("{data:{}}") != 0) {
            JSONObject nmweekObj = new JSONObject(Holidays);
            holidayArr = new String[nmweekObj.getJSONArray("data").length()];
            for (int cnt = 0; cnt < nmweekObj.getJSONArray("data").length(); cnt++) {
                holidayArr[cnt] = nmweekObj.getJSONArray("data").getJSONObject(cnt).getString("holiday");
            }
        }
    } catch (JSONException ex) {
        throw ServiceException.FAILURE("projdb.getCompHolidays : " + ex.getMessage(), ex);
    } finally {
        return holidayArr;
    }
}