Example usage for java.util Collections indexOfSubList

List of usage examples for java.util Collections indexOfSubList

Introduction

In this page you can find the example usage for java.util Collections indexOfSubList.

Prototype

public static int indexOfSubList(List<?> source, List<?> target) 

Source Link

Document

Returns the starting position of the first occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.

Usage

From source file:Main.java

public static void main(String args[]) {
    // create two array list objects       
    List<String> arrlistsrc = new ArrayList<String>();
    List<String> arrlisttarget = new ArrayList<String>();

    // populate two lists
    arrlistsrc.add("A");
    arrlistsrc.add("from java2s.com");
    arrlistsrc.add("C");
    arrlistsrc.add("D");
    arrlistsrc.add("E");

    arrlisttarget.add("C");
    arrlisttarget.add("D");
    arrlisttarget.add("E");

    // check target list in source list
    int index = Collections.indexOfSubList(arrlistsrc, arrlisttarget);

    System.out.println("Target list starts at index: " + index);
}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);/*from   w w w  .j  av a 2s .c  o m*/
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}

From source file:Main.java

public static int indexOfSubList(final List<?> list0, final List<?> list1) {
    return Collections.indexOfSubList(list0, list1);
}

From source file:com.github.fge.jsonschema.walk.ResolvingSchemaWalker.java

private static void checkTrees(final SchemaTree tree, final SchemaTree newTree) throws ProcessingException {
    /*/*w  w  w  . j av a2s .  c  o  m*/
     * We can rely on URIs here: at worst the starting URI was empty, but if
     * we actually fetched another schema, it will never be the empty URI. A
     * simple equality check on URIs can immediately tell us whether the
     * schema is the same.
     */
    if (!tree.getLoadingRef().equals(newTree.getLoadingRef()))
        return;
    /*
     * If it is, we just need to check that their pointers are disjoint. If
     * they are not, it means one is a prefix for the other one. Test this
     * by collecting the two trees' token resolvers and see if they share a
     * common subset at index 0.
     *
     * Note that the pointer can not be equal, of course: this would have
     * been caught by the ref resolver.
     */
    final JsonPointer sourcePointer = tree.getPointer();
    final JsonPointer targetPointer = newTree.getPointer();

    final List<TokenResolver<JsonNode>> sourceTokens = Lists.newArrayList(sourcePointer);
    final List<TokenResolver<JsonNode>> targetTokens = Lists.newArrayList(targetPointer);

    final ProcessingMessage message = new ProcessingMessage().message("").put("schemaURI", tree.getLoadingRef())
            .put("source", sourcePointer.toString()).put("target", targetPointer.toString());

    String msg;

    /*
     * Check if there is an attempt to expand to a parent tree
     */
    msg = BUNDLE.getString("parentExpand");
    if (Collections.indexOfSubList(sourceTokens, targetTokens) == 0)
        throw new SchemaWalkingException(message.message(msg));
    /*
     * Check if there is an attempt to expand to a subtree
     */
    msg = BUNDLE.getString("subtreeExpand");
    if (Collections.indexOfSubList(targetTokens, sourceTokens) == 0)
        throw new SchemaWalkingException(message.message(msg));
}

From source file:com.aliyun.odps.mapred.bridge.LOTGenerator.java

LogicalOperatorTree genTree() {

    resourceItems = buildResourceList();

    LogicalOperatorTree.Builder builder = LogicalOperatorTree.newBuilder();

    // prepare input 
    inputTableInfos = InputUtils.getTables(job);
    inputVolumeInfos = InputUtils.getVolumes(job);
    // FIXME multi-mapper
    Map<TableInfoKey, List<LinkedHashMap<String, String>>> inputTables = mergeInputTableInfos(inputTableInfos);

    // prepare output
    outputTableInfos = OutputUtils.getTables(job);
    outputVolumeInfos = OutputUtils.getVolumes(job);

    // FIXME multi-insert from m-r's mapper
    isNoOutput = outputTableInfos == null;
    isMultiInsert = !isNoOutput && outputTableInfos.length > 1;

    // streaming job has string output columns
    boolean isStreamingOutput = job.getNumReduceTasks() > 0 ? isStreamingReduce : isStreamingMap;

    List<OdpsType> outputColumnTypes = new ArrayList<OdpsType>();
    if (isMultiInsert) {
        // concat output columns for multi-insert
        for (TableInfo ti : outputTableInfos) {
            List<OdpsType> tbColumnTypes = new ArrayList<OdpsType>();
            for (Column col : job.getOutputSchema(ti.getLabel())) {
                tbColumnTypes.add(col.getType());
            }/*from   www. ja  v a  2  s  .c  o m*/
            // check if the same columns already exists
            int idx = Collections.indexOfSubList(outputColumnTypes, tbColumnTypes);
            if (idx >= 0) {
                // merge columns for tableinfos with the same schema
                outputIndexes.put(ti.getLabel(), idx);
                continue;
            }
            idx = outputColumns.size();
            outputIndexes.put(ti.getLabel(), idx);
            for (Column col : job.getOutputSchema(ti.getLabel())) {
                String colName = "multiins" + idx + "_" + col.getName();
                if (isStreamingOutput) {
                    outputColumns.add(new Column(colName, OdpsType.STRING));
                    outputColumnTypes.add(OdpsType.STRING);
                } else {
                    outputColumns.add(TypeUtils.createColumnWithNewName(colName, col));
                    outputColumnTypes.add(col.getType());
                }
            }
        }
        outputColumns.add(new Column(MULTI_INSERT_SELECTOR, OdpsType.STRING));
    } else if (isNoOutput) {
        // FIXME currently UDTF need a output column
        outputColumns.add(new Column(NO_OUTPUT_DUMMY_COLUMN, OdpsType.STRING));
    } else {
        for (Column col : job.getOutputSchema(outputTableInfos[0].getLabel())) {
            if (isStreamingOutput) {
                outputColumns.add(new Column(col.getName(), OdpsType.STRING));
            } else {
                outputColumns.add(TypeUtils.cloneColumn(col));
            }
        }
    }

    // prepare intermediate key/value
    // FIXME types/signature
    // FIXME use col name or not?
    List<Column> mapOutColumns;
    List<Column> firstReduceInColumns = null;
    int innerOutputIndex = 0;
    if (hasReducer) {
        mapOutColumns = new ArrayList<Column>();
        firstReduceInColumns = new ArrayList<Column>();

        if (hasPartitioner) {
            mapOutColumns.add(new Column(PARTITION_ID, OdpsType.BIGINT));
        }

        Column[] keys = this.pipeMode ? pipeline.getFirstNode().getOutputKeySchema()
                : job.getMapOutputKeySchema();
        for (Column col : keys) {
            Column keyCol = TypeUtils.createColumnWithNewName(MAP_OUT_KEY_PREFIX + col.getName(), col);
            mapOutColumns.add(keyCol);
            firstReduceInColumns.add(keyCol);
        }
        Column[] values = this.pipeMode ? pipeline.getFirstNode().getOutputValueSchema()
                : job.getMapOutputValueSchema();
        for (Column col : values) {
            Column valCol = TypeUtils.createColumnWithNewName(MAP_OUT_VAL_PREFIX + col.getName(), col);
            mapOutColumns.add(valCol);
            firstReduceInColumns.add(valCol);
        }
    } else {
        mapOutColumns = outputColumns;
    }

    //XXX: lot not support multi inputs with inner output
    String mapperId = genMapBlock(builder, inputTables, mapOutColumns, innerOutputIndex,
            hasReducer && isInnerOutput && (inputTables.size() <= 1));

    if (hasReducer) {
        genReduceBlock(builder, firstReduceInColumns, mapperId);
    } else {
        // map only output
        handleOutput(builder, false, outputColumns, mapperId, isTableOverwrite, innerOutputIndex);
    }

    return builder.build();
}

From source file:com.aliyun.odps.mapred.bridge.UDTFTaskContextImpl.java

private void initOutputSchema() {
    TableInfo[] tables = getOutputTableInfo();
    if (tables == null) {
        packagedOutputSchema = new Column[] { new Column("nil", OdpsType.STRING) };
        return;/*from  w w w .j a  v a2 s  .c o  m*/
    }

    List<Column[]> schemas = new ArrayList<Column[]>();
    List<OdpsType> outputColumnTypes = new ArrayList<OdpsType>();
    boolean multiInsert = tables.length > 1;
    int length = 0;
    for (TableInfo t : tables) {
        Column[] output;
        if (t.getLabel() == null) {
            output = conf.getOutputSchema();
        } else {
            output = conf.getOutputSchema(t.getLabel());
        }

        List<OdpsType> tbColumnTypes = new ArrayList<OdpsType>();
        for (Column col : output) {
            tbColumnTypes.add(col.getType());
        }
        // check if the same columns already exists
        int idx = Collections.indexOfSubList(outputColumnTypes, tbColumnTypes);
        if (idx >= 0) {
            // merge columns for tableinfos with the same schema
            label2offset.put(t.getLabel(), idx);
            continue;
        }
        label2offset.put(t.getLabel(), length);

        for (Column col : output) {
            outputColumnTypes.add(col.getType());
        }
        length += output.length;
        schemas.add(output);
    }
    // If multi insert, add 1 additional label field
    length += (multiInsert ? 1 : 0);
    // If inner output, add 1 additional label field
    length += (innerOutput ? 1 : 0);
    Column[] outputFields = new Column[length];
    length = 0;
    for (Column[] r : schemas) {
        for (Column f : r) {
            outputFields[length] = f;
            length++;
        }
    }
    if (multiInsert) {
        outputFields[length] = new Column(MULTIDEST_LABEL, OdpsType.STRING);
        length++;
    }
    if (innerOutput) {
        outputFields[length] = new Column(INNEROUTPUT_LABEL, OdpsType.STRING);
    }
    packagedOutputSchema = outputFields;
}

From source file:com.codestation.henkakuserver.HenkakuServer.java

/**
 * Write the url to fetch the next stage into the shellcode
 *
 * @param stage code of the current stage
 * @param url   address to fetch the next stage
 * @return modified shellcode//from  w w  w  . j a  va2 s .c  o  m
 * @throws UnsupportedEncodingException
 */
private byte[] writePkgUrl(byte[] stage, String url) throws UnsupportedEncodingException {

    // prepare search pattern
    byte[] pattern = new byte[256];
    Arrays.fill(pattern, (byte) 0x78);

    List a = Arrays.asList(ArrayUtils.toObject(stage));
    List b = Arrays.asList(ArrayUtils.toObject(pattern));

    // find url placeholder in loader
    int idx = Collections.indexOfSubList(a, b);

    // convert the url to a byte array
    byte[] urlArray = url.getBytes("UTF-8");

    // write the url in the loader
    System.arraycopy(urlArray, 0, stage, idx, urlArray.length);
    Arrays.fill(stage, idx + urlArray.length, idx + 256, (byte) 0x0);

    return stage;
}

From source file:ss16lab.outliers.Statistics.java

public static boolean contains(List<?> list, List<?> sublist) {
    if (list.size() == sublist.size()) {
        return false;
    }// w w  w  . j  a va  2  s . c  om
    if (list.isEmpty() || sublist.isEmpty()) {
        return false;
    }
    return Collections.indexOfSubList(list, sublist) != -1;
}