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

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

Introduction

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

Prototype

public static int indexOf(boolean[] array, boolean valueToFind) 

Source Link

Document

Finds the index of the given value in the array.

Usage

From source file:com.aionemu.gameserver.restrictions.RestrictionsManager.java

public synchronized static void deactivate(Restrictions restriction) {
    for (RestrictionMode mode : RestrictionMode.VALUES) {
        Restrictions[] restrictions = RESTRICTIONS[mode.ordinal()];

        for (int index; (index = ArrayUtils.indexOf(restrictions, restriction)) != -1;) {
            restrictions = (Restrictions[]) ArrayUtils.remove(restrictions, index);
        }//from www .  ja v a2 s .c  o m

        RESTRICTIONS[mode.ordinal()] = restrictions;
    }
}

From source file:com.wsc.myexample.decisionForest.MyDataset.java

/**
 * Returns the code used to represent the label value in the data
 *
 * @param label label's value to code/*  w  ww.  java 2s. c o  m*/
 * @return label's code
 */
public int labelCode(String label) {
    return ArrayUtils.indexOf(values[labelId], label);
}

From source file:com.bstek.dorado.idesupport.RuleSetBuilderTest.java

public void testOutputAndParse() throws Exception {
    RuleTemplateManager ruleTemplateManager = getRuleTemplateBuilder().getRuleTemplateManager();

    byte[] byteArray = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(out);
    try {//  w  w  w .j ava  2 s . c o m
        getRuleSetOutputter().output(writer, ruleTemplateManager);
        byteArray = out.toByteArray();
    } finally {
        writer.close();
        out.close();
    }

    assertNotNull(byteArray);
    InputStream in = new ByteArrayInputStream(byteArray);
    try {
        RuleSet ruleSet = getRuleSetBuilder().buildRuleSet(in);
        assertNotNull(ruleSet);
        assertFalse(ruleSet.getRuleMap().isEmpty());

        List<PackageInfo> packageInfos = ruleSet.getPackageInfos();
        assertNotNull(packageInfos);
        assertTrue(!packageInfos.isEmpty());

        Rule modelRule = ruleSet.getRule("Model");
        assertNotNull(modelRule);

        Map<String, Child> children = modelRule.getChildren();
        assertTrue(children.size() >= 3);

        Child dataTypeChild = children.get("DataType");
        Rule dataTypeRule = dataTypeChild.getRule();
        assertNotNull(dataTypeRule);
        assertEquals("DataType", dataTypeRule.getNodeName());

        Child dataProviderChild = children.get("DataProvider");
        Rule dataProviderRule = dataProviderChild.getRule();
        assertNotNull(dataProviderRule);

        Rule propertyDefRule = ruleSet.getRule("PropertyDef");
        assertNotNull(propertyDefRule);

        Child validatorChild = propertyDefRule.getChild("Validator");
        assertNotNull(validatorChild);
        System.out.println("Children of ValidotorRule: ");
        Set<Rule> validatorRules = validatorChild.getConcreteRules();
        for (Rule validatorRule : validatorRules) {
            System.out.println(validatorRule.getName() + " : " + validatorRule.getNodeName());
        }

        Property mappingProperty = propertyDefRule.getProperty("mapping");
        assertNotNull(mappingProperty);
        assertTrue(mappingProperty.getCompositeType() == CompositeType.Fixed);
        assertEquals(3, mappingProperty.getProperties().size());

        Rule buttonRule = ruleSet.getRule("Button");
        assertNotNull(buttonRule);
        Property property = buttonRule.getProperty("action");
        assertNotNull(property);
        assertEquals("Action", property.getReference().getRule().getName());

        Rule abstractButtonRule = ruleSet.getRule("AbstractButton");
        assertNotNull(abstractButtonRule);
        assertTrue(ArrayUtils.indexOf(buttonRule.getParents(), abstractButtonRule) >= 0);

        boolean hasButtonRule = false;
        Rule[] concretButtonRules = abstractButtonRule.getSubRules();
        for (Rule concretButtonRule : concretButtonRules) {
            String name = concretButtonRule.getName();
            if ("Button".equals(name)) {
                hasButtonRule = true;
            }
        }
        assertTrue(hasButtonRule);

        Rule controlRule = ruleSet.getRule("Control_1");
        assertNotNull(controlRule);
        assertTrue(ArrayUtils.indexOf(abstractButtonRule.getParents(), controlRule) >= 0);

        boolean hasAbstractButtonRule = false;
        Rule[] concretControlRules = controlRule.getSubRules();
        for (Rule concretControlRule : concretControlRules) {
            String name = concretControlRule.getName();
            if ("AbstractButton".equals(name)) {
                hasAbstractButtonRule = true;
            }
        }
        assertTrue(hasAbstractButtonRule);

        Rule floatPanelRule = ruleSet.getRule("FloatPanel");
        assertNotNull(floatPanelRule);
        assertNotNull(floatPanelRule.getChild("Children"));
        assertNotNull(floatPanelRule.getChild("Tools"));
        assertNotNull(floatPanelRule.getChild("Buttons"));

        Property animateTargetProperty = floatPanelRule.getProperty("animateTarget");
        assertNotNull(animateTargetProperty);
        assertFalse(animateTargetProperty.isVisible());

        Rule viewRule = ruleSet.getRule("View");
        for (Child child : viewRule.getChildren().values()) {
            Rule childRule = child.getRule();
            System.out.println(childRule.getName() + " : " + childRule.getNodeName());
        }

        Rule dataTreeGridRule = ruleSet.getRule("DataTreeGrid");
        assertNotNull(dataTreeGridRule);
        property = dataTreeGridRule.getProperty("dataSet");
        assertNotNull(property);
        assertEquals("DataSet", property.getReference().getRule().getName());

        Rule treeRule = ruleSet.getRule("Tree");
        assertNotNull(treeRule);

        Rule customDropDownRule = ruleSet.getRule("CustomDropDown");
        assertNotNull(customDropDownRule);

        Child child = customDropDownRule.getChild("Control");
        assertNotNull(child);

        System.out.println("Children of CustomDropDown: ");
        Set<Rule> concreteRules = child.getConcreteRules();
        for (Rule concreteRule : concreteRules) {
            System.out.println(concreteRule.getName() + " : " + concreteRule.getNodeName());
        }
    } finally {
        in.close();
    }
}

From source file:it.jnrpe.net.JNRPERequestDecoder.java

/**
 * Convert a '0' terminated string to a java string.
 * /*from w w w. j  a v  a  2 s  . c  o  m*/
 * @param buff
 *            the '0' terminated string
        
 * @return the java string */
private String ztString2String(final byte[] buff) {
    return new String(buff, 0, ArrayUtils.indexOf(buff, (byte) 0));
}

From source file:gda.gui.beans.SimpleBinaryBean.java

protected void btnOperateActionPerformed() {
    if (!executeCommand()) {
        return;//from w  ww.j ava  2  s . c o m
    }

    try {
        String[] positions = simpleBinary.getPositions();
        int index = ArrayUtils.indexOf(positions, this.lblState.getText());
        if (index == 0) {
            simpleBinary.moveTo(positions[1]);
        } else {
            simpleBinary.moveTo(positions[0]);
        }
    } catch (DeviceException e) {
        logger.error("exception while GUI bean trying to operate " + simpleBinaryName + ": " + e.getMessage());
    }
}

From source file:it.jnrpe.net.JNRPEProtocolPacket.java

/**
 * @return The string representation of the buffer. 
 *///from   ww  w .j ava 2  s .com
protected String getPacketString() {
    byte[] buffer = getBuffer();
    int zeroIndex = ArrayUtils.indexOf(buffer, (byte) 0);

    if (zeroIndex == ArrayUtils.INDEX_NOT_FOUND) {
        return new String(buffer, charset);
    } else {
        return new String(buffer, 0, zeroIndex, charset);
    }
}

From source file:com.bstek.dorado.core.el.DefaultExpressionHandler.java

protected synchronized static Object createDoradoExpressionUtilsBean(Map<String, Method> utilMethods)
        throws Exception {
    if (doradoExpressionUtilsBean == null) {
        ClassPool pool = ClassPool.getDefault();
        CtClass ctClass = null;//w w w  .j  a  v a2s  . c  om
        try {
            ctClass = pool.get(DORADO_EXPRESSION_UTILS_TYPE);
        } catch (Exception e) {
            // do nothing
        }
        if (ctClass == null) {
            ctClass = pool.makeClass(DORADO_EXPRESSION_UTILS_TYPE);
        }
        for (Map.Entry<String, Method> entry : utilMethods.entrySet()) {
            String name = entry.getKey();
            Method method = entry.getValue();
            int methodIndex = ArrayUtils.indexOf(method.getDeclaringClass().getMethods(), method);

            StringBuffer buf = new StringBuffer();
            StringBuffer args = new StringBuffer();
            buf.append("public ").append("Object").append(' ').append(name).append('(');
            Class<?>[] parameterTypes = method.getParameterTypes();
            for (int i = 0; i < parameterTypes.length; i++) {
                if (i > 0) {
                    buf.append(',');
                    args.append(',');
                }
                buf.append("Object").append(' ').append("p" + i);
                args.append("p" + i);
            }
            buf.append(")");
            if (method.getExceptionTypes().length > 0) {
                buf.append(" throws ");
                int i = 0;
                for (Class<?> exceptionType : method.getExceptionTypes()) {
                    if (i > 0)
                        buf.append(',');
                    buf.append(exceptionType.getName());
                    i++;
                }
            }
            buf.append("{\n").append("return Class.forName(\"" + method.getDeclaringClass().getName())
                    .append("\").getMethods()[").append(methodIndex).append("].invoke(null, new Object[]{")
                    .append(args).append("});").append("\n}");
            CtMethod delegator = CtNewMethod.make(buf.toString(), ctClass);
            delegator.setName(name);
            ctClass.addMethod(delegator);
        }
        Class<?> cl = ctClass.toClass();
        doradoExpressionUtilsBean = cl.newInstance();
    }
    return doradoExpressionUtilsBean;
}

From source file:com.wsc.myexample.decisionForest.MyDataset.java

/**
 * Converts a token to its corresponding int code for a given attribute
 *
 * @param attr attribute's index/*from www . j  a v  a2  s . c  o m*/
 */
public int valueOf(int attr, String token) {
    Preconditions.checkArgument(!isNumerical(attr), "Only for CATEGORICAL attributes");
    Preconditions.checkArgument(values != null, "Values not found");
    return ArrayUtils.indexOf(values[attr], token);
}

From source file:com.manydesigns.elements.forms.SearchFormBuilder.java

public SearchForm build() {
    logger.debug("build");

    SearchForm searchForm = new SearchForm();
    FieldsManager manager = FieldsManager.getManager();

    if (propertyAccessors == null) {
        configReflectiveFields();/*from  w ww . j av a  2  s  .  c  o m*/
    }

    Map<String, SearchField> fieldMap = new HashMap<String, SearchField>();
    for (PropertyAccessor propertyAccessor : propertyAccessors) {
        SearchField field = null;
        String fieldName = propertyAccessor.getName();

        for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {

            String[] fieldNames = current.getKey();
            int index = ArrayUtils.indexOf(fieldNames, fieldName);
            if (index >= 0) {
                field = new SelectSearchField(propertyAccessor, current.getValue(), prefix);
                break;
            }
        }

        if (field == null) {
            field = manager.tryToInstantiateSearchField(classAccessor, propertyAccessor, prefix);
        }

        if (field == null) {
            logger.warn("Cannot instanciate field for property {}", propertyAccessor);
            continue;
        }
        fieldMap.put(fieldName, field);
        searchForm.add(field);
    }

    // handle cascaded select fields
    for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
        String[] fieldNames = current.getKey();
        SelectionProvider selectionProvider = current.getValue();
        SelectionModel selectionModel = selectionProvider.createSelectionModel();

        SelectSearchField previousField = null;
        for (int i = 0; i < fieldNames.length; i++) {
            SelectSearchField selectSearchField = (SelectSearchField) fieldMap.get(fieldNames[i]);
            if (selectSearchField == null) {
                previousField = null;
                continue;
            }
            selectSearchField.setSelectionModel(selectionModel);
            selectSearchField.setSelectionModelIndex(i);
            if (previousField != null) {
                selectSearchField.setPreviousSelectField(previousField);
                previousField.setNextSelectField(selectSearchField);
            }
            previousField = selectSearchField;
        }
    }

    return searchForm;
}

From source file:com.pureinfo.srm.project.action.finish.ProjectBatchFinishAction.java

/**
 * //from www  . j a v a  2  s  . c  o  m
 * 
 * @param _prjFinish
 *            
 * @param _nIndex
 *            
 * @return
 * @throws PureException
 */
private boolean checkCanFinish(ProjectFinish _prjFinish, int _nIndex) throws PureException {
    int nProjectId = _prjFinish.getProjectId();

    // projectId 
    if (nProjectId < 0) {
        msgs[_nIndex] = (_nIndex + 1) + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>,</font>"
                + nProjectId;
        return false;
    }

    Project project = (Project) prjMgr.lookupById(nProjectId);

    // project 
    if (project == null) {
        msgs[_nIndex] = (_nIndex + 1) + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>,</font>"
                + nProjectId;
        return false;
    }

    // 
    if (ArrayUtils.indexOf(PRJ_STATUSES_CANNOT_FINISH, project.getLStatus()) >= 0) {
        msgs[_nIndex] = (_nIndex + 1)
                + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>,:</font>"
                + project.getProjectName() + "";
        return false;
    }

    // 
    if (!Auth2Helper.getManager().hasRight(loginUser, _prjFinish, ArkActionTypes.ADD, false)) {
        msgs[_nIndex] = (_nIndex + 1)
                + "&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>,:</font>"
                + project.getProjectName() + "";
        return false;
    }

    return true;
}