Example usage for org.apache.commons.lang ArrayUtils contains

List of usage examples for org.apache.commons.lang ArrayUtils contains

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils contains.

Prototype

public static boolean contains(boolean[] array, boolean valueToFind) 

Source Link

Document

Checks if the value is in the given array.

Usage

From source file:com.adobe.acs.commons.forms.helpers.impl.PostFormHelperImpl.java

/**
 * Removes unused Map entries from the provided map
 *
 * @param form/*from w w w .  j  a  v a  2s.co m*/
 * @return
 */
protected Form clean(final Form form) {
    final Map<String, String> map = form.getData();
    final Map<String, String> cleanedMap = new HashMap<String, String>();

    for (final Map.Entry<String, String> entry : map.entrySet()) {
        if (!ArrayUtils.contains(FORM_INPUTS, entry.getKey()) && StringUtils.isNotBlank(entry.getValue())) {
            cleanedMap.put(entry.getKey(), entry.getValue());
        }
    }

    return new Form(form.getName(), form.getResourcePath(), cleanedMap, form.getErrors());
}

From source file:com.linkedin.pinot.core.predicate.NoDictionaryEqualsPredicateEvaluatorsTest.java

@Test
public void testStringPredicateEvaluators() {
    String stringValue = RandomStringUtils.random(MAX_STRING_LENGTH);
    EqPredicate eqPredicate = new EqPredicate(COLUMN_NAME, Collections.singletonList(stringValue));
    PredicateEvaluator eqPredicateEvaluator = EqualsPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(eqPredicate, FieldSpec.DataType.STRING);

    NEqPredicate neqPredicate = new NEqPredicate(COLUMN_NAME, Collections.singletonList(stringValue));
    PredicateEvaluator neqPredicateEvaluator = NotEqualsPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(neqPredicate, FieldSpec.DataType.STRING);

    Assert.assertTrue(eqPredicateEvaluator.apply(stringValue));
    Assert.assertFalse(neqPredicateEvaluator.apply(stringValue));

    String[] randomStrings = new String[NUM_MULTI_VALUES];
    PredicateEvaluatorTestUtils.fillRandom(randomStrings, MAX_STRING_LENGTH);
    randomStrings[_random.nextInt(randomStrings.length)] = stringValue;

    Assert.assertTrue(eqPredicateEvaluator.apply(randomStrings));
    Assert.assertFalse(neqPredicateEvaluator.apply(randomStrings));

    for (int i = 0; i < 100; i++) {
        String random = RandomStringUtils.random(MAX_STRING_LENGTH);
        Assert.assertEquals(eqPredicateEvaluator.apply(random), (random.equals(stringValue)));
        Assert.assertEquals(neqPredicateEvaluator.apply(random), (!random.equals(stringValue)));

        PredicateEvaluatorTestUtils.fillRandom(randomStrings, MAX_STRING_LENGTH);
        Assert.assertEquals(eqPredicateEvaluator.apply(randomStrings),
                ArrayUtils.contains(randomStrings, stringValue));
        Assert.assertEquals(neqPredicateEvaluator.apply(randomStrings),
                !ArrayUtils.contains(randomStrings, stringValue));
    }//from w  w  w.j a v  a2 s  .c  o  m
}

From source file:com.dp2345.plugin.PaymentPlugin.java

/**
 * Map// ww  w  . ja  v  a 2s.c om
 * 
 * @param map
 *            Map
 * @param prefix
 *            ?
 * @param suffix
 *            ?
 * @param separator
 *            
 * @param ignoreEmptyValue
 *            
 * @param ignoreKeys
 *            Key
 * @return 
 */
protected String joinKeyValue(Map<String, Object> map, String prefix, String suffix, String separator,
        boolean ignoreEmptyValue, String... ignoreKeys) {
    List<String> list = new ArrayList<String>();
    if (map != null) {
        for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = ConvertUtils.convert(entry.getValue());
            if (StringUtils.isNotEmpty(key) && !ArrayUtils.contains(ignoreKeys, key)
                    && (!ignoreEmptyValue || StringUtils.isNotEmpty(value))) {
                list.add(key + "=" + (value != null ? value : ""));
            }
        }
    }
    return (prefix != null ? prefix : "") + StringUtils.join(list, separator) + (suffix != null ? suffix : "");
}

From source file:com.selventa.whistle.cli.Rcr.java

/**
 * Constructs the Rcr instance and validates the provided arguments
 * @param args/*w  w w  . j  av a  2 s . c o  m*/
 * @throws Exception
 */
public Rcr(String[] args) throws Exception {
    // Are they asking for help?
    if (args.length == 0 || ArrayUtils.contains(args, "-h") || ArrayUtils.contains(args, "--help")
            || ArrayUtils.contains(args, "-?")) {
        printHelp();
        System.exit(0);
    }

    // parse options
    GnuParser parser = new GnuParser();
    this.commandLine = parser.parse(getCommandLineOptions(), args);

    // setup
    try {
        setup();
    } catch (Exception e) {
        System.out.println("ERROR: Failed to set up RCR application: " + e.getMessage());
        System.exit(1);
    }

    // validate
    if (!validateOptions()) {
        System.exit(1);
    }
}

From source file:edu.cornell.med.icb.clustering.TestMCLClusterer.java

@Test
public void zeroDistanceCalculator() {
    final Clusterer clusterer = new MCLClusterer(4);
    final SimilarityDistanceCalculator distanceCalculator = new MaxLinkageDistanceCalculator() {
        public double distance(final int i, final int j) {
            return 0; // instances 0-3 belong to the same cluster
        }/*ww  w .  j a v  a  2s.  c om*/
    };

    final List<int[]> clusters = clusterer.cluster(distanceCalculator, 2);
    assertNotNull(clusters);
    assertEquals("Expected one cluster", 1, clusters.size());
    final int[] cluster = clusters.get(0);
    assertEquals("First cluster must have size 4", 4, cluster.length);
    assertTrue("Instance 0 in cluster 0", ArrayUtils.contains(cluster, 0));
    assertTrue("Instance 1 in cluster 0", ArrayUtils.contains(cluster, 1));
    assertTrue("Instance 2 in cluster 0", ArrayUtils.contains(cluster, 2));
    assertTrue("Instance 3 in cluster 0", ArrayUtils.contains(cluster, 3));
}

From source file:info.magnolia.setup.for4_5.UpdateSecurityFilterClientCallbacksConfiguration.java

private void copyRemainingProperties(InstallContext ctx, Content source, Content target,
        String... ignoredProperties) throws RepositoryException {
    final Collection<NodeData> existingProps = source.getNodeDataCollection();
    for (NodeData prop : existingProps) {
        if (ArrayUtils.contains(ignoredProperties, prop.getName())) {
            continue;
        }//from ww  w . ja v  a  2 s. c  om
        copyStringProperty(source, target, prop.getName());
    }
}

From source file:com.google.gdt.eclipse.designer.gxt.databinding.wizards.autobindings.GxtDatabindingProvider.java

private static String convertTypes(String className) {
    if (ArrayUtils.contains(new String[] { "boolean", "byte", "short", "long", "float", "double" },
            className)) {/*  w  ww . ja v a2  s  . c  o  m*/
        return StringUtils.capitalize(className);
    } else if ("char".equals(className)) {
        return "Character";
    } else if ("int".equals(className)) {
        return "Integer";
    } else if ("java.lang.String".equals(className)) {
        return "String";
    }
    return className;
}

From source file:com.athena.chameleon.engine.utils.JaxbUtilsTest.java

@Test
public void webAppFilterTest() {
    String xml = this.getClass().getResource("/files/webapp/web1.xml").getFile();
    File file = new File(xml);
    InputStream is = null;//from   ww  w. j  a  va  2 s  .  c o m

    try {
        is = new FileInputStream(file);
        int cnt = 0;
        byte[] buf = new byte[1024];

        System.out.println("==============================================================");
        System.out.println("*                  Original File Contents                    *");
        System.out.println("==============================================================");
        while ((cnt = is.read(buf)) != -1) {
            System.out.write(buf, 0, cnt);
        }

        Object obj = JaxbUtils.unmarshal(WebAppType.class.getPackage().getName(),
                this.getClass().getResource("/files/webapp/").getFile(), file.getName());

        WebAppType webApp = (WebAppType) ((JAXBElement<?>) obj).getValue();

        // webApp? <filter />, <filter-mapping />?  ?
        List<JAXBElement<?>> elementList = webApp.getDescriptionAndDisplayNameAndIcon();

        Object o = null;
        List<ParamValueType> paramList = null;
        String[] charSet = { "UTF-8", "UTF8" };
        boolean hasEncodingFilter = false;
        boolean hasUTF8EncodingFilter = false;
        FilterNameType filtername = null;

        for (JAXBElement<?> element : elementList) {
            o = element.getValue();

            if (o instanceof FilterType) {
                filtername = ((FilterType) o).getFilterName();

                paramList = ((FilterType) o).getInitParam();
                for (ParamValueType param : paramList) {
                    // init-param? param-name? encoding?  ?
                    if (param.getParamName().getValue().toLowerCase().equals("encoding")) {
                        hasEncodingFilter = true;

                        // param-value UTF-8? ?
                        if (ArrayUtils.contains(charSet, param.getParamValue().getValue().toUpperCase())) {
                            hasUTF8EncodingFilter = true;
                            break;
                        }
                    }
                }

                if (hasEncodingFilter) {
                    break;
                }
            }
        }

        // encoding filter  UTF-8? ?   filter ? filter-mapping  .
        if (hasEncodingFilter && !hasUTF8EncodingFilter) {
            JAXBElement<?> f = null;
            JAXBElement<?> fm = null;

            for (JAXBElement<?> element : elementList) {
                o = element.getValue();

                if (o instanceof FilterType) {
                    if (((FilterType) o).getFilterName().getValue().equals(filtername.getValue())) {
                        f = element;
                    }
                } else if (o instanceof FilterMappingType) {
                    if (((FilterMappingType) o).getFilterName().getValue().equals(filtername.getValue())) {
                        fm = element;
                    }
                }
            }

            webApp.getDescriptionAndDisplayNameAndIcon().remove(f);
            webApp.getDescriptionAndDisplayNameAndIcon().remove(fm);
        }

        if (!hasUTF8EncodingFilter) {
            // <filter> element 
            FilterType filter = new FilterType();

            FilterNameType filterName = new FilterNameType();
            filterName.setValue("UTF_EncodingFilter");
            filter.setFilterName(filterName);

            FullyQualifiedClassType filterClass = new FullyQualifiedClassType();
            filterClass.setValue("com.osc.filters.SetCharacterEncodingFilter");
            filter.setFilterClass(filterClass);

            // <init-param> element 
            ParamValueType paramValue = new ParamValueType();
            com.athena.chameleon.engine.entity.xml.webapp.v2_5.String strName = new com.athena.chameleon.engine.entity.xml.webapp.v2_5.String();
            strName.setValue("encoding");
            XsdStringType strValue = new XsdStringType();
            strValue.setValue("UTF-8");
            paramValue.setParamName(strName);
            paramValue.setParamValue(strValue);

            filter.getInitParam().add(paramValue);

            paramValue = new ParamValueType();
            strName = new com.athena.chameleon.engine.entity.xml.webapp.v2_5.String();
            strName.setValue("forceEncoding");
            strValue = new XsdStringType();
            strValue.setValue("UTF-8");
            paramValue.setParamName(strName);
            paramValue.setParamValue(strValue);

            filter.getInitParam().add(paramValue);

            // <filter-mapping> elemnet 
            FilterMappingType filterMapping = new FilterMappingType();
            com.athena.chameleon.engine.entity.xml.webapp.v2_5.UrlPatternType urlPattern = new com.athena.chameleon.engine.entity.xml.webapp.v2_5.UrlPatternType();
            urlPattern.setValue("/*");
            filterMapping.getUrlPatternOrServletName().add(urlPattern);
            filterMapping.setFilterName(filterName);

            // <web-app>? filter 
            ObjectFactory factory = new ObjectFactory();
            webApp.getDescriptionAndDisplayNameAndIcon().add(factory.createWebAppTypeFilter(filter));
            webApp.getDescriptionAndDisplayNameAndIcon()
                    .add(factory.createWebAppTypeFilterMapping(filterMapping));
        }

        String xmlData = JaxbUtils.marshal(WebAppType.class.getPackage().getName(), obj, new String[] {
                "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" });

        System.out.println("\n\n==============================================================");
        System.out.println("*                  Modified File Contents                    *");
        System.out.println("==============================================================");
        System.out.println(xmlData);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Error");
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
            fail("Error");
        }
    }
}

From source file:com.flexive.core.storage.genericSQL.GenericSQLFulltextIndexer.java

/**
 * {@inheritDoc}//from w  ww . ja va2s .c o m
 */
@Override
public void index(FxDelta.FxDeltaChange change) {
    initStatements();
    if (pk == null || psi == null || psu == null || psd == null || psd_all == null) {
        LOG.warn("Tried to index FxDeltaChange with no pk provided!");
        return;
    }
    if (change.isGroup())
        return; //only index properties
    try {
        FxProperty prop = change.getNewData() != null
                ? ((FxPropertyAssignment) change.getNewData().getAssignment()).getProperty()
                : ((FxPropertyAssignment) change.getOriginalData().getAssignment()).getProperty();
        if (!prop.getDataType().isTextType())
            return; //make sure only text types are fulltext indexed
        if (!prop.isFulltextIndexed()) {
            return; // respect fulltext flag for updates
        }
    } catch (Exception e) {
        //could not get the property, return
        LOG.error("Could not retrieve the used FxProperty for change " + change + "!");
        return;
    }
    if (change.getNewData() == null) {
        //data removed
        try {
            psd_all.setLong(3, change.getOriginalData().getAssignmentId());
            psd_all.executeUpdate();
        } catch (SQLException e) {
            LOG.error(e);
        }
        return;
    }

    if (change.getOriginalData() == null) {
        //add
        index((FxPropertyData) change.getNewData());
        return;
    }

    //update, try to update and if not found insert
    try {
        final String xmult = StringUtils.join(ArrayUtils.toObject(change.getNewData().getIndices()), ',');
        psu.setLong(5, change.getNewData().getAssignmentId());
        psu.setString(6, xmult);
        psi.setLong(4, change.getNewData().getAssignmentId());
        psi.setString(5, xmult);
        FxValue value = ((FxPropertyData) change.getNewData()).getValue();
        String data;
        long[] newLang = value.getTranslatedLanguages();
        for (long lang : newLang) {
            try {
                if (value instanceof FxBinary)
                    data = prepare(FxXMLUtils
                            .getElementData(((FxBinary) value).getTranslation(lang).getMetadata(), "text"));
                else
                    data = prepare(String.valueOf(value.getTranslation(lang)));
            } catch (Exception e) {
                LOG.error("Failed to fetch indexing data for " + change);
                continue;
            }
            if (data.length() == 0)
                continue;
            psu.setString(1, data);
            psu.setLong(4, lang);
            if (psu.executeUpdate() == 0) {
                psi.setLong(3, lang);
                psi.setString(6, data);
                psi.executeUpdate();
            }
        }
        for (long lang : ((FxPropertyData) change.getOriginalData()).getValue().getTranslatedLanguages()) {
            if (!ArrayUtils.contains(newLang, lang)) {
                //delete lang entry
                psd.setLong(3, change.getOriginalData().getAssignmentId());
                psd.setLong(4, lang);
                psd.executeUpdate();
            }
        }
    } catch (SQLException e) {
        LOG.error(e);
    }
}

From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImplTest.java

@Test
public void testGetSuccessJSON() throws Exception {

    final String actual = packageHelper.getSuccessJSON(packageOne);

    final JSONObject json = new JSONObject(actual);

    assertEquals("success", json.getString("status"));
    assertEquals("/etc/packages/testGroup/testPackageName-1.0.0.zip", json.getString("path"));

    final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };

    JSONArray actualArray = json.getJSONArray("filterSets");
    for (int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }//from w  w w  .  j  av a2s.  c  o m

    assertEquals(expectedFilterSets.length, actualArray.length());
}