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:adalid.commons.velocity.Writer.java

private void writeFile(WriterContext templateWriterContext, File templatePropertiesFile) {
    VelocityContext fileContext = templateWriterContext.getVelocityContextClone();
    TLB.setProgrammers(templateWriterContext.programmers);
    TLB.setWrapperClasses(templateWriterContext.wrapperClasses);
    Properties properties = mergeProperties(fileContext, templatePropertiesFile);
    putStrings(fileContext, properties);
    //      String rootPath = getRootPath(fileContext);
    String userPath = pathString(USER_DIR);
    String temptype = StringUtils.defaultIfBlank(properties.getProperty(TP_TYPE), TP_TYPE_VELOCITY);
    String template = StringUtils.trimToNull(properties.getProperty(TP_TEMPLATE));
    String filePath = StringUtils.trimToNull(properties.getProperty(TP_PATH));
    String filePack = StringUtils.trimToNull(properties.getProperty(TP_PACKAGE));
    String fileName = StringUtils.trimToNull(properties.getProperty(TP_FILE));
    String preserve = StringUtils.trimToNull(properties.getProperty(TP_PRESERVE));
    String charset1 = StringUtils.trimToNull(properties.getProperty(TP_ENCODING));
    String charset2 = StringUtils.trimToNull(properties.getProperty(TP_CHARSET));
    String root = getRoot().getPath();
    String raiz = root.replace('\\', '/');
    String hint = "; check property \"{0}\" at file \"{1}\"";
    if (ArrayUtils.contains(TP_TYPE_ARRAY, temptype)) {
    } else {/*from w  ww. ja  va 2s  .  c  o  m*/
        String pattern = "failed to obtain a valid template type" + hint;
        String message = MessageFormat.format(pattern, TP_TYPE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    if (template == null) {
        String pattern = "failed to obtain a valid template name" + hint;
        String message = MessageFormat.format(pattern, TP_TEMPLATE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    if (fileName == null) {
        String pattern = "failed to obtain a valid file name" + hint;
        String message = MessageFormat.format(pattern, TP_FILE, templatePropertiesFile);
        logger.error(message);
        errors++;
        return;
    }
    String templatePathString = pathString(template);
    String templatePath = StringUtils.substringBeforeLast(templatePathString, FILE_SEPARATOR);
    fileContext.put(VC_TEMPLATE, StringEscapeUtils.escapeJava(templatePathString));
    fileContext.put(VC_TEMPLATE_PATH, StringUtils.replace(templatePath, FILE_SEPARATOR, SLASH));
    fileContext.put(VC_FILE, fileName);
    if (filePath == null) {
        //          filePath = rootPath;
        filePath = userPath;
    } else {
        filePath = pathString(filePath);
        if (isRelativePath(filePath)) {
            if (filePath.startsWith(FILE_SEPARATOR)) {
                //                  filePath = rootPath + filePath;
                filePath = userPath + filePath;
            } else {
                //                  filePath = rootPath + FILE_SEPARATOR + filePath;
                filePath = userPath + FILE_SEPARATOR + filePath;
            }
        }
    }
    fileContext.put(VC_PATH, StringEscapeUtils.escapeJava(filePath));
    if (filePack != null) {
        filePath += FILE_SEPARATOR + pathString(StringUtils.replace(filePack, DOT, SLASH));
        fileContext.put(VC_PACKAGE, dottedString(filePack));
    }
    File path = new File(filePath);
    if (path.exists()) {
        if (path.isDirectory() && path.canWrite()) {
        } else {
            String pattern = "{2} is not a valid directory" + hint;
            String message = MessageFormat.format(pattern, TP_PATH, templatePropertiesFile, path);
            logger.error(message);
            errors++;
            return;
        }
    } else if (path.mkdirs()) {
    } else {
        String pattern = "{2} is not a valid path" + hint;
        String message = MessageFormat.format(pattern, TP_PATH, templatePropertiesFile, path);
        logger.error(message);
        errors++;
        return;
    }
    String fullname = path.getPath() + FILE_SEPARATOR + fileName;
    String slashedPath = fullname.replace('\\', '/');
    File file = new File(fullname);
    if (file.exists()) {
        String regex, pattern, message;
        for (Pattern fxp : fileExclusionPatterns) {
            regex = fxp.pattern();
            if (slashedPath.matches(regex)) {
                excludedFiles++;
                pattern = "file {0} will be deleted; it matches exclusion expression \"{1}\"";
                message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz),
                        regex);
                log(_alertLevel, message);
                warnings++;
                FileUtils.deleteQuietly(file);
                return;
            }
        }
        if (BitUtils.valueOf(preserve)) {
            preservedFiles++;
            pattern = "file {2} will not be replaced" + hint;
            message = MessageFormat.format(pattern, TP_PRESERVE, templatePropertiesFile, fullname);
            log(_detailLevel, message);
            return;
        }
        for (Pattern fxp : filePreservationPatterns) {
            regex = fxp.pattern();
            if (slashedPath.matches(regex)) {
                preservedFiles++;
                pattern = "file {0} will not be replaced; it matches preservation expression \"{1}\"";
                message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz),
                        regex);
                log(_alertLevel, message);
                warnings++;
                return;
            }
        }
    } else {
        String regex, pattern, message;
        for (Pattern fxp : fileExclusionPatterns) {
            regex = fxp.pattern();
            if (slashedPath.matches(regex)) {
                excludedFiles++;
                pattern = "file {0} will not be written; it matches exclusion expression \"{1}\"";
                message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz),
                        regex);
                log(_alertLevel, message);
                warnings++;
                return;
            }
        }
    }
    if (charset1 != null && !Charset.isSupported(charset1)) {
        String pattern = "{2} is not a supported character set" + hint;
        String message = MessageFormat.format(pattern, TP_ENCODING, templatePropertiesFile, charset1);
        logger.error(message);
        errors++;
        return;
    }
    if (charset2 != null && !Charset.isSupported(charset2)) {
        String pattern = "{2} is not a supported character set" + hint;
        String message = MessageFormat.format(pattern, TP_CHARSET, templatePropertiesFile, charset2);
        logger.error(message);
        errors++;
        return;
    }
    fileContext.put(VC_FILE_PATH, StringEscapeUtils.escapeJava(filePath));
    fileContext.put(VC_FILE_NAME, StringEscapeUtils.escapeJava(fileName));
    fileContext.put(VC_FILE_PATH_NAME, StringEscapeUtils.escapeJava(fullname));
    fileContext.put(VC_FILE_PATH_FILE, path);
    if (temptype.equals(TP_TYPE_VELOCITY)) {
        writeFile(fileContext, template, fullname, charset1, charset2);
    } else {
        writeFile(template, fullname);
    }
    executeFile(fileContext, templatePropertiesFile);
}

From source file:com.flexive.shared.structure.FxType.java

private synchronized void addScriptMapping(Map<FxScriptEvent, long[]> scriptMapping, FxScriptEvent scriptEvent,
        long scriptId) {
    if (scriptMapping.get(scriptEvent) == null)
        scriptMapping.put(scriptEvent, new long[] { scriptId });
    else {/*ww w. jav a2s . c o  m*/
        long[] scripts = scriptMapping.get(scriptEvent);
        if (ArrayUtils.contains(scripts, scriptId))
            return;
        long[] new_scripts = new long[scripts.length + 1];
        System.arraycopy(scripts, 0, new_scripts, 0, scripts.length);
        new_scripts[new_scripts.length - 1] = scriptId;
        scriptMapping.put(scriptEvent, new_scripts);
    }
}

From source file:com.atolcd.pentaho.di.ui.trans.steps.gisgeoprocessing.GisGeoprocessingDialog.java

private void setOperatorFlags() {

    String operatorKey = getOperatorKey(wOperator.getText());

    if (operatorKey != null) {

        wOperatorDescription.setText(//from   w  w w  .  ja v a 2  s . c om
                BaseMessages.getString(PKG, "GisGeoprocessing.Operator." + operatorKey + ".Description"));

        // Besoin de 2 gomtries
        if (ArrayUtils.contains(input.getTwoGeometriesOperators(), operatorKey)) {

            wSecondGeometryField.setEnabled(true);
            wlSecondGeometryField.setEnabled(true);

        } else {

            wSecondGeometryField.setEnabled(false);
            wlSecondGeometryField.setEnabled(false);
            wSecondGeometryField.setText("");

        }

        // Possibilit de filtrage de gomtrie
        if (ArrayUtils.contains(input.getWithExtractTypeOperators(), operatorKey)) {

            wlExtractType.setEnabled(true);
            wExtractType.setEnabled(true);

        } else {

            wlExtractType.setEnabled(false);
            wExtractType.setEnabled(false);
            wExtractType.setText(getExtractTypeLabel("ALL"));

        }

        // Besoin de distance
        if (ArrayUtils.contains(input.getWithDistanceOperators(), operatorKey)) {

            wlDynamicDistance.setEnabled(true);
            wDynamicDistance.setEnabled(true);
            wlDistanceField.setEnabled(true);

            if (wDynamicDistance.getSelection()) {
                wDistanceField.setEnabled(true);
                wDistanceValue.setEnabled(false);
                wDistanceValue.setText("");
            } else {
                wDistanceField.setEnabled(false);
                wDistanceField.setText("");
                wDistanceValue.setEnabled(true);
            }

        } else {

            wlDynamicDistance.setEnabled(false);
            wDynamicDistance.setEnabled(false);
            wDynamicDistance.setSelection(false);

            wlDistanceField.setEnabled(false);
            wDistanceField.setEnabled(false);
            wDistanceField.setText("");

            wDistanceValue.setEnabled(false);
            wDistanceValue.setText("");
        }

        // Buffer tendu
        if (operatorKey.equalsIgnoreCase("EXTENDED_BUFFER")) {

            wlBufferSegmentsCount.setEnabled(true);
            wBufferSegmentsCount.setEnabled(true);

            wlBufferCapStyle.setEnabled(true);
            wBufferCapStyle.setEnabled(true);

            wlBufferJoinStyle.setEnabled(true);
            wBufferJoinStyle.setEnabled(true);

            wlBufferSingleSide.setEnabled(true);
            wBufferSingleSide.setEnabled(true);

        } else {

            wlBufferSegmentsCount.setEnabled(false);
            wBufferSegmentsCount.setEnabled(false);
            wBufferSegmentsCount.setText("8");
            wBufferSegmentsCount.setData(8);

            wlBufferCapStyle.setEnabled(false);
            wBufferCapStyle.setEnabled(false);
            wBufferCapStyle.setText(getStyleBufferLabel("ROUND"));

            wlBufferJoinStyle.setEnabled(false);
            wBufferJoinStyle.setEnabled(false);
            wBufferJoinStyle.setText(getStyleBufferLabel("ROUND"));

            wlBufferSingleSide.setEnabled(false);
            wBufferSingleSide.setEnabled(false);
            wBufferSingleSide.setSelection(false);

        }

    }

}

From source file:com.haulmont.cuba.core.sys.MetaModelLoader.java

protected boolean isDefinedForValidationGroup(Annotation annotation, Class groupClass, boolean inheritDefault) {
    try {//from   w w w  .  ja v  a2 s.  c  o m
        Method groupsMethod = annotation.getClass().getMethod("groups");
        Class<?>[] groups = (Class<?>[]) groupsMethod.invoke(annotation);
        if (inheritDefault && groups.length == 0) {
            return true;
        }
        return ArrayUtils.contains(groups, groupClass);
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
        throw new RuntimeException("Unable to use annotation metadata " + annotation);
    }
}

From source file:com.manydesigns.portofino.actions.admin.database.TablesAction.java

protected void configureTypesSelectionProvider(DefaultSelectionProvider typesSP, ColumnForm columnForm) {
    Type type = columnForm.getType();
    Class[] javaTypes = getAvailableJavaTypes(type, columnForm.getLength());
    Integer precision = columnForm.getLength();
    Integer scale = columnForm.getScale();
    Class defaultJavaType = Type.getDefaultJavaType(columnForm.getJdbcType(), precision, scale);
    if (defaultJavaType == null) {
        defaultJavaType = Object.class;
    }/*from  w w  w .  j  a  v a2 s .  com*/
    typesSP.appendRow(new Object[] { columnForm.getColumnName(), type, null },
            new String[] { columnForm.getColumnName(),
                    type.getTypeName() + " (JDBC: " + type.getJdbcType() + ")",
                    "Auto (" + getJavaTypeName(defaultJavaType) + ")" },
            true);
    try {
        Class existingType = Class.forName(columnForm.getJavaType());
        if (!ArrayUtils.contains(javaTypes, existingType)) {
            typesSP.appendRow(new Object[] { columnForm.getColumnName(), type, null },
                    new String[] { columnForm.getColumnName(),
                            type.getTypeName() + " (JDBC: " + type.getJdbcType() + ")",
                            getJavaTypeName(existingType) },
                    true);
        }
    } catch (Exception e) {
        logger.debug("Invalid Java type", e);
    }
    for (Class c : javaTypes) {
        typesSP.appendRow(new Object[] { columnForm.getColumnName(), type, c.getName() },
                new String[] { columnForm.getColumnName(),
                        type.getTypeName() + " (JDBC: " + type.getJdbcType() + ")", getJavaTypeName(c) },
                true);
    }
}

From source file:jef.tools.StringUtils.java

/**
 * //from  www.j  a v  a2  s  . co m
 * 
 * @param s
 * @param trimChars
 * @return
 */
public static final String ltrim(String s, char... trimChars) {
    int len = s.length();
    int st = 0;
    int off = 0;
    while ((st < len) && (ArrayUtils.contains(trimChars, s.charAt(off + st)))) {
        st++;
    }
    return ((st > 0) || (len < s.length())) ? s.substring(st, len) : s;
}

From source file:jef.tools.StringUtils.java

/**
 * ?//from   www.  j  av a  2s .  c o  m
 * 
 * @param s
 * @param trimChars
 * @return
 */
public static final String rtrim(String s, char... trimChars) {
    int len = s.length();
    int st = 0;
    int off = 0; /* avoid getfield opcode */
    while ((st < len) && ArrayUtils.contains(trimChars, s.charAt(off + len - 1))) {
        len--;
    }
    return ((st > 0) || (len < s.length())) ? s.substring(st, len) : s;
}

From source file:com.circle.utils.XMLSerializer.java

private Element processJSONObject(JSONObject jsonObject, Element root, String[] expandableProperties,
        boolean isRoot) {
    if (jsonObject.isNullObject()) {
        root.addAttribute(new Attribute(addJsonPrefix("null"), "true"));
        return root;
    } else if (jsonObject.isEmpty()) {
        return root;
    }/*  w ww.  j  a  v a 2  s  .c  o  m*/

    if (isRoot) {
        if (!rootNamespace.isEmpty()) {
            setNamespaceLenient(true);
            for (Iterator entries = rootNamespace.entrySet().iterator(); entries.hasNext();) {
                Map.Entry entry = (Map.Entry) entries.next();
                String prefix = (String) entry.getKey();
                String uri = (String) entry.getValue();
                if (StringUtils.isBlank(prefix)) {
                    root.setNamespaceURI(uri);
                } else {
                    root.addNamespaceDeclaration(prefix, uri);
                }
            }
        }
    }

    addNameSpaceToElement(root);

    Object[] names = jsonObject.names().toArray();
    Arrays.sort(names);
    Element element = null;
    for (int i = 0; i < names.length; i++) {
        String name = (String) names[i];
        Object value = jsonObject.get(name);
        if (name.startsWith("@xmlns")) {
            setNamespaceLenient(true);
            int colon = name.indexOf(':');
            if (colon == -1) {
                // do not override if already defined by nameSpaceMaps
                if (StringUtils.isBlank(root.getNamespaceURI())) {
                    root.setNamespaceURI(String.valueOf(value));
                }
            } else {
                String prefix = name.substring(colon + 1);
                if (StringUtils.isBlank(root.getNamespaceURI(prefix))) {
                    root.addNamespaceDeclaration(prefix, String.valueOf(value));
                }
            }
        } else if (name.startsWith("@")) {
            root.addAttribute(new Attribute(name.substring(1), String.valueOf(value)));
        } else if (name.equals("#text")) {
            if (value instanceof JSONArray) {
                root.appendChild(((JSONArray) value).join("", true));
            } else {
                root.appendChild(String.valueOf(value));
            }
        } else if (value instanceof JSONArray && (((JSONArray) value).isExpandElements()
                || ArrayUtils.contains(expandableProperties, name))) {
            JSONArray array = (JSONArray) value;
            int l = array.size();
            for (int j = 0; j < l; j++) {
                Object item = array.get(j);
                element = newElement(name);
                if (item instanceof JSONObject) {
                    element = processJSONValue((JSONObject) item, root, element, expandableProperties);
                } else if (item instanceof JSONArray) {
                    element = processJSONValue((JSONArray) item, root, element, expandableProperties);
                } else {
                    element = processJSONValue(item, root, element, expandableProperties);
                }
                addNameSpaceToElement(element);
                root.appendChild(element);
            }
        } else {
            element = newElement(name);
            element = processJSONValue(value, root, element, expandableProperties);
            addNameSpaceToElement(element);
            root.appendChild(element);
        }
    }
    return root;
}

From source file:com.smartmarmot.common.Configurator.java

public DBConn[] rebuildDBList(DBConn[] _dbc) {
    try {/*from  w w  w.j  a v  a 2  s  . c o  m*/
        verifyConfig();
        String[] localdblist = this.getDBList();
        String[] remotedblist = new String[_dbc.length];
        for (int i = 0; i < _dbc.length; i++) {
            remotedblist[i] = _dbc[i].getName();
        }

        Collection<DBConn> connections = new ArrayList<DBConn>();
        for (int j = 0; j < localdblist.length; j++) {
            if (ArrayUtils.contains(remotedblist, localdblist[j])) {
                DBConn tmpDBConn;
                tmpDBConn = _dbc[ArrayUtils.indexOf(remotedblist, localdblist[j])];
                connections.add(tmpDBConn);
            }
            if (!ArrayUtils.contains(remotedblist, localdblist[j])) {
                /*
                 * adding database
                 */
                SmartLogger.logThis(Level.INFO, "New database founded! " + localdblist[j]);
                DBConn tmpDBConn = this.getDBConnManager(localdblist[j]);
                if (tmpDBConn != null) {
                    connections.add(tmpDBConn);
                }
            }
        }
        for (int x = 0; x < _dbc.length; x++) {
            if (!ArrayUtils.contains(localdblist, _dbc[x].getName())) {
                SmartLogger.logThis(Level.WARN,
                        "Database " + _dbc[x].getName() + " removed from configuration file");
                /**
                 * removing database
                 */
                // _dbc[x].closeAll();

                SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " conections closed");
                _dbc[x] = null;
            }
        }
        DBConn[] connArray = (DBConn[]) connections.toArray(new DBConn[0]);
        return connArray;
    } catch (Exception ex) {
        SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list "
                + Constants.DATABASES_LIST + " error:" + ex);
        return _dbc;
    }

}

From source file:jef.tools.StringUtils.java

/**
 * ????trim//from  w ww. ja  v  a 2  s .  c om
 * 
 * @param s
 * @param lTrimChars
 *            ?trim
 * @param rTrimChars
 *            ??trim
 * @return
 */
public static final String lrtrim(String s, char[] lTrimChars, char[] rTrimChars) {
    int len = s.length();
    int st = 0;
    int off = 0;
    while ((st < len) && (ArrayUtils.contains(lTrimChars, s.charAt(off + st)))) {
        st++;
    }
    while ((st < len) && ArrayUtils.contains(rTrimChars, s.charAt(off + len - 1))) {
        len--;
    }
    return ((st > 0) || (len < s.length())) ? s.substring(st, len) : s;
}