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:uk.ac.diamond.scisoft.analysis.rcp.plotting.multiview.PlotWindowManagerPluginTestAbstract.java

@Test
public void testGetOpenViews() {
    // make sure the view is not reported as open
    String[] openViewsBefore = getOpenViews();
    Assert.assertTrue(ArrayUtils.indexOf(openViewsBefore, VIEW_NAME) == -1);

    // Open an additional view
    testOpenView();/* w w w.j  av  a 2s  .c  o m*/

    // make sure the view is now reported as open
    String[] openViewsAfter = getOpenViews();
    Assert.assertTrue(ArrayUtils.indexOf(openViewsAfter, VIEW_NAME) >= 0);

}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.rpc.sdaplotter.AllPyPlotMethodsPluginTest.java

@Before
public void checkBefore() throws Exception {
    Assert.assertTrue(ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), viewName) == -1);
    checkPythonState();//from   w w w  .  ja va2s .c o m
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.rpc.sdaplotter.AllPyPlotMethodsPluginTest.java

@After
public void checkAfter() throws Exception {
    checkPythonState();/*from   w  ww.j  av a2 s.c  om*/
    if (!excludePlotServerCheck) {
        Assert.assertTrue(ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), viewName) != -1);
    }
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.rpc.sdaplotter.AutomatedManualPlottingPluginTest.java

@Test
public void testManualPlotTestOverRpcPython() throws Exception {
    // Launch the AnalysisRpc server that receives our requests and sends them back to us
    Assert.assertTrue(/*from   ww  w . j a v  a 2  s .c om*/
            ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), "Plot 1 RPC Python") == -1);
    runPythonFile("manual_plot_test_over_rpc.py", true);
    Assert.assertTrue(
            ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), "Plot 1 RPC Python") != -1);
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.rpc.sdaplotter.AutomatedManualPlottingPluginTest.java

@Test
public void testManualPlotTestPython() throws Exception {
    // Launch the AnalysisRpc server that receives our requests and sends them back to us
    Assert.assertTrue(/*from ww w.  j a  v  a2 s  .  c  o  m*/
            ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), "Plot 1 DNP Python") == -1);
    runPythonFile("manual_plot_test.py", true);
    Assert.assertTrue(
            ArrayUtils.indexOf(PlotServerProvider.getPlotServer().getGuiNames(), "Plot 1 DNP Python") != -1);
}

From source file:uk.ac.diamond.scisoft.ncd.rcp.views.NcdDetectorParameters.java

@Override
public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue) {
    if (sourceName.equals(NcdCalibrationSourceProvider.NCDDETECTORS_STATE)) {
        if ((detListSaxs != null) && (detListWaxs != null) && !(detListSaxs.isDisposed())
                && !(detListWaxs.isDisposed())) {
            int idxSaxs = detListSaxs.getSelectionIndex();
            String saveDetSaxs = null;
            if (idxSaxs != -1) {
                saveDetSaxs = detListSaxs.getItem(idxSaxs);
            }/*from  w w w.  jav a2  s  .c o  m*/
            int idxWaxs = detListWaxs.getSelectionIndex();
            String saveDetWaxs = null;
            if (idxWaxs != -1) {
                saveDetWaxs = detListWaxs.getItem(idxWaxs);
            }
            detListSaxs.removeAll();
            detListWaxs.removeAll();
            if (sourceValue instanceof HashMap<?, ?>) {
                for (Object settings : ((HashMap<?, ?>) sourceValue).values()) {
                    if (settings instanceof NcdDetectorSettings) {

                        NcdDetectorSettings detSettings = (NcdDetectorSettings) settings;

                        if (detSettings.getType().equals(DetectorTypes.SAXS_DETECTOR)) {
                            detListSaxs.add(detSettings.getName());
                            continue;
                        }

                        if (detSettings.getType().equals(DetectorTypes.WAXS_DETECTOR)) {
                            detListWaxs.add(detSettings.getName());
                            continue;
                        }
                    }
                }
            }

            // Restore saved detector selection
            // If no detector was selected, select first one in the list
            // If saved detector selection isn't available in the updated list, select first one
            if (detListSaxs.getItemCount() > 0) {
                idxSaxs = (idxSaxs != -1) ? ArrayUtils.indexOf(detListSaxs.getItems(), saveDetSaxs) : 0;
                idxSaxs = (idxSaxs == -1) ? 0 : idxSaxs;
                detListSaxs.select(idxSaxs);
                ncdSaxsDetectorSourceProvider.setSaxsDetector(detListSaxs.getItem(idxSaxs));
            }

            if (detListWaxs.getItemCount() > 0) {
                idxWaxs = (idxWaxs != -1) ? ArrayUtils.indexOf(detListWaxs.getItems(), saveDetWaxs) : 0;
                idxWaxs = (idxWaxs == -1) ? 0 : idxWaxs;
                detListWaxs.select(idxWaxs);
                ncdWaxsDetectorSourceProvider.setWaxsDetector(detListWaxs.getItem(idxWaxs));
            }
        }

        if (calList != null && !(calList.isDisposed())) {
            int idxSel = calList.getSelectionIndex();
            String saveSelection = ncdScalerSourceProvider.getScaler();
            calList.removeAll();
            if (sourceValue instanceof HashMap<?, ?>) {
                for (Object settings : ((HashMap<?, ?>) sourceValue).values()) {
                    if (settings instanceof NcdDetectorSettings) {

                        NcdDetectorSettings detSettings = (NcdDetectorSettings) settings;

                        if (detSettings.getType().equals(DetectorTypes.CALIBRATION_DETECTOR)) {
                            calList.add(detSettings.getName());
                            continue;
                        }
                    }
                }
            }
            if (calList.getItemCount() > 0) {
                idxSel = (idxSel != -1) ? ArrayUtils.indexOf(calList.getItems(), saveSelection) : 0;
                idxSel = (idxSel == -1) ? 0 : idxSel;
                calList.select(idxSel);
                ncdScalerSourceProvider.setScaler(calList.getItem(idxSel));
                calList.notifyListeners(SWT.Selection, null);
            }
        }
    }

    if (sourceName.equals(NcdProcessingSourceProvider.SAXSDETECTOR_STATE)) {
        if (sourceValue instanceof String) {
            NcdDetectorSettings detSettings = ncdDetectorSourceProvider.getNcdDetectors().get(sourceValue);
            if (detSettings != null) {
                int idxDim = detSettings.getDimension() - 1;
                if (dimSaxs != null && !(dimSaxs[idxDim].isDisposed())) {
                    for (Button btn : dimSaxs)
                        btn.setSelection(false);
                    dimSaxs[idxDim].setSelection(true);
                }
                Amount<Length> pxSize = detSettings.getPxSize();
                if (pxSaxs != null && !(pxSaxs.isDisposed())) {
                    if (pxSize != null) {
                        String pxText = String.format("%.3f", pxSize.doubleValue(SI.MILLIMETRE));
                        if (!(pxText.equals(pxSaxs.getText()))) {
                            pxSaxs.setText(pxText);
                        }
                    } else {
                        pxSaxs.setText("");
                    }
                }
            }
        }
    }

    if (sourceName.equals(NcdProcessingSourceProvider.WAXSDETECTOR_STATE)) {
        if (sourceValue instanceof String) {
            NcdDetectorSettings detSettings = ncdDetectorSourceProvider.getNcdDetectors().get(sourceValue);
            if (detSettings != null) {
                int idxDim = detSettings.getDimension() - 1;
                if (dimWaxs != null && !(dimWaxs[idxDim].isDisposed())) {
                    for (Button btn : dimWaxs)
                        btn.setSelection(false);
                    dimWaxs[idxDim].setSelection(true);
                }
                Amount<Length> pxSize = detSettings.getPxSize();
                if (pxWaxs != null && !(pxWaxs.isDisposed())) {
                    if (pxSize != null) {
                        String pxText = String.format("%.3f", pxSize.doubleValue(SI.MILLIMETRE));
                        if (!(pxText.equals(pxWaxs.getText()))) {
                            pxWaxs.setText(pxText);
                        }
                    } else {
                        pxWaxs.setText("");
                    }
                }
            }
        }
    }

    if (sourceName.equals(NcdProcessingSourceProvider.WAXS_STATE)) {
        if (detTypeWaxs != null && !detTypeWaxs.isDisposed()) {
            boolean tmpBool = detTypeWaxs.getSelection();
            if (sourceValue != null && (Boolean) sourceValue != tmpBool) {
                detTypeWaxs.setSelection((Boolean) sourceValue);

                detListWaxs.setEnabled((Boolean) sourceValue);
                pxWaxs.setEnabled((Boolean) sourceValue);
                pxWaxsLabel.setEnabled((Boolean) sourceValue);
                for (Button dim : dimWaxs)
                    dim.setEnabled((Boolean) sourceValue);
            }
        }
    }
    if (sourceName.equals(NcdProcessingSourceProvider.SAXS_STATE)) {
        if (detTypeSaxs != null && !detTypeSaxs.isDisposed()) {
            boolean tmpBool = detTypeSaxs.getSelection();
            if (sourceValue != null && (Boolean) sourceValue != tmpBool) {
                detTypeSaxs.setSelection((Boolean) sourceValue);

                detListSaxs.setEnabled((Boolean) sourceValue);
                pxSaxs.setEnabled((Boolean) sourceValue);
                pxSaxsLabel.setEnabled((Boolean) sourceValue);
                for (Button dim : dimSaxs)
                    dim.setEnabled((Boolean) sourceValue);
            }
        }
    }

    if (sourceName.equals(NcdProcessingSourceProvider.SCALER_STATE)) {
        if (sourceValue instanceof String) {
            if ((calList != null) && !(calList.isDisposed())) {
                int idxSel = calList.indexOf((String) sourceValue);
                if (idxSel != -1) {
                    calList.select(idxSel);
                } else {
                    return;
                }
            }
            if ((normChan != null) && !(normChan.isDisposed())) {
                NcdDetectorSettings detSettings = ncdDetectorSourceProvider.getNcdDetectors().get(sourceValue);
                if (detSettings != null) {
                    int max = detSettings.getMaxChannel();
                    normChan.setMaximum(max);
                    normChan.setSelection(detSettings.getNormChannel());
                }
            }
        }
    }
}

From source file:v7cr.Review.java

public Review updateVote(BSONBackedObject vote, String newMessage, String rating) {
    BSONBackedObject[] votes = getObjectFieldAsArray("v");
    int idx = ArrayUtils.indexOf(votes, vote);
    if (idx == -1)
        return this;
    votes[idx] = votes[idx].append("c", newMessage).append("v", rating);
    return new Review(unset("v").pushAll("v", votes)).updateStatus();
}

From source file:wzw.lang.ArraySupport.java

public static int indexOf(Object[] array, Object obj) {
    return ArrayUtils.indexOf(array, obj);
}