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

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

Introduction

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

Prototype

int INDEX_NOT_FOUND

To view the source code for org.apache.commons.lang ArrayUtils INDEX_NOT_FOUND.

Click Source Link

Document

The index value when an element is not found in a list or array: -1.

Usage

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();/*from  w w  w.  java  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: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  w  w  w.  ja  v a 2 s  .  co 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;
}