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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:ch.cyberduck.core.LocaleFactory.java

/**
 * @param key   English variant// w w  w  .j ava  2s.  c om
 * @param table The identifier of the table to lookup the string in. Could be a file.
 * @return Localized from table
 */
public static String localizedString(final String key, final String table) {
    final String lookup = get().localize(key, table);
    if (StringUtils.contains(lookup, "{0}")) {
        return StringUtils.replace(lookup, "'", "''");
    }
    return lookup;
}

From source file:com.yiji.openapi.sdk.util.Reflections.java

public static List<Object> invokeGetter(Object obj, String[] propertyNames) {
    List<Object> list = new ArrayList<Object>(propertyNames.length);
    for (String propertyName : propertyNames) {
        Object propertyValue = null;
        if (StringUtils.contains(propertyName, ".")) {
            String[] propertyNamePaths = StringUtils.split(propertyName, ".");
            Object temp = obj;/*from  w  w w.  j  av a  2  s  .c  om*/
            for (String propertyNamePath : propertyNamePaths) {
                if (temp == null) {
                    break;
                }
                temp = Reflections.invokeGetter(temp, propertyNamePath);
            }
            propertyValue = temp;
        } else {
            propertyValue = Reflections.invokeGetter(obj, propertyName);
        }
        list.add(propertyValue);
    }
    return list;
}

From source file:com.u2apple.rt.filter.QueryFilter.java

@Override
public List<AndroidDeviceRanking> filter(List<AndroidDeviceRanking> androidDevices) {
    List<AndroidDeviceRanking> newDevices = new ArrayList<>();
    if (isQueryValid(query)) {
        if (StringUtils.contains(query, "AND")) {
            String[] queryItems = query.split("AND");
            for (AndroidDeviceRanking device : androidDevices) {
                boolean matches = true;
                for (String queryItem : queryItems) {
                    String[] q = queryItem.split(":");
                    String key = q[0].trim();
                    String expected = q[1].trim();
                    String value = getValueByKey(device, key);
                    if (!StringUtils.equalsIgnoreCase(expected, value)) {
                        matches = false;
                    }//from www  .  j a v a 2  s  . co  m
                }
                if (matches) {
                    newDevices.add(device);
                }
            }
        } else if (StringUtils.contains(query, ":")) {
            String[] q = query.split(":");
            String key = q[0].trim();
            String expected = q[1].trim();
            for (AndroidDeviceRanking device : androidDevices) {
                String value = getValueByKey(device, key);
                if (StringUtils.equalsIgnoreCase(expected, value)) {
                    newDevices.add(device);
                }
            }
        } else {
            String[] queries = query.split("\\s");
            if (queries.length == 2) {
                String expectedBrand = queries[0];
                String expectedVid = queries[1];
                for (AndroidDeviceRanking device : androidDevices) {
                    if (StringUtils.equalsIgnoreCase(expectedBrand, device.getRoProductBrand())
                            && StringUtils.equalsIgnoreCase(expectedVid, device.getVid())) {
                        newDevices.add(device);
                    }
                }
            }
        }
    }
    return newDevices;
}

From source file:com.netflix.genie.core.jpa.specifications.JpaSpecificationUtils.java

/**
 * Create either an equals or like predicate based on the presence of the '%' character in the search value.
 *
 * @param cb         The criteria builder to use for predicate creation
 * @param expression The expression of the field the predicate is acting on
 * @param value      The value to compare the field to
 * @return A LIKE predicate if the value contains a '%' otherwise an EQUAL predicate
 *//* w ww  .  j a  v  a 2s.  co m*/
public static Predicate getStringLikeOrEqualPredicate(@NotNull final CriteriaBuilder cb,
        @NotNull final Expression<String> expression, @NotNull final String value) {
    if (StringUtils.contains(value, PERCENT)) {
        return cb.like(expression, value);
    } else {
        return cb.equal(expression, value);
    }
}

From source file:io.wcm.handler.media.MediaRequestTest.java

@Test
public void testToString() {
    MediaRequest request = new MediaRequest("/path", null);
    assertTrue(StringUtils.contains(request.toString(), "/path"));
}

From source file:com.mirth.connect.server.logging.MirthLog4jFilter.java

@Override
public int decide(LoggingEvent event) {
    // This check is done to filter out SAXParser warnings introduced in 7u40 (MIRTH-3548)
    if (event.getLevel().equals(Level.ERROR) && event.getLoggerName().equals(LOGGER_NAME)) {
        String msg = event.getRenderedMessage();

        if (StringUtils.isNotBlank(msg)) {
            if (StringUtils.equals(msg, "Compiler warnings:") || StringUtils.contains(msg,
                    "Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.")
                    || StringUtils.contains(msg,
                            "Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.")
                    || StringUtils.contains(msg,
                            "Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.")) {
                return Filter.DENY;
            }//w  ww .  j av  a2  s. co m
        }
    }

    return Filter.NEUTRAL;
}

From source file:io.wcm.handler.url.suffix.impl.IncludeResourcePartsFilter.java

@Override
public boolean includes(String suffixPart) {
    return !StringUtils.contains(suffixPart, UrlSuffixUtil.KEY_VALUE_DELIMITER);
}

From source file:com.yiji.openapi.sdk.util.BeanMapper.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<String, Object> deepMap(Object source, String[] properties) throws Exception {

    Map<String, Object> map = Maps.newHashMap();
    for (String property : properties) {
        if (StringUtils.contains(property, ".")) {
            String currentProperty = StringUtils.substringBefore(property, ".");
            String remainProperties = StringUtils.substringAfter(property, ".");
            Map<String, Object> remainMap = deepMap(BeanUtils.getDeclaredProperty(source, currentProperty),
                    new String[] { remainProperties });
            if (map.get(currentProperty) != null) {
                ((Map) map.get(currentProperty)).putAll(remainMap);
            } else {
                map.put(currentProperty, remainMap);
            }//  ww w . ja v a2s  . c o m

        } else {
            Object value = BeanUtils.getDeclaredProperty(source, property);
            if (value instanceof Collection) {

            }
            map.put(property, value);
        }
    }
    return map;
}

From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java

/**
 * Returns the URI of the given {@link Action} which must be located in the given package.
 * See {@link Context#getUri(Class)} for more information.
 *
 * @param actionBasePackage The package name which will be removed from the start of the action class name.
 *        Thereby, package names like {@code com.quartercode.femtowebtest.actions} are not included in URIs.
 * @param action The action class whose URI should be returned.
 * @return The URI the given action class is mapped to.
 *//*from  w w  w  .  ja  v a2s  .co  m*/
public static String getUri(String actionBasePackage, Class<? extends Action> action) {

    String actionFQCN = action.getName();

    // Verify that the action class is
    // - not an inner class
    // - not called "Action"
    // - ends with action
    Validate.isTrue(!StringUtils.contains(actionFQCN, '$'),
            "Action classes are not allowed to be inner classes; '%s' is therefore invalid", actionFQCN);
    Validate.isTrue(!actionFQCN.endsWith(".Action"),
            "Actions classes which are just called 'Action' are disallowed");
    Validate.isTrue(actionFQCN.endsWith("Action"),
            "Actions classes must end with 'Action'; '%s' is therefore invalid", actionFQCN);

    // Verify that the action class is inside the base package
    Validate.isTrue(actionFQCN.startsWith(actionBasePackage),
            "Cannot retrieve URI of action class '%s' because it doesn't start with the set action base package '%s'",
            actionFQCN, actionBasePackage);

    // Retrieve the name of the action class without the base package
    String actionName = actionFQCN.substring(actionBasePackage.length() + 1);

    // Replace all "." with "/", add an "/" to the front, uncapitalize the last URI part, remove "Action" from the last URI part
    // Example: "path.to.SomeTestAction" -> "/path/to/someTest")
    String[] actionNameComponents = splitAtLastSeparator(actionName, ".");
    String uriDir = actionNameComponents[0].replace('.', '/');
    String uriName = StringUtils.uncapitalize(StringUtils.removeEnd(actionNameComponents[1], "Action"));

    return "/" + joinNonBlankItems("/", uriDir, uriName);
}

From source file:com.thinkbiganalytics.metadata.core.BaseId.java

public BaseId(Serializable ser) {
    if (ser instanceof String) {
        String uuid = (String) ser;
        if (!StringUtils.contains(uuid, "-")) {
            uuid = ((String) ser).replaceFirst(
                    "([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)",
                    "$1-$2-$3-$4-$5");
        }/*from  w  w w .  jav  a 2 s  .c  o m*/
        setUuid(UUID.fromString(uuid));

    } else if (ser instanceof UUID) {
        setUuid((UUID) ser);
    } else {
        throw new IllegalArgumentException("Unknown ID value: " + ser);
    }
}