Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

In this page you can find the example usage for java.lang String compareToIgnoreCase.

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:org.wso2.carbon.operation.mgt.OperationAdmin.java

/**
 * return only the parameters for explicitly set for this operation
 * (not including inherited ones), where each parameter is an XML fragment
 * representing the "parameter" element//w  w w  . j  ava  2 s .c  o m
 *
 * @param serviceName
 * @param operationName
 * @return declared operation params
 * @throws AxisFault
 */
public String[] getDeclaredOperationParameters(String serviceName, String operationName) throws AxisFault {
    AxisService axisService = getAxisConfig().getServiceForActivation(serviceName);
    AxisOperation op = axisService.getOperation(new QName(operationName));

    if (op == null) {
        throw new AxisFault(
                "Invalid operation : " + operationName + " not available in service : " + serviceName);
    }

    ArrayList<String> parameters = new ArrayList<String>();
    ArrayList opParams = op.getParameters();

    for (Object opParam : opParams) {
        Parameter parameter = (Parameter) opParam;
        OMElement element = parameter.getParameterElement();
        if (element != null) {
            parameters.add(element.toString());
        }
    }

    Collections.sort(parameters, new Comparator<String>() {
        public int compare(String arg0, String arg1) {
            return arg0.compareToIgnoreCase(arg1);
        }
    });
    return parameters.toArray(new String[parameters.size()]);
}

From source file:de.hybris.platform.solrfacetsearch.integration.FacetDrillDownTest.java

private void checkOrderByManufacturerName(final Collection<ProductModel> products) {
    String previousName = "";
    for (final ProductModel product : products) {
        assertTrue(/* w w w.  j  a  v  a 2 s.com*/
                String.format("Products not sorted by 'manufacturerName'. '%s' should come before '%s' ",
                        previousName, product.getManufacturerName()),
                previousName.compareToIgnoreCase(product.getManufacturerName()) <= 0);
        previousName = product.getManufacturerName();
    }
}

From source file:com.dianping.resource.io.util.MimeType.java

/**
 * Compares this {@code MediaType} to another alphabetically.
 * @param other media type to compare to
 * @see MimeTypeUtils#sortBySpecificity(java.util.List)
 */// w  ww. ja v  a2 s. c  o m
@Override
public int compareTo(MimeType other) {
    int comp = getType().compareToIgnoreCase(other.getType());
    if (comp != 0) {
        return comp;
    }
    comp = getSubtype().compareToIgnoreCase(other.getSubtype());
    if (comp != 0) {
        return comp;
    }
    comp = getParameters().size() - other.getParameters().size();
    if (comp != 0) {
        return comp;
    }
    TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    thisAttributes.addAll(getParameters().keySet());
    TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    otherAttributes.addAll(other.getParameters().keySet());
    Iterator<String> thisAttributesIterator = thisAttributes.iterator();
    Iterator<String> otherAttributesIterator = otherAttributes.iterator();
    while (thisAttributesIterator.hasNext()) {
        String thisAttribute = thisAttributesIterator.next();
        String otherAttribute = otherAttributesIterator.next();
        comp = thisAttribute.compareToIgnoreCase(otherAttribute);
        if (comp != 0) {
            return comp;
        }
        String thisValue = getParameters().get(thisAttribute);
        String otherValue = other.getParameters().get(otherAttribute);
        if (otherValue == null) {
            otherValue = "";
        }
        comp = thisValue.compareTo(otherValue);
        if (comp != 0) {
            return comp;
        }
    }
    return 0;
}

From source file:com.karthikb351.vitinfo2.fragment.schedule.ScheduleListAdapter.java

private String formatTime(String time) {

    String AMPM = time.substring(time.length() - 2);
    String timeHeader = time.substring(0, time.length() - 3);

    if (timeHeader.length() == 4) {
        timeHeader = "0" + timeHeader;
    }//  w w w .  j  a va 2 s. c o m
    String hour = timeHeader.substring(0, 2);
    String minutes = timeHeader.substring(3, 5);

    int hr = Integer.parseInt(hour);
    int mins = Integer.parseInt(minutes);

    if (AMPM.compareToIgnoreCase("PM") == 0 && hr != 12) {
        hr += 12;
    } else if (AMPM.compareToIgnoreCase("AM") == 0 && hr == 12) {
        hr = 0;
    }

    if (mins == 0) {
        if (hr != 0) {
            hr--;
        }
        mins = 50;
    }

    time = hr + ":" + mins;

    if (time.length() == 4) {
        time = "0" + time;
    }

    return time;
}

From source file:com.swordlord.gozer.databinding.DataBindingManager.java

public DataRowBase getResolvedRow(LinkedList<DataBindingElement> elements, String strTableName,
        DataRowBase rowFather) {//from  w  ww .j a va  2s  .com
    if ((elements == null) || (elements.size() == 0)) {
        LOG.error("elements is empty");
    }

    int i = 0;
    boolean propertyFound = true;
    for (DataBindingElement element : elements) {
        i++;
        if (!element.isField() && i < elements.size()) {
            String strPathElement = element.getPathElement();

            // ignore the same level
            if (strPathElement.compareToIgnoreCase(strTableName) != 0) {
                Object property = rowFather.getProperty(strPathElement);

                if (property == null) {
                    // continuous with next
                    propertyFound = false;
                } else {
                    propertyFound = true;
                    if (property instanceof DataRowBase) {
                        rowFather = (DataRowBase) property;
                    } else if (property instanceof ToManyList) {
                        ToManyList list = (ToManyList) property;
                        if (list.size() > 0) {
                            rowFather = (DataRowBase) list.get(element.getRowNumber());
                        }
                    }
                }
                // this is some nice side effect where we just loop as long
                // as we
                // are not at the right level
            }
        }
    }

    if (propertyFound)
        return rowFather;
    else
        return null;

}

From source file:edu.ucuenca.authorsrelatedness.Distance.java

private double NGD(String a, String b) throws IOException, SQLException {

    a = a.trim();/*from  w  ww .ja v a 2  s .  co m*/
    b = b.trim();

    if (a.compareToIgnoreCase(b) == 0) {
        return 0;
    }

    //double n0 = getResultsCount(""+a+"");
    //double n1 = getResultsCount(""+b+"");
    //String c = ""+a+" "+b+"";
    String _a = "\"" + a + "\"~10";
    String _b = "\"" + b + "\"~10";
    String c = "\"" + a + " " + b + "\"~50";
    if (Cache.getInstance().config.get("relaxMode").getAsBoolean().value()) {
        _a = "" + a;
        _b = "" + b;
        c = a + " " + b;
    }

    double n0 = getResultsCount(_a);
    double n1 = getResultsCount(_b);
    double n2 = 0;

    if (n0 == 0 || n1 == 0) {
        n2 = 0;
    } else {
        n2 = getResultsCount(c);
    }

    //double m = 5026040.0 * 590;

    double m = getResultsCount("the");

    double distance = 0;

    int Measure = 0;

    double l1 = Math.max(Math.log10(n0), Math.log10(n1)) - Math.log10(n2);
    double l2 = Math.log10(m) - Math.min(Math.log10(n0), Math.log10(n1));

    if (Measure == 0) {
        distance = l1 / l2;
    }

    if (Measure == 1) {
        distance = 1 - (Math.log10(n2) / Math.log10(n0 + n1 - n2));
    }

    if (n0 == 0 || n1 == 0 || n2 == 0) {
        distance = 1;
    }

    //System.out.println("n0="+n0);
    //System.out.println("n1="+n1);
    //System.out.println("n2="+n2);
    //System.out.println(a + "," + b + "=" + distance2);
    return distance;
}

From source file:org.eclipse.ecr.runtime.osgi.OSGiRuntimeService.java

@Override
public void reloadProperties() throws Exception {
    File dir = Environment.getDefault().getConfig();
    String[] names = dir.list();// w w w. j a va  2 s . c  o  m
    if (names != null) {
        Arrays.sort(names, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareToIgnoreCase(o2);
            }
        });
        Properties props = new Properties();
        for (String name : names) {
            if (name.endsWith(".config") || name.endsWith(".ini") || name.endsWith(".properties")) {
                FileInputStream in = new FileInputStream(new File(dir, name));
                try {
                    props.load(in);
                } finally {
                    in.close();
                }

            }
        }
        // replace the current runtime properties
        properties = props;
    }
}

From source file:com.sfs.whichdoctor.dao.ItemDAOImpl.java

/**
 * Update indexes.//from   ww  w  .  ja  v a2s  .  c om
 *
 * @param object2GUID the object2 guid
 * @param itemType the item type
 */
private void updateIndexes(final int object2GUID, final String itemType) {

    dataLogger.debug("Updating search indexes for an item of type: " + itemType);

    if (itemType.compareToIgnoreCase("Employee") == 0 || itemType.compareToIgnoreCase("Employer") == 0
            || itemType.compareToIgnoreCase("Employment") == 0) {

        try {
            this.personDAO.updateRegion(object2GUID);
        } catch (Exception e) {
            dataLogger.error("Error updating region for person (" + object2GUID + "): " + e.getMessage());
        }
    }
}

From source file:org.wso2.carbon.governance.api.endpoints.EndpointManager.java

/**
 * Finds all Endpoint artifacts on the registry.
 *
 * @return all Endpoint artifacts on the registry.
 * @throws GovernanceException if the operation failed.
 *///w  w  w . j a  v a2s .c o  m
public Endpoint[] getAllEndpoints() throws GovernanceException {
    List<String> endpointPaths = Arrays
            .asList(GovernanceUtils.getResultPaths(registry, GovernanceConstants.ENDPOINT_MEDIA_TYPE));
    Collections.sort(endpointPaths, new Comparator<String>() {
        public int compare(String o1, String o2) {
            // First order by name
            int result = RegistryUtils.getResourceName(o1)
                    .compareToIgnoreCase(RegistryUtils.getResourceName(o2));
            if (result != 0) {
                return result;
            }
            // Then order by namespace
            return o1.compareToIgnoreCase(o2);
        }
    });
    List<Endpoint> endpoints = new ArrayList<Endpoint>();
    for (String endpointPath : endpointPaths) {
        GovernanceArtifact artifact = GovernanceUtils.retrieveGovernanceArtifactByPath(registry, endpointPath);
        endpoints.add((Endpoint) artifact);
    }
    return endpoints.toArray(new Endpoint[endpoints.size()]);
}

From source file:org.rdv.rbnb.MetadataManager.java

/**
 * Get the metadata channel tree for the given <code>path</code>. This will
 * populate the channel map with channel objects derived from the metadata.
 * This will recursively make requests for child servers and plugins up to the
 * maximum request depth of {@value #MAX_REQUEST_DEPTH}.
 * //from  www. j a va  2  s . c o  m
 * @param sink sink the sink connection to the RBNB server
 * @param path the path for the desired metadata
 * @param channels the map to populate with channel objects
 * @param depth the depth of the request
 * @return the metadata channel tree for the given path
 * @throws SAPIException if a server error occurs
 * @see #MAX_REQUEST_DEPTH
 */
private ChannelTree getChannelTree(Sink sink, String path, Map<String, Channel> channels, int depth)
        throws SAPIException {
    depth++;

    ChannelTree ctree = ChannelTree.EMPTY_TREE;

    ChannelMap markerChannelMap = new ChannelMap();

    ChannelMap cmap = new ChannelMap();

    if (path == null) {
        path = "";
        cmap.Add("...");
    } else {
        cmap.Add(path + "/...");
    }

    sink.RequestRegistration(cmap);

    cmap = sink.Fetch(FETCH_TIMEOUT, cmap);

    if (cmap.GetIfFetchTimedOut()) {
        log.error("Failed to get metadata.  Fetch timed out.");
        return ctree;
    }

    ctree = ChannelTree.createFromChannelMap(cmap);

    //store user metadata in channel objects
    String[] channelList = cmap.GetChannelList();
    for (int i = 0; i < channelList.length; i++) {
        int channelIndex = cmap.GetIndex(channelList[i]);
        if (channelIndex != -1) {
            ChannelTree.Node node = ctree.findNode(channelList[i]);
            String userMetadata = cmap.GetUserInfo(channelIndex);
            Channel channel = new RBNBChannel(node, userMetadata);
            channels.put(channelList[i], channel);

            //look for marker channels
            String mimeType = channel.getMetadata("mime");
            if (mimeType != null && mimeType.compareToIgnoreCase(EventMarker.MIME_TYPE) == 0) {
                markerChannelMap.Add(node.getFullName());
            }
        }
    }

    Iterator<?> it = ctree.iterator();
    while (it.hasNext()) {
        ChannelTree.Node node = (ChannelTree.Node) it.next();
        NodeTypeEnum type = node.getType();

        // look for child servers or plugins and get their channels      
        if ((type == ChannelTree.SERVER || type == ChannelTree.PLUGIN) && !path.startsWith(node.getFullName())
                && depth < MAX_REQUEST_DEPTH) {
            ChannelTree childChannelTree = getChannelTree(sink, node.getFullName(), channels, depth);
            ctree = childChannelTree.merge(ctree);
        }
    }

    if (markerChannelMap.NumberOfChannels() > 0) {
        double markersDuration = System.currentTimeMillis() / 1000d;

        //request from start of marker channels to now
        sink.Request(markerChannelMap, 0, markersDuration, "absolute");

        markerChannelMap = sink.Fetch(FETCH_TIMEOUT, markerChannelMap);
        if (!markerChannelMap.GetIfFetchTimedOut()) {
            //notify marker listeners
            fireMarkersUpdated(markerChannelMap);
        } else {
            log.error("Failed to get event markers. Fetched timed out.");
        }
    }

    return ctree;
}