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:gov.nih.nci.cabig.caaers.web.fields.AbstractInputField.java

@Deprecated
public void setRequired(boolean required) {
    if (!required)
        return;/*  www  .ja v a  2 s .  co  m*/
    if (!ArrayUtils.contains(validators, FieldValidator.NOT_NULL_VALIDATOR)) {
        if (validators != null && validators.length > 0) {
            FieldValidator[] oldValidators = validators;
            validators = new FieldValidator[oldValidators.length + 1];
            System.arraycopy(oldValidators, 0, validators, 1, oldValidators.length);
        } else {
            validators = new FieldValidator[1];
        }
        validators[0] = FieldValidator.NOT_NULL_VALIDATOR; // this should be the first
    }
}

From source file:net.navasoft.madcoin.backend.services.vo.request.SuccessRequestVOWrapper.java

private boolean validateProcessAnnotations(ProcessedField var, ProcessingField entry) {
    return var.expectedType().equals(entry.expectedType()) && var.precedence().equals(entry.precedence())
            && ArrayUtils.contains(var.possibleVariables(), entry.expectedVariable());
}

From source file:biz.netcentric.cq.tools.actool.configmodel.AuthorizableConfigBean.java

public boolean membersContainsAnonymous() {
    return ArrayUtils.contains(members, Constants.USER_ANONYMOUS);
}

From source file:com.pureinfo.srm.reports.table.MyTabeleDataHelper.java

/**
 * @param _contentClass content classes that take parts in do statistic; has at least 1 element 
 * @param _alias alias for content classes,the fisrt one will be set to 'this' no matter what is passed in, 
 * must have the same size as <code>_contentClass</code>
 * @param _sToCalculate to calculate what? this will be set in SELECT clause,and its value will be contained 
 * in the data map returned// w w  w  . j  a v  a  2 s .  c o  m
 * @param _condition conditions, that will be used in WHERE clause
 * @param _sGroupProp group by this
 * @param _caredValues what values are cared; if result is not in this array,it will be considered as "OTHER"
 * @return an map.contains <code>contentClass[0]._sGroupProp</code>->its result(a <code>java.lang.Number</code>)
 * @throws PureException if database access error or class metadata not found
 */
public static Map getRowMap(Class[] _contentClass, String[] _alias, String _sToCalculate,
        SQLCondition _condition, String _sGroupProp, String[] _caredValues) throws PureException {
    IContentMgr mgr = ArkContentHelper.getContentMgrOf(_contentClass[0]);
    List params = new ArrayList();
    IObjects datas = null;
    IStatement query = null;
    Map row = null;
    if (_sToCalculate == null)
        _sToCalculate = "count( {this.*} )";
    try {
        String sCondion = "";
        if (_condition != null)
            sCondion = _condition.toSQL(params);
        String strSQL = "SELECT " + _sToCalculate + " AS _COUNT, {this." + _sGroupProp + "} FROM {this}";
        for (int i = 1; i < _alias.length; i++) {
            strSQL += (",{" + _alias[i] + '}');
        }
        strSQL += (sCondion == null || sCondion.trim().length() < 1 ? "" : " WHERE ") + sCondion
                + " GROUP BY {this." + _sGroupProp + '}';
        query = mgr.createQuery(strSQL, 0);
        for (int i = 1; i < _contentClass.length; i++) {
            query.registerAlias(_alias[i], _contentClass[i]);
        }
        if (!params.isEmpty()) {
            query.setParameters(0, params);
        }
        datas = query.executeQuery();
        row = new HashMap(datas.getSize());
        do {
            DolphinObject data = datas.next();
            if (data == null) {
                break;
            }
            row.put(data.getProperty(_sGroupProp), data.getProperty("_COUNT"));
        } while (true);
    } finally {
        params.clear();
        DolphinHelper.clear(datas, query);
    }

    int caredTotal = 0;
    int total = 0;
    for (Iterator iter = row.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Map.Entry) iter.next();
        String sName = (String) entry.getKey();
        Number num = (Number) entry.getValue();
        if (_caredValues != null) {
            if (ArrayUtils.contains(_caredValues, sName)) {
                caredTotal += num.intValue();
            }
        }
        total += num.intValue();
    }
    row.put(OTHER, new Integer(total - caredTotal));
    row.put(TOTAL, new Integer(total));
    return row;
}

From source file:com.adobe.acs.tools.csv_asset_importer.impl.Column.java

public static Map<String, Column> getColumns(final String[] row, final String multiDelimiter,
        final String[] ignoreProperties, final String[] requiredProperties) throws CsvAssetImportException {
    final Map<String, Column> map = new HashMap<String, Column>();

    for (int i = 0; i < row.length; i++) {
        final Column col = new Column(row[i], i);

        col.setIgnore(ArrayUtils.contains(ignoreProperties, col.getPropertyName()));
        col.setMultiDelimiter(multiDelimiter);

        map.put(col.getPropertyName(), col);
    }//ww  w  .j  a  va 2  s  . c  om

    final List<String> missingRequiredProperties = hasRequiredFields(map.values(), requiredProperties);

    if (!missingRequiredProperties.isEmpty()) {
        throw new CsvAssetImportException(
                "Could not find required columns in CSV: " + StringUtils.join(missingRequiredProperties, ", "));
    }

    return map;
}

From source file:info.magnolia.cms.taglibs.util.SearchResultSnippetTag.java

/**
 * Extract a collection of snippets from any paragraph in the given page.
 * @return a collection of Strings./*from   w ww  .j a v  a 2s. c o  m*/
 * @todo avoid overlapping snippets (use regexp insted of simple indexOfs)
 * @todo only extract snippets from user-configured properties
 * @todo abbreviate on whitespace and puntuation, detect start of sentences
 * @todo replace ampersand in regexp
 * @todo break methods and write junits
 */
public Collection getSnippets() {

    if (log.isDebugEnabled()) {
        log.debug("collecting snippets"); //$NON-NLS-1$
    }

    Collection snippets = new ArrayList();
    String[] searchTerms = StringUtils.split(this.query);

    Collection paragraphCollections = this.page.getChildren(ItemType.CONTENTNODE);

    Iterator iterator = paragraphCollections.iterator();
    outer: while (iterator.hasNext()) {
        Content paragraphCollection = (Content) iterator.next();

        Collection paragraphs = paragraphCollection.getChildren();

        Iterator parIterator = paragraphs.iterator();
        while (parIterator.hasNext()) {
            Content paragraph = (Content) parIterator.next();

            if (log.isDebugEnabled()) {
                log.debug("Iterating on paragraph " + paragraph); //$NON-NLS-1$
            }

            Collection properties = paragraph.getNodeDataCollection();

            Iterator dataIterator = properties.iterator();
            while (dataIterator.hasNext()) {
                NodeData property = (NodeData) dataIterator.next();
                if (property.getType() != PropertyType.BINARY) {

                    String resultString = property.getString();

                    if (log.isDebugEnabled()) {
                        log.debug("Iterating on property " + property.getName()); //$NON-NLS-1$
                        log.debug("Property value is " + resultString); //$NON-NLS-1$
                    }

                    // a quick and buggy way to avoid configuration properties, we should allow the user to
                    // configure a list of nodeData to search for...
                    if (resultString.length() < 20) {
                        continue;
                    }

                    for (int j = 0; j < searchTerms.length; j++) {
                        String searchTerm = StringUtils.lowerCase(searchTerms[j]);

                        // exclude keywords and words with less than 2 chars
                        if (!ArrayUtils.contains(SimpleSearchTag.KEYWORDS, searchTerm)
                                && searchTerm.length() > 2) {

                            if (log.isDebugEnabled()) {
                                log.debug("Looking for search term [" + searchTerm + "] in [" + resultString //$NON-NLS-1$//$NON-NLS-2$
                                        + "]"); //$NON-NLS-1$
                            }

                            // first check, avoid using heavy string replaceAll operations if the search term is not
                            // there
                            if (!StringUtils.contains(resultString.toLowerCase(), searchTerm)) {
                                continue;
                            }

                            // strips out html tags using a regexp
                            resultString = resultString.replaceAll("\\<.*?\\>", ""); //$NON-NLS-1$ //$NON-NLS-2$

                            // only get first matching keyword
                            int pos = resultString.toLowerCase().indexOf(searchTerm);
                            if (pos > -1) {

                                int posEnd = pos + searchTerm.length();
                                int from = (pos - chars / 2);
                                if (from < 0) {
                                    from = 0;
                                }

                                int to = from + chars;
                                if (to > resultString.length()) {
                                    to = resultString.length();
                                }

                                StringBuffer snippet = new StringBuffer();

                                snippet.append(StringUtils.substring(resultString, from, pos));
                                snippet.append("<strong>"); //$NON-NLS-1$
                                snippet.append(StringUtils.substring(resultString, pos, posEnd));
                                snippet.append("</strong>"); //$NON-NLS-1$
                                snippet.append(StringUtils.substring(resultString, posEnd, to));

                                if (from > 0) {
                                    snippet.insert(0, "... "); //$NON-NLS-1$
                                }
                                if (to < resultString.length()) {
                                    snippet.append("... "); //$NON-NLS-1$
                                }

                                if (log.isDebugEnabled()) {
                                    log.debug("Search term found, adding snippet " + snippet); //$NON-NLS-1$
                                }

                                snippets.add(snippet);
                                if (snippets.size() >= this.maxSnippets) {
                                    if (log.isDebugEnabled()) {
                                        log.debug("Maximum number of snippets (" //$NON-NLS-1$
                                                + this.maxSnippets + ") reached, exiting"); //$NON-NLS-1$
                                    }
                                    break outer;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return snippets;
}

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateGroupManagementTest.java

@Test
@Transactional//from w ww. java2 s  . c o m
public void test20CreateUsers() {
    log.trace("Entering");
    // Obtaingin roles
    final GrantedAuthority ROLE_ADMIN = findRoleByRoleName("ROLE_ADMIN");
    final GrantedAuthority ROLE_USER = findRoleByRoleName("ROLE_USER");
    final GrantedAuthority ROLE_GUEST = findRoleByRoleName("ROLE_GUEST");

    // Creating users
    final List<SecurityUser> users = new ArrayList<SecurityUser>();

    SecurityUser user = new HibernateSecurityUser();
    user.setUsername("John Smith");
    user.setPassword("john");
    user.addUserAuthority(ROLE_ADMIN);
    user.addUserAuthority(ROLE_GUEST);
    users.add(user);

    user = new HibernateSecurityUser();
    user.setUsername("Maria Perez");
    user.setPassword("maria");
    user.addUserAuthority(ROLE_USER);
    users.add(user);

    user = new HibernateSecurityUser();
    user.setUsername("Juan Lopez");
    user.setPassword("juan");
    user.addUserAuthority(ROLE_GUEST);
    users.add(user);

    user = new HibernateSecurityUser();
    user.setUsername("Ramon Jimnez");
    user.setPassword("ramon");
    users.add(user);

    log.debug("Persisting users");
    dao.persist(users);

    // Check user roles
    for (SecurityUser originalUser : users) {
        log.debug("Cheking user: " + originalUser.getUsername());

        final UserDetails recoverUser = userManager.loadUserByUsername(originalUser.getUsername());
        Assert.assertEquals("loaded user", originalUser, recoverUser);

        GrantedAuthority[] originalAuthorities = originalUser.getAuthorities();
        GrantedAuthority[] recoverAuthorities = recoverUser.getAuthorities();
        Assert.assertEquals("authorities size", originalAuthorities.length, recoverAuthorities.length);
        for (GrantedAuthority authority : recoverAuthorities) {
            Assert.assertTrue("originalAuthorities must contains authority",
                    ArrayUtils.contains(originalAuthorities, authority));
        }
    }

    log.trace("Exiting");
}

From source file:com.healthcit.cacure.web.tag.AnswerPresenterTag.java

@Override
public int doStartTag() throws JspException {
    try {//from ww w.j av a2 s. co  m

        FormElement fe = formElement;
        if (formElement instanceof LinkElement) {
            ApplicationContext ctx = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(pageContext.getServletContext());
            fe = ctx.getBean(QuestionAnswerManager.class).getFantom(fe.getId());
        }

        String controlHtml = "";

        // TABLE Questions
        if (fe.isTable()) {
            controlHtml = processComplexControls(fe);
        }

        //Non-TABLE Questions
        else {
            Answer.AnswerType[] array = new Answer.AnswerType[] { AnswerType.TEXT, AnswerType.NUMBER,
                    AnswerType.INTEGER, AnswerType.POSITIVE_INTEGER, AnswerType.DATE, AnswerType.YEAR,
                    AnswerType.MONTHYEAR, AnswerType.CHECKBOX, AnswerType.RADIO, AnswerType.DROPDOWN,
                    AnswerType.TEXTAREA };

            if (ArrayUtils.contains(array, fe.getAnswerType())) {
                /*
                 * At this point we will be in this method only if
                 * FormElement is either QuestionElement,
                 * ExternalQuestionElement or LinkElement that is linked to
                 * one of the above
                 */
                List<? extends BaseQuestion> questions = fe.getQuestions();
                if (questions != null && questions.size() > 0) {
                    BaseQuestion question = questions.get(0);
                    controlHtml = processSimpleControls(fe, question.getAnswer());
                }
            } else {
                throw new JspException("Ansert type '" + fe.getAnswerType() + "' is not handled. Please see '"
                        + this.getClass().getSimpleName() + "' to verify");
            }
        }

        pageContext.getOut().print(controlHtml);
    } catch (IOException ioe) {
        throw new JspTagException("Error: IOException while writing to the user");
    }
    return SKIP_BODY;
}

From source file:cc.recommenders.mining.calls.pbn.PBNSmileModelBuilderFixture.java

public static void assertNodeExists(Network net, String id) {
    String[] nodeIds = net.getAllNodeIds();
    boolean actual = ArrayUtils.contains(nodeIds, SmileNameConverter.convertToLegalSmileName(id));

    Asserts.assertTrue(actual);/*  w  w  w  . ja v a  2 s . com*/
}

From source file:mitm.common.security.ca.CSVRequestConverter.java

private void checkRequiredColumns() throws RequestConverterException {
    if (!ArrayUtils.contains(columnOrder, Column.EMAIL)) {
        throw new RequestConverterException("Email column is missing.");
    }/*from  w w  w .  ja  v a  2 s .c  om*/

    if (!ArrayUtils.contains(columnOrder, Column.COMMONNAME)) {
        throw new RequestConverterException("Common name column is missing.");
    }
}