Example usage for org.apache.commons.lang3 StringUtils indexOfIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils indexOfIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils indexOfIgnoreCase.

Prototype

public static int indexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) 

Source Link

Document

Case in-sensitive find of the first index within a CharSequence.

A null CharSequence will return -1 .

Usage

From source file:com.none.tom.simplerssreader.utils.SearchUtils.java

public static LinkedHashMap<Integer, Integer> getIndicesForQuery(final String str, final String query) {
    final LinkedHashMap<Integer, Integer> indices = new LinkedHashMap<>();

    int start = StringUtils.indexOfIgnoreCase(str, query);

    indices.put(start, start + query.length());

    for (++start; (start = StringUtils.indexOfIgnoreCase(str, query, start)) > 0; start++) {
        indices.put(start, start + query.length());
    }/* w w w. ja v a 2 s .  com*/

    return indices;
}

From source file:at.bitfire.davdroid.DateUtils.java

public static String findAndroidTimezoneID(String tz) {
    String deviceTZ = null;// w w  w  .j a v a  2 s  .  co  m
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (availableTZ.equalsIgnoreCase(tz)) {
            deviceTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (deviceTZ == null) {
        Log.w(TAG, "Coulnd't find time zone with matching identifiers, trying to guess");
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tz, availableTZ) != -1) {
                deviceTZ = availableTZ;
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (deviceTZ == null) {
        final String defaultTZ = TimeZone.getDefault().getID();
        Log.e(TAG, "Couldn't identify time zone, using system default (" + defaultTZ + ") as fallback");
        deviceTZ = defaultTZ;
    }

    return deviceTZ;
}

From source file:kenh.expl.functions.IndexOf.java

public int process(String seq, String searchSeq, boolean ignoreCase) {
    if (ignoreCase)
        return StringUtils.indexOfIgnoreCase(seq, searchSeq);
    else/*from ww w .jav a2  s  . c  o  m*/
        return StringUtils.indexOf(seq, searchSeq);
}

From source file:at.bitfire.ical4android.DateUtils.java

public static String findAndroidTimezoneID(String tzID) {
    String deviceTZ = null;//from   w  w  w  . j  ava  2  s . c o  m
    String availableTZs[] = SimpleTimeZone.getAvailableIDs();

    // first, try to find an exact match (case insensitive)
    for (String availableTZ : availableTZs)
        if (availableTZ.equalsIgnoreCase(tzID)) {
            deviceTZ = availableTZ;
            break;
        }

    // if that doesn't work, try to find something else that matches
    if (deviceTZ == null) {
        for (String availableTZ : availableTZs)
            if (StringUtils.indexOfIgnoreCase(tzID, availableTZ) != -1) {
                deviceTZ = availableTZ;
                Log.w(TAG, "Couldn't find system time zone \"" + tzID + "\", assuming " + deviceTZ);
                break;
            }
    }

    // if that doesn't work, use UTC as fallback
    if (deviceTZ == null) {
        final String defaultTZ = TimeZone.getDefault().getID();
        Log.w(TAG, "Couldn't find system time zone \"" + tzID + "\", using system default (" + defaultTZ
                + ") as fallback");
        deviceTZ = defaultTZ;
    }

    return deviceTZ;
}

From source file:info.magnolia.vaadin.periscope.result.SupplierUtil.java

private static List<Integer> allIndicesOf(final String text, final String query) {
    final List<Integer> indices = new ArrayList<>();
    int index = StringUtils.indexOfIgnoreCase(text, query);
    while (index >= 0) {
        indices.add(index);//from   w ww . j a  va 2s  . co m
        index = StringUtils.indexOfIgnoreCase(text, query, index + 1);
    }
    return indices;
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.string.ApacheStringUtilsDemo.java

@Test
public void otherUtils() {
    // ignoreCase:contains/startWith/EndWith/indexOf/lastIndexOf
    assertThat(StringUtils.containsIgnoreCase("Aaabbb", "aaa")).isTrue();
    assertThat(StringUtils.indexOfIgnoreCase("Aaabbb", "aaa")).isEqualTo(0);

    // 0//from   w w w .j  a  va  2 s. com
    assertThat(StringUtils.leftPad("1", 3, '0')).isEqualTo("001");
    assertThat(StringUtils.leftPad("12", 3, '0')).isEqualTo("012");

    // ???
    assertThat(StringUtils.abbreviate("abcdefg", 7)).isEqualTo("abcdefg");
    assertThat(StringUtils.abbreviate("abcdefg", 6)).isEqualTo("abc...");

    // ?/?
    assertThat(StringUtils.capitalize("abc")).isEqualTo("Abc");
    assertThat(StringUtils.uncapitalize("Abc")).isEqualTo("abc");
}

From source file:com.yzsl.web.CommonController.java

/**
 * ??JSON???// w  w w.j  a va2s.  c  o m
 * 
 * @param object
 * @param includesProperties
 *            ??
 * @param excludesProperties
 *            ???
 */
public void writeJsonByFilter(HttpServletResponse response, Object object, String[] includesProperties,
        String[] excludesProperties) {
    try {
        FastjsonFilter filter = new FastjsonFilter();// excludesincludes
        if (excludesProperties != null && excludesProperties.length > 0) {
            filter.getExcludes().addAll(Arrays.<String>asList(excludesProperties));
        }
        if (includesProperties != null && includesProperties.length > 0) {
            filter.getIncludes().addAll(Arrays.<String>asList(includesProperties));
        }
        //logger.info("JSON?[" + excludesProperties + "]??[" + includesProperties + "]");
        String json;
        String User_Agent = getRequest().getHeader("User-Agent");
        if (StringUtils.indexOfIgnoreCase(User_Agent, "MSIE 6") > -1) {
            // SerializerFeature.BrowserCompatible?\\uXXXX??IE6
            json = JSON.toJSONString(object, filter, SerializerFeature.WriteDateUseDateFormat,
                    SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.BrowserCompatible);
        } else {
            // SerializerFeature.WriteDateUseDateFormat???yyyy-MM-dd hh24:mi:ss
            // SerializerFeature.DisableCircularReferenceDetect?
            json = JSON.toJSONString(object, filter, SerializerFeature.WriteDateUseDateFormat,
                    SerializerFeature.DisableCircularReferenceDetect);
        }
        //logger.info("??JSON" + json);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(json);
        response.getWriter().flush();
        response.getWriter().close();
        //         getResponse().setContentType("text/html;charset=utf-8");
        //         getResponse().getWriter().write(json);
        //         getResponse().getWriter().flush();
        //         getResponse().getWriter().close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.kingen.web.CommonController.java

/**
 * ??JSON???//from  w  w w  .j  a v  a2s .  c  om
 * 
 * @param object
 * @param includesProperties
 *            ??
 * @param excludesProperties
 *            ???
 */
public void writeJsonByFilter(HttpServletResponse response, Object object, String[] includesProperties,
        String[] excludesProperties) {
    try {
        FastjsonFilter filter = new FastjsonFilter();// excludesincludes
        if (excludesProperties != null && excludesProperties.length > 0) {
            filter.getExcludes().addAll(Arrays.<String>asList(excludesProperties));
        }
        if (includesProperties != null && includesProperties.length > 0) {
            filter.getIncludes().addAll(Arrays.<String>asList(includesProperties));
        }
        //logger.info("JSON?[" + excludesProperties + "]??[" + includesProperties + "]");
        String json;
        String User_Agent = getRequest().getHeader("User-Agent");
        if (StringUtils.indexOfIgnoreCase(User_Agent, "MSIE 6") > -1) {
            // SerializerFeature.BrowserCompatible?\\uXXXX??IE6
            json = JSON.toJSONString(object, filter, SerializerFeature.WriteDateUseDateFormat,
                    SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.BrowserCompatible);
        } else {
            // SerializerFeature.WriteDateUseDateFormat???yyyy-MM-dd hh24:mi:ss
            // SerializerFeature.DisableCircularReferenceDetect?
            json = JSON.toJSONString(object, filter, SerializerFeature.WriteDateUseDateFormat,
                    SerializerFeature.DisableCircularReferenceDetect);
        }
        //logger.info("??JSON" + json);
        response.setContentType("text/html;charset=utf-8");

        //         response.getWriter().write(json);
        //         response.getWriter().flush();
        //         response.getWriter().close();

        //         response.getOutputStream().write(json.getBytes());
        response.getOutputStream().write(json.getBytes("UTF-8"));
        response.getOutputStream().flush();
        response.getOutputStream().close();

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gov.va.isaac.gui.listview.operations.FindAndReplace.java

/**
 * @see gov.va.isaac.gui.listview.operations.Operation#createTask()
 *//* w w w  . ja v  a 2s  .co m*/
@Override
public CustomTask<OperationResult> createTask() {
    return new CustomTask<OperationResult>(FindAndReplace.this) {
        private Matcher matcher;

        @Override
        protected OperationResult call() throws Exception {
            double i = 0;
            successCons.clear();
            Set<SimpleDisplayConcept> modifiedConcepts = new HashSet<SimpleDisplayConcept>();
            for (SimpleDisplayConcept c : conceptList_) {
                if (cancelRequested_) {
                    return new OperationResult(FindAndReplace.this.getTitle(), cancelRequested_);
                }

                String newTxt = null;
                Set<String> successMatches = new HashSet<>();

                updateProgress(i, conceptList_.size());
                updateMessage("Processing " + c.getDescription());

                // For each concept, filter the descriptions to be changed based on user selected DescType
                ConceptVersionBI con = OTFUtility.getConceptVersion(c.getNid());
                Set<DescriptionVersionBI<?>> descsToChange = getDescsToChange(con);

                for (DescriptionVersionBI<?> desc : descsToChange) {
                    // First see if text is found in desc before moving onward
                    if (frc_.isRegExp() && hasRegExpMatch(desc) || !frc_.isRegExp() && hasGenericMatch(desc)) {

                        // Now check if language is selected, that it exists in language refset
                        if (frc_.getLanguageRefset().getNid() == 0
                                || !desc.getAnnotationsActive(OTFUtility.getViewCoordinate(),
                                        frc_.getLanguageRefset().getNid()).isEmpty()) {

                            // Replace Text
                            if (frc_.isRegExp()) {
                                newTxt = replaceRegExp();
                            } else {
                                newTxt = replaceGeneric(desc);
                            }

                            DescriptionType descType = getDescType(con, desc);
                            successMatches.add("    --> '" + desc.getText() + "' changed to '" + newTxt
                                    + "' ..... of type: " + descType);
                            updateDescription(desc, newTxt);
                        }
                    }
                }
                if (successMatches.size() > 0) {
                    modifiedConcepts.add(c);
                    successCons.put(c.getDescription() + " --- " + con.getPrimordialUuid().toString(),
                            successMatches);
                }

                updateProgress(++i, conceptList_.size());
            }

            return new OperationResult(FindAndReplace.this.getTitle(), modifiedConcepts, getMsgBuffer());
        }

        private boolean hasRegExpMatch(DescriptionVersionBI<?> desc) {
            Pattern pattern = Pattern.compile(frc_.getSearchText());

            matcher = pattern.matcher(desc.getText());

            if (matcher.find()) {
                return true;
            } else {
                return false;
            }
        }

        private String replaceRegExp() {
            // Replace all occurrences of pattern in input
            return matcher.replaceAll(frc_.getReplaceText());
        }

        private String replaceGeneric(DescriptionVersionBI<?> desc) {
            String txt = desc.getText();

            if (frc_.isCaseSens()) {
                while (txt.contains(frc_.getSearchText())) {
                    txt = txt.replace(frc_.getSearchText(), frc_.getReplaceText());
                }
            } else {
                int startIdx = StringUtils.indexOfIgnoreCase(txt, frc_.getSearchText());
                int endIdx = startIdx + frc_.getSearchText().length();

                while (startIdx >= 0) {
                    StringBuffer buf = new StringBuffer(txt);
                    buf.replace(startIdx, endIdx, frc_.getReplaceText());
                    txt = buf.toString();

                    startIdx = StringUtils.indexOfIgnoreCase(txt, frc_.getSearchText());
                }
            }

            return txt;
        }

        private boolean hasGenericMatch(DescriptionVersionBI<?> desc) {
            String txt = desc.getText();

            if (frc_.isCaseSens()) {
                if (!txt.contains(frc_.getSearchText())) {
                    return false;
                }
            } else {
                if (!StringUtils.containsIgnoreCase(txt, frc_.getSearchText())) {
                    return false;
                }
            }

            return true;
        }

        private void updateDescription(DescriptionVersionBI<?> desc, String newTxt)
                throws IOException, InvalidCAB, ContradictionException {
            DescriptionCAB dcab = desc.makeBlueprint(OTFUtility.getViewCoordinate(), IdDirective.PRESERVE,
                    RefexDirective.INCLUDE);
            dcab.setText(newTxt);
            DescriptionChronicleBI dcbi = OTFUtility.getBuilder().constructIfNotCurrent(dcab);
            ExtendedAppContext.getDataStore()
                    .addUncommitted(ExtendedAppContext.getDataStore().getConceptForNid(dcbi.getConceptNid()));
        }

        private Set<DescriptionVersionBI<?>> getDescsToChange(ConceptVersionBI con) {
            Set<DescriptionVersionBI<?>> descsToChange = new HashSet<>();

            try {
                for (DescriptionVersionBI<?> desc : con.getDescriptionsActive()) {

                    if (frc_.getSelectedDescTypes().contains(DescriptionType.FSN)
                            && con.getFullySpecifiedDescription().getNid() == desc.getNid()) {
                        descsToChange.add(desc);
                    } else if (frc_.getSelectedDescTypes().contains(DescriptionType.PT)
                            && con.getPreferredDescription().getNid() == desc.getNid()) {
                        descsToChange.add(desc);
                    } else if (frc_.getSelectedDescTypes().contains(DescriptionType.SYNONYM)
                            && con.getFullySpecifiedDescription().getNid() != desc.getNid()
                            && con.getPreferredDescription().getNid() != desc.getNid()) {
                        descsToChange.add(desc);
                    }
                }
            } catch (IOException | ContradictionException e) {
                // TODO (artf231875) Auto-generated catch block
                e.printStackTrace();
            }

            return descsToChange;
        }

        private DescriptionType getDescType(ConceptVersionBI con, DescriptionVersionBI<?> desc)
                throws IOException, ContradictionException {
            // TODO (artf231875) Auto-generated method stub
            if (con.getFullySpecifiedDescription().getNid() == desc.getNid()) {
                return DescriptionType.FSN;
            } else if (con.getPreferredDescription().getNid() == desc.getNid()) {
                return DescriptionType.PT;
            } else {
                return DescriptionType.SYNONYM;
            }
        }
    };
}

From source file:com.moviejukebox.plugin.ComingSoonPlugin.java

/**
 * Parse the search results// w  w w. ja v a  2s .co m
 *
 * Search results end with "Trovati NNN Film" (found NNN movies).
 *
 * After this string, more movie URL are found, so we have to set a boundary
 *
 * @param xml
 * @return
 */
private static List<String[]> parseComingSoonSearchResults(String xml) {
    final List<String[]> result = new ArrayList<>();

    int beginIndex = StringUtils.indexOfIgnoreCase(xml, "Trovate");
    int moviesFound = -1;
    if (beginIndex > 0) {
        int end = xml.indexOf(" film", beginIndex + 7);
        if (end > 0) {
            String tmp = HTMLTools.stripTags(xml.substring(beginIndex + 8, xml.indexOf(" film", beginIndex)));
            moviesFound = NumberUtils.toInt(tmp, -1);
        }
    }

    if (moviesFound < 0) {
        LOG.error("Couldn't find 'Trovate NNN film in archivio' string. Search page layout probably changed");
        return result;
    }

    List<String> films = HTMLTools.extractTags(xml, "box-lista-cinema", "BOX FILM RICERCA", "<a h", "</a>",
            false);
    if (CollectionUtils.isEmpty(films)) {
        return result;
    }

    LOG.debug("Search found {} movies", films.size());

    for (String film : films) {
        String comingSoonId = null;
        beginIndex = film.indexOf("ref=\"/film/");
        if (beginIndex >= 0) {
            comingSoonId = getComingSoonIdFromURL(film);
        }
        if (StringTools.isNotValidString(comingSoonId)) {
            continue;
        }

        String title = HTMLTools.extractTag(film, "<div class=\"h5 titolo cat-hover-color anim25\">", "</div>");
        if (StringTools.isNotValidString(title)) {
            continue;
        }

        String originalTitle = HTMLTools.extractTag(film, "<div class=\"h6 sottotitolo\">", "</div>");
        if (StringTools.isNotValidString(originalTitle)) {
            originalTitle = Movie.UNKNOWN;
        }
        if (originalTitle.startsWith("(")) {
            originalTitle = originalTitle.substring(1, originalTitle.length() - 1).trim();
        }

        String year = Movie.UNKNOWN;
        beginIndex = film.indexOf("ANNO</span>:");
        if (beginIndex > 0) {
            int endIndex = film.indexOf(HTML_LI, beginIndex);
            if (endIndex > 0) {
                year = film.substring(beginIndex + 12, endIndex).trim();
            }
        }

        result.add(new String[] { comingSoonId, title, originalTitle, year });
    }

    return result;
}