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:pl.edu.icm.visnow.lib.utils.vtk.VTKNativeCore.java

private static int vtkToVnCellType(int vtkCellType) {
    int[] vtkCellTypes = new int[] { 1, 3, 5, 9, 10, 14, 13, 12 };
    return ArrayUtils.indexOf(vtkCellTypes, vtkCellType);
}

From source file:ptidej.solver.OccurrenceComponent.java

public static char[] computeSimpleName(final char[] aName) {
    int indexOfMinusSign = ArrayUtils.indexOf(aName, '-');
    if (indexOfMinusSign > 0) {
        return ArrayUtils.subarray(aName, 0, indexOfMinusSign);
    } else {/*  w  w w  . j  a v a  2  s. co m*/
        return aName;
    }
}

From source file:raptor.swt.chess.analysis.AnalysisCommentsGenerator.java

/**
 * Returns the string with natural language description of each advantage in the given vector.
 *///from ww w.j  av a2s.com
static String getAdvantageName(boolean[] advVector) {
    String result = ""; //$NON-NLS-1$
    int multiplicity = getAdvantageMultiplicity(advVector);

    if (multiplicity == 1)
        return advToStringTranslate[ArrayUtils.indexOf(advVector, true)];

    for (int i = 0; i < advVector.length; i++) {
        if (advVector[i] && multiplicity >= 3) {
            result += advToStringTranslate[i] + ", "; //$NON-NLS-1$
            multiplicity--;
        } else if (advVector[i] && multiplicity == 2) {
            result += advToStringTranslate[i] + L10n.getStringS("AnalysisCommentsGenerator_10"); //$NON-NLS-1$
            multiplicity--;
        } else if (advVector[i] && multiplicity == 1) {
            result += advToStringTranslate[i];
            break;
        }
    }
    return result;
}

From source file:rascal.object.AbstractObjectFactory.java

public GitObject createObject(String name) throws IOException, CorruptedObjectException {
    ReadableByteChannel channel = getChannel(name);
    byte[] buffer = new byte[OBJECT_HEADER_BUFFER_LENGTH];
    channel.read(ByteBuffer.wrap(buffer));
    channel.close();//w  ww .j  a v a  2 s .  com
    int headerSpaceIndex;
    int headerEndIndex;
    if ((headerSpaceIndex = ArrayUtils.indexOf(buffer, (byte) ' ')) == ArrayUtils.INDEX_NOT_FOUND
            || (headerEndIndex = ArrayUtils.indexOf(buffer, (byte) 0)) == ArrayUtils.INDEX_NOT_FOUND
            || headerSpaceIndex >= headerEndIndex) {
        throw new CorruptedObjectException(name, "Corrupted object header");
    }
    try {
        return createObject(name, buffer, headerSpaceIndex, headerEndIndex);
    } catch (UnknownObjectTypeException e) {
        throw new CorruptedObjectException(name, e);
    } catch (NumberFormatException e) {
        throw new CorruptedObjectException(name, e);
    }
}

From source file:rdfanalyzer.spark.CollapsedGraph.java

public static String main(String[] args) throws Exception {
    String result = "";

    // SQL can be run over RDDs that have been registered as tables.
    DataFrame predicatesFrame = Service.sqlCtx().sql(
            "SELECT t2o AS s, t1p AS p, t4o AS o, Count(*) AS nr FROM (SELECT t1.subject AS t1s, t2.object AS t2o, t1.predicate AS t1p, t1.object AS t1o FROM Graph t1, Graph t2"
                    + " WHERE (t2.predicate = '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') AND t1.subject = t2.subject) MyTable1, "
                    + "(SELECT t3.object AS t3o, t3.subject AS t3s, t3.predicate AS t3p, t4.object AS t4o FROM Graph t3, Graph t4"
                    + " WHERE (t4.predicate = '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') AND t3.object = t4.subject) MyTable2"
                    + " WHERE t1s=t3s AND t1p=t3p AND t1o=t3o GROUP BY t2o, t1p, t4o ORDER BY t1p");

    Row[] resultRows = predicatesFrame.collect();

    // Merge Edgefinder data and format output results. Based on if output
    // is table or chart it is returned into different formats.
    result = "<table class=\"table table-striped\">";
    result += "<thead><tr><th style=\"text-align: center;\">Subject</th><th style=\"text-align: center;\">Predicate</th><th style=\"text-align: center;\">Object</th><th style=\"text-align: center;\">Nr. of occurencies</th></tr></thead>";

    Set<String> subjects = new HashSet<String>();
    String predicate = "";
    Set<String> objects = new HashSet<String>();
    Long sum = (long) 0.0;
    cachedData.clear();/*  www .  j  a  v  a 2s  .  c om*/

    for (Row r : resultRows) {
        if (!predicate.equals(r.getString(1))) {
            if (!predicate.equals("")) {
                result += generateRow(subjects, predicate, objects, sum, args[1]);
            }

            predicate = r.getString(1);
            subjects.clear();
            objects.clear();
            sum = (long) 0.0;
        }

        subjects.add(r.getString(0));
        objects.add(r.getString(2));
        sum += r.getLong(3);
    }

    result += generateRow(subjects, predicate, objects, sum, args[1]);
    result += "</table>";

    if (args[1].equals("Table")) {
        return result;
    } else {
        result = "";
        Set<String> classNames = new HashSet<String>();

        for (CollapsedEntry objEntry : cachedData) {
            String tempClass = "";

            for (String s : objEntry.subjects) {
                tempClass += RDFgraph.shortenURI(s) + "-";
            }

            tempClass = tempClass.substring(0, tempClass.length() - 1);
            classNames.add(tempClass);
            tempClass = "";

            for (String o : objEntry.objects) {
                tempClass += RDFgraph.shortenURI(o) + "-";
            }

            tempClass = tempClass.substring(0, tempClass.length() - 1);
            classNames.add(tempClass);
        }

        int[][] matrix = new int[classNames.size()][classNames.size()];

        for (int[] row : matrix) {
            Arrays.fill(row, 0);
        }

        String[] classNamesArray = new String[classNames.size()];
        String strClasses = "";
        int k = 0;

        for (String s : classNames) {
            strClasses += s + ",";
            classNamesArray[k] = s;

            k++;
        }

        for (CollapsedEntry objEntry : cachedData) {
            String class1 = "";
            String class2 = "";
            Long nrEntries = objEntry.sum;

            for (String s : objEntry.subjects) {
                class1 += RDFgraph.shortenURI(s) + "-";
            }

            class1 = class1.substring(0, class1.length() - 1);

            for (String o : objEntry.objects) {
                class2 += RDFgraph.shortenURI(o) + "-";
            }

            class2 = class2.substring(0, class2.length() - 1);

            matrix[ArrayUtils.indexOf(classNamesArray, class1)][ArrayUtils.indexOf(classNamesArray,
                    class2)] += Integer.parseInt(Long.toString(nrEntries));
        }

        for (int i = 0; i < classNames.size(); i++) {
            for (int j = 0; j < classNames.size(); j++) {
                result += Integer.toString(matrix[i][j]) + ",";
            }

            result = result.substring(0, result.length() - 1);
            result += "$";
        }

        strClasses = strClasses.substring(0, strClasses.length() - 1);
        result = result.substring(0, result.length() - 1);
        result += "&" + strClasses;

        return result;
    }

}

From source file:rdfanalyzer.spark.EdgeFinder.java

public static String main(String[] args) throws Exception {
    String result = "";

    // Read graph from parquet
    DataFrame graphFrame = Service.sqlCtx().parquetFile(Configuration.storage() + args[0] + ".parquet");
    graphFrame.cache().registerTempTable("Graph");

    // Run SQL over loaded Graph.
    DataFrame resultsFrame = Service.sqlCtx().sql(
            "SELECT t2o AS s, t1p AS p, t4o AS o, Count(*) AS nr FROM (SELECT t1.subject AS t1s, t2.object AS t2o, t1.predicate AS t1p, t1.object AS t1o FROM Graph t1, Graph t2"
                    + " WHERE (t2.predicate = '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') AND t1.subject = t2.subject) MyTable1, "
                    + "(SELECT t3.object AS t3o, t3.subject AS t3s, t3.predicate AS t3p, t4.object AS t4o FROM Graph t3, Graph t4"
                    + " WHERE (t4.predicate = '<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') AND t3.object = t4.subject) MyTable2"
                    + " WHERE t1s=t3s AND t1p=t3p AND t1o=t3o GROUP BY t2o, t1p, t4o");

    // Format output based on if output is table or chart
    Row[] resultRows = resultsFrame.collect();

    if (args[1].equals("Table")) {
        result = "<table class=\"table table-striped\">";
        result += "<thead><tr><th style=\"text-align: center;\">Subject</th><th style=\"text-align: center;\">Predicate</th><th style=\"text-align: center;\">Object</th><th style=\"text-align: center;\">Nr. of occurencies</th></tr></thead>";

        for (Row r : resultRows) {
            result += "<tr><td data-toggle=\"tooltip\" title=\"" + r.getString(0) + "\">"
                    + RDFgraph.shortenURI(r.getString(0)) + "</td><td data-toggle=\"tooltip\" title=\""
                    + r.getString(1) + "\">" + RDFgraph.shortenURI(r.getString(1))
                    + "</td><td data-toggle=\"tooltip\" title=\"" + r.getString(2) + "\">"
                    + RDFgraph.shortenURI(r.getString(2)) + "</td><td>" + Long.toString(r.getLong(3))
                    + "</td></tr>";
        }//  w  ww .  j ava  2 s  .com

        result += "</table>";
    } else if (args[1].equals("Chart")) {
        cachedRows = resultRows;

        String strClasses = GetClasses.main(args);
        String[] classNames = strClasses.split(",");

        int[][] matrix = new int[classNames.length][classNames.length];

        for (int[] row : matrix) {
            Arrays.fill(row, 0);
        }

        for (Row r : resultRows) {
            matrix[ArrayUtils.indexOf(classNames, RDFgraph.shortenURI(r.getString(0)))][ArrayUtils
                    .indexOf(classNames, RDFgraph.shortenURI(r.getString(2)))] += Integer
                            .parseInt(Long.toString(r.getLong(3)));
        }

        for (int i = 0; i < classNames.length; i++) {
            for (int j = 0; j < classNames.length; j++) {
                result += Integer.toString(matrix[i][j]) + ",";
            }

            result = result.substring(0, result.length() - 1);
            result += "$";
        }

        result = result.substring(0, result.length() - 1);
        result += "&" + strClasses;
    }

    return result;
}

From source file:sernet.verinice.rcp.accountgroup.GroupView.java

private void updateAccountList() {
    if (accountGroupDataService != null && accountGroupDataService.getAllAccounts() != null) {
        accounts = accountGroupDataService.getAllAccounts();
        // remove accounts that are enlisted in tableToGroupAccounts
        for (String account : accountsInGroup) {
            if (ArrayUtils.contains(accounts, account)) {
                accounts = (String[]) ArrayUtils.remove(accounts, ArrayUtils.indexOf(accounts, account));
            }//from  w w w . ja  v a 2 s.c  o  m
        }
        Arrays.sort(accounts, COLLATOR);
        tableAccounts.setInput(accounts);
    }
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.inspector.InspectionTab.java

protected List<Dataset> sliceAxes(List<AxisChoice> axes, Slice[] slices, boolean[] average, int[] order) {
    List<Dataset> slicedAxes = new ArrayList<Dataset>();

    boolean[] used = getUsedDims();
    for (int o : order) {
        if (used[o]) {
            AxisChoice c = axes.get(o);/*from   ww  w  .j  a v a2 s .  c o m*/
            int[] imap = c.getIndexMapping();

            // We need to reorder multidimensional axis values to match reorder data  
            int[] reorderAxesDims = new int[imap.length];
            for (int i = 0, j = 0; i < order.length && j < imap.length; i++) {
                int idx = ArrayUtils.indexOf(imap, order[i]);
                if (idx != ArrayUtils.INDEX_NOT_FOUND)
                    reorderAxesDims[j++] = idx;
            }

            ILazyDataset axesData = c.getValues();
            int[] shape = axesData.getShape();
            Slice[] s = new Slice[imap.length];
            for (int i = 0; i < s.length; i++) {
                Slice ts = slices[imap[i]];
                if (ts.getLength() <= shape[i]) {
                    s[i] = ts.clone();
                    if (average[imap[i]]) {
                        Integer start = s[i].getStart();
                        start = start == null ? 0 : start;
                        s[i].setStop(start + 1);
                    }
                }
            }

            Dataset slicedAxis = DatasetUtils.convertToDataset(axesData.getSlice(s));

            Dataset reorderdAxesData = slicedAxis.getTransposedView(reorderAxesDims);
            //            reorderdAxesData.setName(axesData.getName());

            reorderdAxesData.setName(c.getLongName());

            slicedAxes.add(reorderdAxesData.squeeze());
        }
    }

    return slicedAxes;
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.multiview.MultiPlotViewTestBase.java

/**
 * @param plotName/*from  w  w  w .j  a  v  a  2  s. com*/
 *            plot name to test
 * @return true if there is a {@link IPlotWindowManager#getOpenViews()} contains plotName
 */
public static boolean isPlotWindowManagerHave(String plotName) {
    String[] openViews = PlotWindow.getManager().getOpenViews();
    return ArrayUtils.indexOf(openViews, plotName) != -1;
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.plotting.multiview.PlotWindowManagerPluginTestAbstract.java

@Test
public void testOpenUniqueView() {
    // we don't know the name of the view until we open it
    // so save all the views ahead of time and make sure after
    // the fact//from  w  w  w  .jav  a2s  .  c om
    Set<String> viewRefsBefore = getAllMultiPlotViews();
    String[] openViewsBefore = PlotWindow.getManager().getOpenViews();

    // open new view with unique name
    String uniqueViewName = openView(null, null);

    // make sure it is open
    Assert.assertTrue(isMultiplePlotViewReferenced(uniqueViewName));
    Assert.assertTrue(isPlotWindowManagerHave(uniqueViewName));
    // and make sure it wasn't open before we asked it to be open
    Assert.assertFalse(viewRefsBefore.contains(uniqueViewName));
    Assert.assertTrue(ArrayUtils.indexOf(openViewsBefore, uniqueViewName) == -1);
}