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:net.geoprism.dashboard.DashboardMap.java

/**
 * MdMethod/*from  w  w w . ja  va2s .  c  o m*/
 * 
 * Invoked after the user reorders a layer via drag+drop in the dashboard viewer.
 * 
 * @return The JSON representation of the current DashboardMap.
 */
@Override
@Transaction
public java.lang.String orderLayers(java.lang.String[] layerIds) {
    if (layerIds == null || layerIds.length == 0) {
        throw new RuntimeException("Unable to order layers, the layerIds array is either null or empty.");
    }

    HasLayerQuery q = new HasLayerQuery(new QueryFactory());
    q.WHERE(q.parentId().EQ(this.getId()));
    q.AND(q.childId().IN(layerIds));

    OIterator<? extends HasLayer> iter = q.getIterator();

    try {
        while (iter.hasNext()) {
            HasLayer rel = iter.next();
            rel.appLock();
            rel.setLayerIndex(ArrayUtils.indexOf(layerIds, rel.getChildId()) + 1);
            rel.apply();
        }
    } finally {
        iter.close();
    }

    this.reorderLayers();

    return "";
}

From source file:com.jaspersoft.studio.property.descriptor.returnvalue.InputReturnValueDialog.java

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    createFromVariable(container);//w  ww .j a  va  2  s. c  o m
    createToVariable(container);

    Label calculationLabel = new Label(container, SWT.NONE);
    calculationLabel.setText(Messages.RVPropertyPage_calculation_type);

    calculation = new Combo(container, SWT.READ_ONLY);
    calculation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    calculation.setItems(calculationValues);

    Label incrementLabel = new Label(container, SWT.NONE);
    incrementLabel.setText(Messages.RVPropertyPage_incrementer_factory_class);

    Composite incrementContainer = new Composite(container, SWT.NONE);
    GridLayout incrementContainerLayout = new GridLayout(2, false);
    incrementContainerLayout.horizontalSpacing = 0;
    incrementContainerLayout.verticalSpacing = 0;
    incrementContainerLayout.marginWidth = 0;
    incrementContainerLayout.marginHeight = 0;
    incrementContainer.setLayout(incrementContainerLayout);
    incrementContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    incrementText = new Text(incrementContainer, SWT.BORDER);
    incrementText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button incrementButton = new Button(incrementContainer, SWT.NONE);
    incrementButton.setText("..."); //$NON-NLS-1$
    incrementButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectionDialog dialog;
            try {
                dialog = JavaUI.createTypeDialog(getShell(), new ProgressMonitorDialog(getShell()),
                        getIncrementContext(), IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES,
                        false);
                dialog.setTitle(Messages.ClassTypeCellEditor_open_type);
                dialog.setMessage(Messages.ClassTypeCellEditor_dialog_message);
                if (dialog.open() == Window.OK) {
                    if (dialog.getResult() != null && dialog.getResult().length > 0) {
                        IType bt = (IType) dialog.getResult()[0];
                        incrementText.setText(bt.getFullyQualifiedName());
                    }
                }
            } catch (JavaModelException e1) {
                e1.printStackTrace();
            }
        }
    });

    //INITIALIZE THE WIDGET WITH THE CONTENT OF THE CONTAINER IF IT IS VALID

    if (rvContainer.getCalculation() != null) {
        int index = ArrayUtils.indexOf(CalculationEnum.values(), rvContainer.getCalculation());
        if (index == ArrayUtils.INDEX_NOT_FOUND)
            index = 0;
        calculation.select(index);
    }

    if (rvContainer.getIncrementerFactoryClassName() != null)
        incrementText.setText(rvContainer.getIncrementerFactoryClassName());

    //ADD THE MODIFY LISTENER AT THE END TO AVOID THAT IT'S CALLED DURING THE INITIALIZATION

    initializeVariables();
    incrementText.addModifyListener(widgetModified);
    calculation.addModifyListener(widgetModified);
    updateContainer();
    return container;
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapWithIndexesResourceEStoreImpl.java

@Override
public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) {
    return ArrayUtils.indexOf(toArray(object, feature), value);
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapWithIndexesResourceEStoreImpl.java

@Override
public int lastIndexOf(InternalEObject object, EStructuralFeature feature, Object value) {
    return ArrayUtils.indexOf(toArray(object, feature), value);
}

From source file:com.ecbeta.common.util.JSONUtils.java

public static boolean isIn(JSONObject obj, JSONObject search) {
    if (!search.has("value")) {
        return true;
    }//from w  w  w . ja va2  s  .c  o m
    try {
        expectOne(search, "field", "type", "operator");
        String operator = search.getString("operator");
        String field = search.getString("field");
        String type = search.getString("type");
        expectMore(search, "value");
        JSONArray value = search.getJSONArray("value");
        String v0 = value.getString(0);
        String v1 = value.size() > 1 ? value.getString(1) : null;
        String sf = obj.getString(field);

        if ("text".equals(type)) {
            if ("contains".equals(operator)) {
                if (obj.has(field) && sf.contains(v0)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("begins".equals(operator)) {
                if (obj.has(field) && sf.startsWith(v0)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("ends".equals(operator)) {
                if (obj.has(field) && sf.endsWith(v0)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("is".equals(operator)) {
                if (obj.has(field) && sf.equals(v0)) {
                    return true;
                } else {
                    return false;
                }
            }
        } else if ("int".equals(type) || "float".equals(type)) {
            if ("is".equals(operator)) {
                if (obj.has(field) && obj.getDouble(field) == Double.parseDouble(v0)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("between".equals(operator)) {
                if (obj.has(field) && obj.getDouble(field) >= Double.parseDouble(v0)
                        && obj.getDouble(field) <= Double.parseDouble(v1)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("in".equals(operator)) {
                if (obj.has(field) && ArrayUtils.indexOf(value.toArray(), sf) >= 0) {
                    return true;
                } else {
                    return false;
                }
            } else if ("not in".equals(operator)) {
                if (obj.has(field) && ArrayUtils.indexOf(value.toArray(), sf) < 0) {
                    return true;
                } else {
                    return false;
                }
            }
        } else if ("date".equals(type)) {
            if ("is".equals(operator)) {
                if (obj.has(field) && obj.getLong(field) == Long.parseLong(v0)) {
                    return true;
                } else {
                    return false;
                }
            } else if ("between".equals(operator)) {
                if (obj.has(field) && obj.getLong(field) >= Long.parseLong(v0)
                        && obj.getLong(field) <= Long.parseLong(v1)) {
                    return true;
                } else {
                    return false;
                }
            }
        } else {
            if ("is".equals(operator)) {
                if (obj.has(field) && obj.getLong(field) == Long.parseLong(v0)) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "{0}", e);
    }

    /*   
       field    : '',    // search field name
       value    : '',    // string or array of string with values
       operator : 'is',  // search operator [is, in, between, begins with, contains, ends with]
       type     : ''     // data type, [text, int, float, date]
    */ /*       "field": ["qqName"],
        "type": ["text"],
        "value": ["A"],
        "operator": ["contains"]*/
    return true;
}

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

protected Field buildField(PropertyAccessor propertyAccessor) {
    Field field = null;// w  w w. j  av a2  s .  c o  m
    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 SelectField(propertyAccessor, current.getValue(), mode, prefix);
            break;
        }
    }
    if (field == null) {
        field = manager.tryToInstantiateField(classAccessor, propertyAccessor, mode, prefix);
    }

    if (field == null) {
        logger.warn("Cannot instanciate field for property {}", propertyAccessor);
    }
    return field;
}

From source file:com.kbotpro.randoms.GraveDigger.java

/**
 * Gets called if canRun() returns true.
 *///from w  w  w  .  j a  va2 s.  c o  m
public synchronized void onStart() {
    finished = false;
    tookAllCoffins = false;
    id = -1;
    idx = -1;
    KTimer timeout = new KTimer(600000);
    main: while (!botEnv.randomManager.scriptStopped && isLoggedIn() && !timeout.isDone()
            && (mausoleum = objects.getClosestObject(20, MAUSOLEUM_ID)) != null) {
        IComponent iface;
        if (getMyPlayer().isMoving() || getMyPlayer().getAnimation() != -1) {
            sleep(50, 100);
            continue;
        } else if (interfaces.clickContinue()) {
            sleep(900, 1200);
            continue;
        }
        IComponent[] leftValuables = interfaces.getInterfaces("No - I haven't left any valuables");
        if (leftValuables.length > 0 && leftValuables[0].isVisible()) {
            leftValuables[0].doClick();
            sleep(900, 1200);
            continue;
        } else if ((iface = getIComponent("Yes, ")) != null && iface.isValid() && iface.isVisible()) {
            iface.doClick();
            sleep(500, 800);
            continue;
        } else if ((iface = interfaces.getComponent(INSTRUCTION_INTERFACE, CLOSE_CHILD_ID)) != null
                && iface.isVisible()) {
            iface.doClick();
            sleep(500, 800);
            continue;
        }
        if (game.getCurrentTab() != Game.TAB_INVENTORY && !interfaces.interfaceExists(11)) {
            game.openTab(Game.TAB_INVENTORY);
            sleep(random(800, 1200));
            continue;
        }
        if ((inventory.getCount() - inventory.getCount(false, COFFIN_IDS)) > 23
                || interfaces.interfaceExists(11)) {
            if (!interfaces.interfaceExists(11)) {
                PhysicalObject o = objects.getClosestObject(30, DEPOSIT_BOX);
                if (o != null) {
                    if (getDistanceTo(o.getLocation()) > 5 || !o.onScreen()) {
                        walking.walkToMM(o.getLocation());
                    }
                    camera.setAngle(camera.getAngleTo(o.getLocation()));
                    o.doAction("Deposit");
                    sleep(random(800, 1200));
                    continue;
                }
            } else {
                IComponent[] deposit = interfaces.getComponent(11, 17).getChildren();
                int depositedCount = 0;
                for (IComponent i : deposit) {
                    if (depositedCount >= 5)
                        break;
                    if (i.getElementID() != -1 && !getAllDoNoDeposit().contains(i.getElementID())
                            && i.getElementStackSize() == 1) {
                        if (i.doAction("Deposit-1")) {
                            depositedCount++;
                        }
                    }
                }
                if (depositedCount == 0) {
                    interfaces.getComponent(11, 18).doClick();
                }
                interfaces.getComponent(11, 15).doClick();
                sleep(1000, 2000);
                continue;

            }
        }
        if (finished) {
            NPC leo = npcs.getClosest(20, LEO_ID);
            if (leo.onScreen()) {
                if (game.hasSelectedItem()) {
                    menu.atMenu("Cancel");
                }
                leo.doAction("talk");
            } else
                walking.walkToMM(leo.getLocation());
        } else if (tookAllCoffins) {
            // Dunno if this bit will work! curGrave.getUID() == objects.getObjectAt(curGrave.getLocation().getUID()))
            if (curGrave != null
                    && curGrave.getID() == objects.getObjectsAt(curGrave.getLocation())[0].getID()) {
                if (idx != -1) { //We know the grave's index somethingy...
                    if (id != -1) { //We know the coffin id, lets use it on the grave
                        if (curGrave.onScreen()) {
                            inventory.atItem(id, "Use");
                            sleep(50, 100);
                            if (curGrave.doAction("Use")) {
                                waitForAnimation(827);
                            }
                        } else {
                            walking.walkToMM(curGrave.getLocation());
                        }
                    } else { //We don't know the coffin id, lets find it out
                        for (Item coffin : inventory.getItems()) {
                            if (ArrayUtils.contains(COFFIN_IDS, coffin.getID())) {
                                inventory.atItem(coffin.getID(), "Check");
                                sleep(1500, 3000);
                                if (idx == getCoffinIndex()) {
                                    id = coffin.getID();
                                    while (interfaces.getComponent(COFFIN_INTERFACE_ID, 12) != null
                                            && !clickExit(interfaces.getComponent(COFFIN_INTERFACE_ID, 12))) {
                                        sleep(800, 1200);
                                    }
                                    continue main;
                                }
                            }
                        }
                    }
                } else { //We don't know the grave's index somethingy, lets find it out
                    int graveIdx = ArrayUtils.indexOf(EMPTY_GRAVE_IDS, curGrave.getID());
                    if (curStone != null && curStone.getID() == objects
                            .getClosestObject(20, GRAVESTONE_IDS[graveIdx]).getID()) {
                        if (getGravestoneIndex() != -1) {
                            idx = getGravestoneIndex();
                            while (interfaces.getComponent(GRAVESTONE_INTERFACE_ID, 3) != null
                                    && clickExit(interfaces.getComponent(GRAVESTONE_INTERFACE_ID, 3))) {
                                //clickExit(interfaces.getComponent(GRAVESTONE_INTERFACE_ID, 3));
                                sleep(800, 1200);
                            }
                        } else {
                            if (curStone.onScreen()) {
                                if (game.hasSelectedItem()) {
                                    menu.atMenu("Cancel");
                                }
                                //curStone.doAction("Read");
                                mouse.moveMouse(curStone.getScreenPos());
                                menu.atMenu("Read");
                            } else
                                walking.walkToMM(curStone.getLocation());
                        }
                    } else {
                        curStone = objects.getClosestObject(20, GRAVESTONE_IDS[graveIdx]);
                        sleep(50, 100);
                        continue main;
                    }
                }
            } else {
                id = -1;
                idx = -1;
                curGrave = objects.getClosestObject(20, EMPTY_GRAVE_IDS);
                if (curGrave == null)
                    finished = true;
                sleep(50, 100);
                continue main;
            }
        } else {
            //PhysicalObject obj = objects.getClosestObject(20, FILLED_GRAVE_IDS);
            PhysicalObject obj = getClosestObj(FILLED_GRAVE_IDS);

            if (obj != null) {
                if (obj.onScreen()) {
                    //obj.doAction("Take-coffin");
                    mouse.moveMouse(obj.getScreenPos());
                    sleep(10, 50);
                    if (botEnv.menu.atMenu("Take-coffin")) {
                        waitForAnimation(827);
                    }
                } else
                    walking.walkToMM(obj.getLocation());
            } else {
                tookAllCoffins = true;
            }
        }
        sleep(1000, 2000);
    }
    sleep(1000, 2000);
    while (game.getGameState() == 25)
        sleep(500, 1000);
    if (interfaces.canContinue()) {
        interfaces.clickContinue();
        sleep(1000, 2000);
    }
    if (timeout.isDone()) {
        botEnv.scriptManager.stopAllScripts();
    }
}

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

private Field buildField(PropertyAccessor propertyAccessor, String rowPrefix) {
    Field field = null;/*from   w  w  w.  jav a 2s.c o m*/
    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 SelectField(propertyAccessor, mode, rowPrefix);
            break;
        }
    }
    if (field == null) {
        field = manager.tryToInstantiateField(classAccessor, propertyAccessor, mode, rowPrefix);
    }

    return field;
}

From source file:fr.inria.atlanmod.neoemf.map.datastore.estores.impl.DirectWriteMapResourceEStoreImpl.java

@Override
public int indexOf(InternalEObject object, EStructuralFeature feature, Object value) {
    PersistentEObject neoEObject = NeoEObjectAdapterFactoryImpl.getAdapter(object, PersistentEObject.class);
    Object[] array = (Object[]) getFromMap(neoEObject, feature);
    if (array == null) {
        return -1;
    }/*from ww  w  . ja  va 2s .c o  m*/
    if (feature instanceof EAttribute) {
        return ArrayUtils.indexOf(array, serializeToMapValue((EAttribute) feature, value));
    } else {
        PersistentEObject childEObject = NeoEObjectAdapterFactoryImpl.getAdapter(value,
                PersistentEObject.class);
        return ArrayUtils.indexOf(array, childEObject.id());
    }
}

From source file:com.pureinfo.srm.reports.table.data.ProductStatistic.java

private void initProductForms() throws PureException {
    List forms = NamedValueHelper.getNamedValues(SRMNamedValueTypes.PRODUCT_FORM, true);
    m_productForms = MyTabeleDataHelper.list2Strings(forms, "value", "name");
    String[][] temp = new String[2][m_productIds.length];
    for (int i = 0; i < m_productIds.length; i++) {
        temp[0][i] = m_productIds[i];//from w w w. ja va2  s.c  om
        int idx = ArrayUtils.indexOf(m_productForms[0], m_productIds[i]);
        temp[1][i] = m_productForms[1][idx];
    }
    m_productForms = temp;
}