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:edu.illinois.cs.cogcomp.edison.features.lrec.TestChunkWindowThreeBefore.java

public final void test() throws EdisonException {

    log.debug("PreviousTags Feature Extractor");
    // Using the first TA and a constituent between span of 30-40 as a test
    TextAnnotation ta = tas.get(1);//w w w  . ja v a  2s  . c  o m
    View TOKENS = ta.getView("TOKENS");

    List<Constituent> testlist = TOKENS.getConstituentsCoveringSpan(0, 20);

    for (Constituent c : testlist) {
        log.debug(c.getSurfaceForm());
    }

    log.debug("Testlist size is " + testlist.size());

    Constituent test = testlist.get(4);

    log.debug("The constituent we are extracting features from in this test is: " + test.getSurfaceForm());

    ChunkWindowThreeBefore prevtags = new ChunkWindowThreeBefore("ChunkWindowThreeBefore");

    log.debug("Startspan is " + test.getStartSpan() + " and Endspan is " + test.getEndSpan());

    Set<Feature> feats = prevtags.getFeatures(test);
    String[] expected_outputs = { "ChunkWindowThreeBefore:0(NP)", "ChunkWindowThreeBefore:1(NP)" };

    if (feats == null) {
        log.debug("Feats are returning NULL.");
    }

    log.debug("Printing Set of Features");
    for (Feature f : feats) {
        log.debug(f.getName());
        assert (ArrayUtils.contains(expected_outputs, f.getName()));
    }

}

From source file:com.google.gdt.eclipse.designer.model.widgets.panels.SplitPanelInfo.java

/**
 * @return the {@link WidgetInfo} associated using {@link MethodInvocation} with given name.
 *///from  ww w  .  j a  v a2s.com
protected final WidgetInfo getWidgetAssociatedByMethod(String... names) {
    List<WidgetInfo> widgets = getChildrenWidgets();
    for (WidgetInfo widget : widgets) {
        String methodName = getWidgetAssociationMethod(widget);
        if (ArrayUtils.contains(names, methodName)) {
            return widget;
        }
    }
    return null;
}

From source file:net.jcreate.e3.table.decorator.URLDecorator.java

public Object decorate(Object pValue, Cell pCell) throws Exception {
    if (pValue == null) {
        return null;
    }/* w  w w . j a v a  2  s . co m*/
    String work = pValue.toString();

    int urlBegin;
    StringBuffer buffer = new StringBuffer();

    // First check for email addresses.
    while ((urlBegin = work.indexOf('@')) != -1) {
        int start = 0;
        int end = work.length() - 1;

        // scan backwards...
        for (int j = urlBegin; j >= 0; j--) {
            if (Character.isWhitespace(work.charAt(j))) {
                start = j + 1;
                break;
            }
        }

        // scan forwards...
        for (int j = urlBegin; j <= end; j++) {
            if (Character.isWhitespace(work.charAt(j))) {
                end = j - 1;
                break;
            }
        }

        String email = work.substring(start, end + 1);

        buffer.append(work.substring(0, start)).append("<a href=\"mailto:") //$NON-NLS-1$
                .append(email + "\">") //$NON-NLS-1$
                .append(email).append("</a>"); //$NON-NLS-1$

        if (end == work.length()) {
            work = TagConstants.EMPTY_STRING;
        } else {
            work = work.substring(end + 1);
        }
    }

    work = buffer.toString() + work;
    buffer = new StringBuffer();

    // Now check for urls...
    while ((urlBegin = work.indexOf(URL_DELIM)) != -1) {

        // scan backwards...
        int fullUrlBegin = urlBegin;
        StringBuffer prefixBuffer = new StringBuffer(10);
        for (int j = fullUrlBegin - 1; j >= 0; j--) {
            if (Character.isWhitespace(work.charAt(j))) {
                fullUrlBegin = j + 1;
                break;
            }
            fullUrlBegin = j;
            prefixBuffer.append(work.charAt(j));
        }

        if (!ArrayUtils.contains(URLS_PREFIXES, StringUtils.reverse(prefixBuffer.toString()))) {

            buffer.append(work.substring(0, urlBegin + 3));
            work = work.substring(urlBegin + 3);
            continue;
        }

        int urlEnd = work.length();

        // scan forwards...
        for (int j = urlBegin; j < urlEnd; j++) {
            if (Character.isWhitespace(work.charAt(j))) {
                urlEnd = j;
                break;
            }
        }

        String url = work.substring(fullUrlBegin, urlEnd);

        buffer.append(work.substring(0, fullUrlBegin)).append("<a href=\"")//$NON-NLS-1$
                .append(url).append("\">")//$NON-NLS-1$
                .append(url).append("</a>"); //$NON-NLS-1$

        if (urlEnd >= work.length()) {
            work = TagConstants.EMPTY_STRING;
        } else {
            work = work.substring(urlEnd);
        }
    }

    buffer.append(work);
    return buffer.toString();
}

From source file:com.leixl.easyframework.web.filter.VcaptchaFilter.java

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;

    String requestURI = request.getRequestURI();

    if (ArrayUtils.contains(includeURIs, requestURI)) {
        if (!doValidate(request, response)) {
            ResponseUtils.renderJson(response, resultJson);
            return;
        }//  w w  w .ja v a  2s . co m
    }
    chain.doFilter(req, resp);
}

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

@Test
public void testIntPredicateEvaluators() {
    int intValue = _random.nextInt();
    EqPredicate eqPredicate = new EqPredicate(COLUMN_NAME,
            Collections.singletonList(Integer.toString(intValue)));
    PredicateEvaluator eqPredicateEvaluator = EqualsPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(eqPredicate, FieldSpec.DataType.INT);

    NEqPredicate neqPredicate = new NEqPredicate(COLUMN_NAME,
            Collections.singletonList(Integer.toString(intValue)));
    PredicateEvaluator neqPredicateEvaluator = NotEqualsPredicateEvaluatorFactory
            .newNoDictionaryBasedEvaluator(neqPredicate, FieldSpec.DataType.INT);

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

    int[] randomInts = new int[NUM_MULTI_VALUES];
    PredicateEvaluatorTestUtils.fillRandom(randomInts);
    randomInts[_random.nextInt(randomInts.length)] = intValue;

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

    for (int i = 0; i < 100; i++) {
        int random = _random.nextInt();
        Assert.assertEquals(eqPredicateEvaluator.apply(random), (random == intValue));
        Assert.assertEquals(neqPredicateEvaluator.apply(random), (random != intValue));

        PredicateEvaluatorTestUtils.fillRandom(randomInts);
        Assert.assertEquals(eqPredicateEvaluator.apply(randomInts), ArrayUtils.contains(randomInts, intValue));
        Assert.assertEquals(neqPredicateEvaluator.apply(randomInts),
                !ArrayUtils.contains(randomInts, intValue));
    }//  www .  jav  a 2s  .  c  o m
}

From source file:com.manydesigns.portofino.pageactions.crud.reflection.CrudAccessor.java

public CrudAccessor(@NotNull final CrudConfiguration crudConfiguration, @NotNull ClassAccessor tableAccessor) {
    super(null);//  w  w w  .j  av  a2 s. co m
    this.crudConfiguration = crudConfiguration;
    this.tableAccessor = tableAccessor;
    PropertyAccessor[] columnAccessors = tableAccessor.getProperties();
    PropertyAccessor[] keyColumnAccessors = tableAccessor.getKeyProperties();

    propertyAccessors = new CrudPropertyAccessor[columnAccessors.length];
    keyPropertyAccessors = new CrudPropertyAccessor[keyColumnAccessors.length];

    int i = 0;
    for (PropertyAccessor columnAccessor : columnAccessors) {
        CrudProperty crudProperty = findCrudPropertyByName(crudConfiguration, columnAccessor.getName());
        boolean inKey = ArrayUtils.contains(keyColumnAccessors, columnAccessor);
        CrudPropertyAccessor propertyAccessor = new CrudPropertyAccessor(crudProperty, columnAccessor, inKey);
        propertyAccessors[i] = propertyAccessor;
        i++;
    }

    i = 0;
    for (PropertyAccessor keyColumnAccessor : keyColumnAccessors) {
        String propertyName = keyColumnAccessor.getName();
        try {
            CrudPropertyAccessor keyPropertyAccessor = getProperty(keyColumnAccessor.getName());
            keyPropertyAccessors[i] = keyPropertyAccessor;
        } catch (NoSuchFieldException e) {
            logger.error("Could not find key property: " + propertyName, e);
        }
        i++;
    }

    /*        logger.debug("Sorting crud properties to preserve their previous order as much as possible");
            Arrays.sort(propertyAccessors, new Comparator<CrudPropertyAccessor>() {
    private int oldIndex(CrudPropertyAccessor c) {
        int i = 0;
        for (CrudProperty old : crudConfiguration.getProperties()) {
            if (old.equals(c.getCrudProperty())) {
                return i;
            }
            i++;
        }
        return -1;
    }
            
    public int compare(CrudPropertyAccessor c1, CrudPropertyAccessor c2) {
        Integer index1 = oldIndex(c1);
        Integer index2 = oldIndex(c2);
        if (index1 != -1) {
            if (index2 != -1) {
                return index1.compareTo(index2);
            } else {
                return -1;
            }
        } else {
            return index2 == -1 ? 0 : 1;
        }
    }
            });*/
}

From source file:alpha.portal.webapp.util.Functions.java

/**
 * Contains./* w  w  w  . ja  va2  s .  c o m*/
 * 
 * @param list
 *            the list
 * @param o
 *            the o
 * @return true, if successful
 */
@SuppressWarnings("unchecked")
public static boolean contains(final String[] list, final String o) {
    return ArrayUtils.contains(list, o);
}

From source file:jp.co.opentone.bsol.linkbinder.dto.Attachment.java

/**
 * ????./*from  ww w. j  a  v a  2  s  .  co  m*/
 * @param fileName ??
 * @return 
 */
public static AttachmentFileType detectFileTypeByFileName(String fileName) {
    if (StringUtils.isEmpty(fileName)) {
        return AttachmentFileType.UNKNOWN;
    }

    String extension = FilenameUtils.getExtension(fileName);
    if (StringUtils.isEmpty(extension)) {
        return AttachmentFileType.UNKNOWN;
    }

    return ArrayUtils.contains(IMAGE_EXTENSIONS, extension.toLowerCase()) ? AttachmentFileType.IMAGE
            : AttachmentFileType.UNKNOWN;
}

From source file:net.osxx.AuthenticationRealm.java

/**
 * ???//from  ww  w  .j  av  a2  s . c  om
 * 
 * @param token
 *            
 * @return ??
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) {
    AuthenticationToken authenticationToken = (AuthenticationToken) token;
    String username = authenticationToken.getUsername();
    String password = new String(authenticationToken.getPassword());
    String captchaId = authenticationToken.getCaptchaId();
    String captcha = authenticationToken.getCaptcha();
    String ip = authenticationToken.getHost();
    if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) {
        throw new UnsupportedTokenException();
    }
    if (username != null && password != null) {
        Admin admin = adminService.findByUsername(username);
        Member member = memberService.findByUsername(username);
        if (admin == null && member == null) {
            throw new UnknownAccountException();
        }
        if (admin != null) {
            if (!admin.getIsEnabled()) {
                throw new DisabledAccountException();
            }
            Setting setting = SettingUtils.get();
            if (admin.getIsLocked()) {
                if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) {
                    int loginFailureLockTime = setting.getAccountLockTime();
                    if (loginFailureLockTime == 0) {
                        throw new LockedAccountException();
                    }
                    Date lockedDate = admin.getLockedDate();
                    Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                    if (new Date().after(unlockDate)) {
                        admin.setLoginFailureCount(0);
                        admin.setIsLocked(false);
                        admin.setLockedDate(null);
                        adminService.update(admin);
                    } else {
                        throw new LockedAccountException();
                    }
                } else {
                    admin.setLoginFailureCount(0);
                    admin.setIsLocked(false);
                    admin.setLockedDate(null);
                    adminService.update(admin);
                }
            }
            if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) {
                int loginFailureCount = admin.getLoginFailureCount() + 1;
                if (loginFailureCount >= setting.getAccountLockCount()) {
                    admin.setIsLocked(true);
                    admin.setLockedDate(new Date());
                }
                admin.setLoginFailureCount(loginFailureCount);
                adminService.update(admin);
                throw new IncorrectCredentialsException();
            }
            admin.setLoginIp(ip);
            admin.setLoginDate(new Date());
            admin.setLoginFailureCount(0);
            adminService.update(admin);
            return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName());
        } else {
            if (!member.getIsEnabled()) {
                throw new DisabledAccountException();
            }
            Setting setting = SettingUtils.get();
            if (member.getIsLocked()) {
                if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) {
                    int loginFailureLockTime = setting.getAccountLockTime();
                    if (loginFailureLockTime == 0) {
                        throw new LockedAccountException();
                    }
                    Date lockedDate = member.getLockedDate();
                    Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                    if (new Date().after(unlockDate)) {
                        member.setLoginFailureCount(0);
                        member.setIsLocked(false);
                        member.setLockedDate(null);
                        memberService.update(member);
                    } else {
                        throw new LockedAccountException();
                    }
                } else {
                    member.setLoginFailureCount(0);
                    member.setIsLocked(false);
                    member.setLockedDate(null);
                    memberService.update(member);
                }
            }
            if (!DigestUtils.md5Hex(password).equals(member.getPassword())) {
                int loginFailureCount = member.getLoginFailureCount() + 1;
                if (loginFailureCount >= setting.getAccountLockCount()) {
                    member.setIsLocked(true);
                    member.setLockedDate(new Date());
                }
                member.setLoginFailureCount(loginFailureCount);
                memberService.update(member);
                throw new IncorrectCredentialsException();
            }
            member.setLoginIp(ip);
            member.setLoginDate(new Date());
            member.setLoginFailureCount(0);
            memberService.update(member);

            return new SimpleAuthenticationInfo(new Principal(member.getId(), username), password, getName());
        }

    }
    throw new UnknownAccountException();
}

From source file:com.kalessil.phpStorm.phpInspectionsEA.inspectors.phpDoc.UnknownInspectionInspector.java

private static Set<String> collectKnownInspections() {
    final Set<String> names = new HashSet<>();
    final PluginId phpSupport = PluginId.getId("com.jetbrains.php");

    for (IdeaPluginDescriptor plugin : PluginManager.getPlugins()) {
        /* check plugins' dependencies and extensions */
        /* we have to rely on impl-class, see https://youtrack.jetbrains.com/issue/WI-34555 */
        final MultiMap<String, Element> extensions = ((IdeaPluginDescriptorImpl) plugin).getExtensions();
        final boolean isPhpPlugin = plugin.getPluginId().equals(phpSupport);
        if (null == extensions
                || (!ArrayUtils.contains(plugin.getDependentPluginIds(), phpSupport)) && !isPhpPlugin) {
            continue;
        }/*from  w  w w  . j  av  a  2 s .com*/

        /* extract inspections; short names */
        for (Element node : extensions.values()) {
            final String nodeName = node.getName();
            if (null == nodeName || !nodeName.equals("localInspection")) {
                continue;
            }

            final Attribute name = node.getAttribute("shortName");
            final String shortName = null == name ? null : name.getValue();
            if (null != shortName && shortName.length() > 0) {
                names.add(shortName);
            }
        }
    }

    return names;
}