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.gargoylesoftware.htmlunit.BrowserVersionFeaturesTest.java

/**
 * Test of alphabetical order.//from ww w. j av a  2s  . c o m
 */
@Test
public void lexicographicOrder() {
    String lastFeatureName = null;
    for (final BrowserVersionFeatures feature : BrowserVersionFeatures.values()) {
        final String featureName = feature.name();
        if (lastFeatureName != null && featureName.compareTo(lastFeatureName) < 1) {
            fail("BrowserVersionFeatures.java: '" + featureName + "' should be before '" + lastFeatureName
                    + "'");
        }
        lastFeatureName = featureName;
    }
}

From source file:com.prowidesoftware.swift.model.SwiftBlock5.java

/**
 * Sets the block name. Will cause an exception unless setting block number to "5".
 * @param blockName the block name to set
 * @throws IllegalArgumentException if parameter blockName is not the string "5"
 * @since 5.0/* ww  w . ja  v a  2  s  .  c  om*/
 */
protected void setBlockName(final String blockName) {
    // sanity check
    Validate.notNull(blockName, "parameter 'blockName' cannot be null");
    Validate.isTrue(blockName.compareTo("5") == 0, "blockName must be string '5'");
}

From source file:ju.ehealthservice.search.Search.java

public List<String> getFileNames(int time, String field) {
    if (patientExists()) {
        long duration = 0;
        if (field.compareTo("minutes") == 0) {
            duration = time * 60 * 1000L;
        } else if (field.compareTo("hours") == 0) {
            duration = time * 60 * 60 * 1000L;
        } else if (field.compareTo("days") == 0) {
            duration = time * 24 * 60 * 60 * 1000L;
        } else if (field.compareTo("years") == 0) {
            //year calculation
            duration = time * 365 * 24 * 60 * 60 * 1000L;
        }//www  .  jav a2  s.  c o m
        Date now = new Date();
        try {
            for (File listOfFile : listOfFiles) {
                if (listOfFile.isFile()) {
                    String fileName = listOfFile.getName().split("_", 2)[1];
                    Date date = Constants.sdf.parse(fileName);
                    if (now.getTime() - date.getTime() < duration) {
                        files.add(listOfFile.getName());
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return trimFileExtension(files);
}

From source file:com.prowidesoftware.swift.model.SwiftBlock3.java

/**
 * Sets the block name. Will cause an exception unless setting block number to "3".
 * @param blockName the block name to set
 * @throws IllegalArgumentException if parameter blockName is not the string "3"
 * @since 5.0//  ww  w  .j  a  v  a2s.  co m
 */
protected void setBlockName(final String blockName) {
    // sanity check
    Validate.notNull(blockName, "parameter 'blockName' cannot be null");
    Validate.isTrue(blockName.compareTo("3") == 0, "blockName must be string '3'");
}

From source file:info.magnolia.module.admininterface.dialogs.LanguageSelect.java

/**
 * @see info.magnolia.cms.gui.dialog.DialogSelect#init(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, info.magnolia.cms.core.Content, info.magnolia.cms.core.Content)
 *//*from   www . jav  a2  s  .co  m*/
public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode,
        Content configNode) throws RepositoryException {
    super.init(request, response, websiteNode, configNode);

    List options = new ArrayList();

    Collection col = MessagesManager.getAvailableLocales();

    for (Iterator iter = col.iterator(); iter.hasNext();) {
        Locale locale = (Locale) iter.next();
        String code = locale.getLanguage();
        if (StringUtils.isNotEmpty(locale.getCountry())) {
            code += "_" + locale.getCountry(); //$NON-NLS-1$
        }
        String name = locale.getDisplayName(MgnlContext.getLocale());
        SelectOption option = new SelectOption(name, code);
        options.add(option);
    }

    // sort them
    Collections.sort(options, new Comparator() {

        public int compare(Object arg0, Object arg1) {
            try {
                String name0 = ((SelectOption) arg0).getLabel();
                String name1 = ((SelectOption) arg1).getLabel();
                return name0.compareTo(name1);
            } catch (Exception e) {
                return 0;
            }
        }
    });

    this.setOptions(options);
}

From source file:com.lillicoder.newsblurry.feeds.Feed.java

@Override
public int compareTo(IFeed another) {
    if (another == null)
        return 1;

    // Feeds should come before any feed with children.
    if (another.hasChildren())
        return 1;

    // Sort by name (alphabetical).
    String name = this.getName();
    String anotherName = another.getName();
    return name.compareTo(anotherName);
}

From source file:io.gatling.jenkins.targetenvgraphs.envgraphs.graphite.TrendGraphBuilder.java

private String gatlingRequestNameToGraphiteRequestName(String requestName) {
    if (requestName.compareTo("Global") == 0) {
        return "Global_Information";
    }//  w ww  . j  a va2 s.  c  o m
    return requestName;
}

From source file:com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList.java

public List<AgentActiveThreadCount> getAgentActiveThreadRepository() {
    // sort agentId
    agentActiveThreadRepository.sort(new Comparator<AgentActiveThreadCount>() {
        @Override/*from   w ww  .j a va 2 s. c  o m*/
        public int compare(AgentActiveThreadCount o1, AgentActiveThreadCount o2) {
            final String agentId1 = StringUtils.defaultString(o1.getAgentId(), "");
            final String agentId2 = StringUtils.defaultString(o2.getAgentId(), "");
            return agentId1.compareTo(agentId2);
        }
    });
    return agentActiveThreadRepository;
}

From source file:com.sm.query.utils.QueryUtils.java

public static boolean compare(Result left, String operator, Result right) {
    Comparator comparator = getComparator(operator);
    if (left.getType() == Type.STRING) {
        if (left.getValue() != null && right.getValue() != null) {
            String leftValue = (String) left.getValue();
            String rightValue = (String) right.getValue();
            switch (comparator) {
            case Equal:
                return leftValue.equals(rightValue);
            case NotEqual:
                return !leftValue.equals(rightValue);
            case Greater:
                return (leftValue.compareTo(rightValue) > 0);
            case GreaterEq:
                return (leftValue.compareTo(rightValue) >= 0);
            case Less:
                return (leftValue.compareTo(rightValue) < 0);
            case LessEq:
                return (leftValue.compareTo(rightValue) <= 0);
            default:
                throw new QueryException("invalid " + comparator.toString() + " for String");
            }/* ww  w .  j  a  va 2 s  . c  o m*/
        } else if (left.getValue() == null && right.getValue() == null)
            return true;
        else
            return false;
    } else if (left.getType() == Type.NULL || right.getType() == Type.NULL) {
        switch (comparator) {
        case Equal:
            return (left.getValue() == null && right.getValue() == null);
        case NotEqual:
            return !(left.getValue() == null && right.getValue() == null);
        // return false,instead of exception
        default:
            return false;
        }
    } else if (left.getType() == Type.BOOLEAN || left.getType() == Type.BOOLEANS) {
        switch (comparator) {
        case Equal:
            return ((Boolean) left.getValue()).equals(((Boolean) right.getValue()));
        case NotEqual:
            return !((Boolean) left.getValue()).equals(((Boolean) right.getValue()));
        default:
            throw new QueryException("invalid " + comparator.toString() + " for boolean");
        }
    } else {
        if (isObjectType(left.getType()))
            throw new QueryException("comparator not for " + left.getType().toString());
        else { //this is no number type
            if (determineType(left, right) == Type.LONG) {
                long lf = convertLong(left);
                long rt = convertLong(right);
                long diff = lf - rt;
                return deterMineLong(diff, comparator);
            } else {
                double lf = convertDouble(left);
                double rt = convertDouble(right);
                double diff = lf - rt;
                return deterMineDouble(diff, comparator);
            }

        }

    }
}

From source file:edu.cwru.apo.News.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.checkCredentials) {
        if (result != null) {
            String requestStatus;
            try {
                requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("valid") == 0) {
                    // put message here
                    Toast msg = Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG);
                    msg.show();/* w  ww.j  a  v a 2s . com*/
                } else {
                    Toast msg = Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                // put invalid JSON message here
                Toast msg = Toast.makeText(getApplicationContext(), "JSON Error: Invalid element",
                        Toast.LENGTH_LONG);
                msg.show();
                e.printStackTrace();
            }

        } else {
            Toast msg = Toast.makeText(getApplicationContext(), "Error: result is null", Toast.LENGTH_LONG);
            msg.show();
        }
    } else {
        Toast msg = Toast.makeText(getApplicationContext(), "Invalid method called", Toast.LENGTH_LONG);
        msg.show();
    }
}