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:cn.shengyuan.yun.admin.web.template.directive.BaseDirective.java

/**
 * ??//w  w  w .  j  a v  a2  s. c  o m
 * 
 * @param params
 *            ?
 * @param ignoreProperties
 *            
 * @return ?
 */
protected List<Order> getOrders(Map<String, TemplateModel> params, String... ignoreProperties)
        throws TemplateModelException {
    String orderBy = StringUtils
            .trim(FreemarkerUtils.getParameter(ORDER_BY_PARAMETER_NAME, String.class, params));
    List<Order> orders = new ArrayList<Order>();
    if (StringUtils.isNotEmpty(orderBy)) {
        String[] orderByItems = orderBy.split(ORDER_BY_ITEM_SEPARATOR);
        for (String orderByItem : orderByItems) {
            if (StringUtils.isNotEmpty(orderByItem)) {
                String property = null;
                Direction direction = null;
                String[] orderBys = orderByItem.split(ORDER_BY_FIELD_SEPARATOR);
                if (orderBys.length == 1) {
                    property = orderBys[0];
                } else if (orderBys.length >= 2) {
                    property = orderBys[0];
                    try {
                        direction = Direction.valueOf(orderBys[1]);
                    } catch (IllegalArgumentException e) {
                        continue;
                    }
                } else {
                    continue;
                }
                if (!ArrayUtils.contains(ignoreProperties, property)) {
                    orders.add(new Order(property, direction));
                }
            }
        }
    }
    return orders;
}

From source file:gda.device.scannable.MonoScannable.java

@Override
public void setUserUnits(String userUnitsString) throws DeviceException {

    Unit<?> newUnits = QuantityFactory.createUnitFromString(userUnitsString);
    if (configured) {
        if (ArrayUtils.contains(this.acceptableUnits, newUnits)) {
            this.userUnits = newUnits;
        }//  ww  w  .  ja v a  2 s .  com
    } else {
        this.initialUserUnits = userUnitsString;
    }
}

From source file:com.atolcd.pentaho.di.trans.steps.gisrelate.GisRelate.java

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (GisRelateMeta) smi;/*w  w  w.j  av a  2s. c o m*/
    data = (GisRelateData) sdi;

    Object result;

    Object[] r = getRow();

    if (r == null) {

        setOutputDone();
        return false;

    }

    if (first) {

        first = false;
        data.outputRowMeta = (RowMetaInterface) getInputRowMeta().clone();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this);

        operator = meta.getOperator();
        returnType = meta.getReturnType();

        // Rcupration des indexes des colonnes contenant les gomrtries
        // d'entre
        firstGeometryFieldIndex = getInputRowMeta().indexOfValue(meta.getFirstGeometryFieldName());
        secondGeometryFieldIndex = getInputRowMeta().indexOfValue(meta.getSecondGeometryFieldName());
        firstGeometryInterface = (GeometryInterface) getInputRowMeta().getValueMeta(firstGeometryFieldIndex);
        secondGeometryInterface = (GeometryInterface) getInputRowMeta().getValueMeta(secondGeometryFieldIndex);
        // Besoin de distance
        if (ArrayUtils.contains(meta.getWithDistanceOperators(), operator)) {

            withDistance = true;
            if (meta.isDynamicDistance()) {
                distanceFieldIndex = getInputRowMeta().indexOfValue(meta.getDistanceFieldName());
            } else {

                try {
                    distanceValue = Double.parseDouble(environmentSubstitute(meta.getDistanceValue()));
                } catch (Exception e) {
                    throw new KettleException("Distance is not valid");
                }
            }

        } else {
            withDistance = false;
        }

        // En fonction du type de rsultat
        if (ArrayUtils.contains(meta.getBoolResultOperators(), operator)) {
            resultType = Boolean.class;
        } else if (ArrayUtils.contains(meta.getNumericResultOperators(), operator)) {
            resultType = Double.class;
        }

        // Rcupration de l'index de la colonne contenant le rsultat
        outputFieldIndex = data.outputRowMeta.indexOfValue(meta.getOutputFieldName());

        logBasic("Initialized successfully");

    }

    Object[] outputRow = null;
    result = getRelateResult(r);

    if (resultType.equals(Boolean.class)) {

        if (returnType.equalsIgnoreCase("ALL")) {

            outputRow = RowDataUtil.resizeArray(r, r.length + 1);
            outputRow[outputFieldIndex] = (Boolean) result;
            putRow(data.outputRowMeta, outputRow);

        } else {

            if (String.valueOf((Boolean) result).equalsIgnoreCase(returnType)) {
                putRow(data.outputRowMeta, r);
            }

        }

    } else if (resultType.equals(Double.class)) {

        outputRow = RowDataUtil.resizeArray(r, r.length + 1);
        outputRow[outputFieldIndex] = (Double) result;
        putRow(data.outputRowMeta, outputRow);

    }

    incrementLinesInput();

    if (checkFeedback(getLinesRead())) {
        logBasic("Linenr " + getLinesRead());
    }

    return true;
}

From source file:net.shopxx.plugin.LoginPlugin.java

protected String joinValue(Map<String, Object> map, String prefix, String suffix, String separator,
        boolean ignoreEmptyValue, String... ignoreKeys) {
    List<String> list = new ArrayList<String>();
    if (map != null) {
        for (Map.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(value != null ? value : "");
            }//from  w w  w  .  j a  v  a  2s  .c  o m
        }
    }
    return (prefix != null ? prefix : "") + StringUtils.join(list, separator) + (suffix != null ? suffix : "");
}

From source file:com.sammyun.controller.shop.LoginController.java

/**
 * ??/*from  w w w .  jav  a2s  .  c  om*/
 */
@RequestMapping(value = "/submit", method = RequestMethod.POST)
public @ResponseBody Message submit(String captchaId, String captcha, String username,
        HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    String password = rsaService.decryptParameter("enPassword", request);
    rsaService.removePrivateKey(request);

    if (!captchaService.isValid(CaptchaType.memberLogin, captchaId, captcha)) {
        return Message.error("shop.captcha.invalid");
    }
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        return Message.error("shop.common.invalid");
    }
    Member member;
    Setting setting = SettingUtils.get();
    if (setting.getIsEmailLogin() && username.contains("@")) {
        List<Member> members = memberService.findListByEmail(username);
        if (members.isEmpty()) {
            member = null;
        } else if (members.size() == 1) {
            member = members.get(0);
        } else {
            return Message.error("shop.login.unsupportedAccount");
        }
    } else {
        member = memberService.findByUsername(username);
    }
    if (member == null) {
        return Message.error("shop.login.unknownAccount");
    }
    if (!member.getIsEnabled()) {
        return Message.error("shop.login.disabledAccount");
    }
    checkLockedStatus(member, setting);

    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);
        if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) {
            return Message.error("shop.login.accountLockCount", setting.getAccountLockCount());
        } else {
            return Message.error("shop.login.incorrectCredentials");
        }
    }
    updateLoginStatus(request, member);

    Map<String, Object> attributes = new HashMap<String, Object>();
    Enumeration<?> keys = session.getAttributeNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        attributes.put(key, session.getAttribute(key));
    }
    session.invalidate();
    session = request.getSession();
    for (Entry<String, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }

    session.setAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME, new Principal(member.getId(), username));
    WebUtils.addCookie(request, response, Member.USERNAME_COOKIE_NAME, member.getUsername());

    return SUCCESS_MESSAGE;
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BrokerQueryParser.java

protected boolean isUniqueQuery(MultivaluedMap<String, String> queryParameters, String sourceId) {
    boolean uniqueQuery = true;
    QueryRequestCache queryRequestCache = getQueryRequestCache();
    String oid = queryParameters.getFirst(SearchConstants.OID_PARAMETER);
    if (StringUtils.isNotBlank(oid)) {
        uniqueQuery = queryRequestCache.isQueryIdUnique(oid);
    } else {/*from ww w .j  av a  2  s.  c  o m*/
        String uuid = UUID.randomUUID().toString();
        queryParameters.putSingle(SearchConstants.OID_PARAMETER, uuid);
        queryRequestCache.add(uuid);
    }

    String path = queryParameters.getFirst(BrokerConstants.PATH_PARAMETER);
    if (StringUtils.isNotBlank(path)) {
        String[] pathValues = path.split(",");
        if (ArrayUtils.contains(pathValues, sourceId)) {
            uniqueQuery = false;
        }
    }
    return uniqueQuery;
}

From source file:gda.device.scannable.CoupledScannable.java

/**
 * Adds a function to the list//w w  w .  j  ava 2s. c om
 * 
 * @param newFunction
 */
public void addFunction(Function newFunction) {
    if (!ArrayUtils.contains(theFunctions, newFunction)) {
        theFunctions = (Function[]) ArrayUtils.add(theFunctions, newFunction);
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.common.informationflow.InformationFlowGeneralHelper.java

/**
 * retrieves the caption for the legend// www  . ja  v  a  2  s .c o  m
 * 
 * @param lineCaptionSelected
 *          which type of element / attribute to be used for the caption
 * @param lineCaptionAttributeId
 *          the id of the attribute
 * @param informationFlowOptions
 *          the info flow options bean
 * @param locale
 *          the currently used locale
 * @return See method description.
 */
public static String getDescriptionTypeName(AttributeTypeService attributeTypeService,
        int[] lineCaptionSelected, Integer lineCaptionAttributeId,
        IInformationFlowOptions informationFlowOptions, Locale locale) {

    List<String> descriptionTypeNames = Lists.newArrayList();

    for (int lineCaption : lineCaptionSelected) {
        switch (lineCaption) {

        case InformationFlowOptionsBean.LINE_DESCR_ATTRIBUTES:
            if (GraphicalExportBaseOptions.NOTHING_SELECTED != lineCaptionAttributeId.intValue()) {
                AttributeType attrType = attributeTypeService.loadObjectById(lineCaptionAttributeId);
                descriptionTypeNames.add(attrType.getName());
            } else {
                descriptionTypeNames.add("n.a.");
            }

            break;

        case InformationFlowOptionsBean.LINE_DESCR_TECHNICAL_COMPONENTS:
            descriptionTypeNames
                    .add(MessageAccess.getStringOrNull(Constants.BB_TECHNICALCOMPONENTRELEASE_PLURAL, locale));
            break;

        case InformationFlowOptionsBean.LINE_DESCR_DESCRIPTION:
            descriptionTypeNames.add(MessageAccess.getStringOrNull(Constants.ATTRIBUTE_DESCRIPTION, locale));
            break;

        case InformationFlowOptionsBean.LINE_DESCR_NAME:
            descriptionTypeNames.add(MessageAccess.getStringOrNull(Constants.ATTRIBUTE_NAME, locale));
            break;

        default: // Business Objects are displayed at the end
        }
    }
    if (ArrayUtils.contains(lineCaptionSelected, InformationFlowOptionsBean.LINE_DESCR_BUSINESS_OBJECTS)) {
        descriptionTypeNames.add(MessageAccess.getStringOrNull(Constants.BB_BUSINESSOBJECT_PLURAL, locale));
    }
    return StringUtils.join(descriptionTypeNames, "; ");
}

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

public static Map<String, Column> getColumns(final String[] row, final String multiDelimiter,
        final String[] ignoreProperties, final String[] requiredProperties) throws CsvException {
    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);
    }//from  w ww.  j a  va  2 s  . co m

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

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

    return map;
}

From source file:edu.cornell.med.icb.goby.alignments.AlignmentReaderImpl.java

/**
 * Returns true if filename belongs to an alignment basename that can be read.
 *
 * @param filename Filename of an alignment component.
 * @return True if the alignment can be read, false otherwise.
 *///w ww  .j  a  v a  2 s. c o m
public static boolean canRead(final String filename) {

    final String filenameNoExtension = FilenameUtils.removeExtension(filename);
    String fileExtension = FilenameUtils.getExtension(filename);

    if (!ArrayUtils.contains(AlignmentReaderImpl.COMPACT_ALIGNMENT_FILE_REQUIRED_EXTS, "." + fileExtension)
            && !ArrayUtils.contains(AlignmentReaderImpl.COMPACT_ALIGNMENT_FILE_POSSIBLE_EXTS,
                    "." + fileExtension)) {
        // the file does not contain any of the Goby required or possible extensions. It is not a supported file.
        return false;
    }
    // the file contains a Goby alignment extension, we further check that each needed extension exists:
    int count = 0;
    for (final String extension : AlignmentReaderImpl.COMPACT_ALIGNMENT_FILE_REQUIRED_EXTS) {

        if (RepositionableInputStream.resourceExist(filenameNoExtension + extension)) {
            // we can read this file.
            count++;
        }
    }
    return count == AlignmentReaderImpl.COMPACT_ALIGNMENT_FILE_REQUIRED_EXTS.length;
}