Example usage for java.util Vector retainAll

List of usage examples for java.util Vector retainAll

Introduction

In this page you can find the example usage for java.util Vector retainAll.

Prototype

public boolean retainAll(Collection<?> c) 

Source Link

Document

Retains only the elements in this Vector that are contained in the specified Collection.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);/*from  ww  w.j a  va2 s.c  om*/
    }
    System.out.println(v);

    Vector v2 = new Vector(5);
    for (int i = 0; i < 5; i++) {
        v2.add(0, i);
    }
    System.out.println(v2);
    System.out.println(v2.equals(v));

    v.retainAll(v2);
    System.out.println(v);
}

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> vec = new Vector<Integer>(4);
    Vector<Integer> vecretain = new Vector<Integer>(4);

    vec.add(1);//www .  j  a v a  2s .co m
    vec.add(2);
    vec.add(3);
    vec.add(4);
    vec.add(5);
    vec.add(6);
    vec.add(7);

    // this elements will be retained
    vecretain.add(5);
    vecretain.add(3);
    vecretain.add(2);

    vec.retainAll(vecretain);

    for (Integer number : vec) {
        System.out.println("Number = " + number);
    }
}

From source file:org.lockss.devtools.TestRunKbartReport.java

/**
 * A class that reads the output file, summarises it and runs various tests.
 *///from  w  w  w.j a va  2  s .  co  m
private void checkOutputFile(Reader r) {
    BufferedReader reader = new BufferedReader(r);
    int numberLines = 0;
    String outputHeader = null;
    try {
        outputHeader = reader.readLine();
        numberLines = 1;
        String s;
        while ((s = reader.readLine()) != null) {
            // Get the header from the first line
            //if (numberLines==0) outputHeader = s;
            numberLines++;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Count empty and duplicate lines in the input
    int numEmptyLines = 0;
    int numDuplicateLines = 0;
    Vector<String> lineList = new Vector<String>(Arrays.asList(lines));
    for (String line : lines) {
        if (StringUtils.isEmpty(line))
            numEmptyLines++;
        else {
            // If not empty, check ifthe line is a duplicate
            lineList.remove(line);
            if (lineList.contains(line))
                numDuplicateLines++;
        }
    }
    ;

    // Number of entries
    assertEquals(lines.length - numEmptyLines - numDuplicateLines, numberLines);

    // Setup the expected output header line
    Vector<String> labels = new Vector<String>(columnOrdering.getOrderedLabels());
    if (hideEmptyColumns) {
        // The expected output header is the list of col names from input header,
        // plus any constant-valued cols specified in the Ordering.

        // Only keep the columns specified in the input, as the rest will be
        // empty. The list of input cols comes from splitting the original
        // header on commas and trimming each token.
        // Additionally, expect a missing column from the original inputs.
        labels.retainAll(new ArrayList<String>() {
            {
                // retain labels from the input header
                for (String s : Arrays.asList(StringUtils.split(header, ","))) {
                    add(StringUtils.trim(s).toLowerCase());
                }
                // retain non-field labels from the ordering
                for (String s : columnOrdering.getNonFieldColumnLabels()) {
                    add(s);
                    //add(s.indexOf(" ")>=0 ? String.format("\"%s\"", s) : s);
                }
                // Also add title_url as it is filled in automatically by the exporter
                add(KbartTitle.Field.TITLE_URL.getLabel());
            }
        }
        //Arrays.asList(StringUtils.split(header.replace(" ", ""), ","))
        );
        labels.remove(emptyColumnLabel.toLowerCase());
    }
    if (showTdbStatus) {
        // expect an extra column
        // TODO this is not implemented yet, we need to add the extra column label
    }

    String expectedHeader = StringUtils.join(labels, ",");
    // Header should be equivalent to the defined field ordering
    //assertEquals(expectedHeader.toLowerCase(), outputHeader.toLowerCase());
    // NOTE the utf output includes a BOM, which screws up comparison
    // Also remove quotes added by CVS output rules (this is a quick kludge)
    outputHeader = outputHeader.replaceAll("\"", "");
    System.out.format("Output %s\nExpected %s\n", outputHeader, expectedHeader);
    assertTrue(outputHeader.toLowerCase().endsWith(expectedHeader.toLowerCase()));

    // TODO record ordering should be alphabetical by title, or first column

}