Example usage for java.util LinkedList add

List of usage examples for java.util LinkedList add

Introduction

In this page you can find the example usage for java.util LinkedList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:eu.stratosphere.pact.test.contracts.ReduceITCase.java

@Parameters
public static Collection<Object[]> getConfigurations() throws FileNotFoundException, IOException {

    LinkedList<Configuration> tConfigs = new LinkedList<Configuration>();

    String[] localStrategies = { PactCompiler.HINT_LOCAL_STRATEGY_SORT };
    String[] shipStrategies = { PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_HASH };

    for (String localStrategy : localStrategies) {
        for (String shipStrategy : shipStrategies) {

            Configuration config = new Configuration();
            config.setString("ReduceTest#LocalStrategy", localStrategy);
            config.setString("ReduceTest#ShipStrategy", shipStrategy);
            config.setInteger("ReduceTest#NoSubtasks", 4);
            tConfigs.add(config);
        }/*from ww w. j a v  a2s  .  c o m*/
    }

    return toParameterList(ReduceITCase.class, tConfigs);
}

From source file:com.hipu.bdb.util.FileUtils.java

/**
 * Retrieve a number of lines from the file around the given 
 * position, as when paging forward or backward through a file. 
 * /*from w  w w.  j a  va2 s  . co m*/
 * @param file File to retrieve lines
 * @param position offset to anchor lines
 * @param signedDesiredLineCount lines requested; if negative, 
 *        want this number of lines ending with a line containing
 *        the position; if positive, want this number of lines,
 *        all starting at or after position. 
 * @param lines List<String> to insert found lines
 * @param lineEstimate int estimate of line size, 0 means use default
 *        of 128
 * @return LongRange indicating the file offsets corresponding to 
 *         the beginning of the first line returned, and the point
 *         after the end of the last line returned
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static LongRange pagedLines(File file, long position, int signedDesiredLineCount, List<String> lines,
        int lineEstimate) throws IOException {
    // consider negative positions as from end of file; -1 = last byte
    if (position < 0) {
        position = file.length() + position;
    }

    // calculate a reasonably sized chunk likely to have all desired lines
    if (lineEstimate == 0) {
        lineEstimate = 128;
    }
    int desiredLineCount = Math.abs(signedDesiredLineCount);
    long startPosition;
    long fileEnd = file.length();
    int bufferSize = (desiredLineCount + 5) * lineEstimate;
    if (signedDesiredLineCount > 0) {
        // reading forward; include previous char in case line-end
        startPosition = position - 1;
    } else {
        // reading backward
        startPosition = position - bufferSize + (2 * lineEstimate);
    }
    if (startPosition < 0) {
        startPosition = 0;
    }
    if (startPosition + bufferSize > fileEnd) {
        bufferSize = (int) (fileEnd - startPosition);
    }

    // read that reasonable chunk
    FileInputStream fis = new FileInputStream(file);
    fis.getChannel().position(startPosition);
    byte[] buf = new byte[bufferSize];
    IOUtils.closeQuietly(fis);

    // find all line starts fully in buffer
    // (positions after a line-end, per line-end definition in 
    // BufferedReader.readLine)
    LinkedList<Integer> lineStarts = new LinkedList<Integer>();
    if (startPosition == 0) {
        lineStarts.add(0);
    }
    boolean atLineEnd = false;
    boolean eatLF = false;
    int i;
    for (i = 0; i < bufferSize; i++) {
        if ((char) buf[i] == '\n' && eatLF) {
            eatLF = false;
            continue;
        }
        if (atLineEnd) {
            atLineEnd = false;
            lineStarts.add(i);
            if (signedDesiredLineCount < 0 && startPosition + i > position) {
                // reached next line past position, read no more
                break;
            }
        }
        if ((char) buf[i] == '\r') {
            atLineEnd = true;
            eatLF = true;
            continue;
        }
        if ((char) buf[i] == '\n') {
            atLineEnd = true;
        }
    }
    if (startPosition + i == fileEnd) {
        // add phantom lineStart after end
        lineStarts.add(bufferSize);
    }
    int foundFullLines = lineStarts.size() - 1;

    // if found no lines
    if (foundFullLines < 1) {
        if (signedDesiredLineCount > 0) {
            if (startPosition + bufferSize == fileEnd) {
                // nothing more to read: return nothing
                return new LongRange(fileEnd, fileEnd);
            } else {
                // retry with larger lineEstimate
                return pagedLines(file, position, signedDesiredLineCount, lines,
                        Math.max(bufferSize, lineEstimate));
            }

        } else {
            // try again with much larger line estimate
            // TODO: fail gracefully before growing to multi-MB buffers
            return pagedLines(file, position, signedDesiredLineCount, lines, bufferSize);
        }
    }

    // trim unneeded lines
    while (signedDesiredLineCount > 0 && startPosition + lineStarts.getFirst() < position) {
        // discard lines starting before desired position
        lineStarts.removeFirst();
    }
    while (lineStarts.size() > desiredLineCount + 1) {
        if (signedDesiredLineCount < 0 && (startPosition + lineStarts.get(1) <= position)) {
            // discard from front until reach line containing target position
            lineStarts.removeFirst();
        } else {
            lineStarts.removeLast();
        }
    }
    int firstLine = lineStarts.getFirst();
    int partialLine = lineStarts.getLast();
    LongRange range = new LongRange(startPosition + firstLine, startPosition + partialLine);
    List<String> foundLines = IOUtils
            .readLines(new ByteArrayInputStream(buf, firstLine, partialLine - firstLine));

    if (foundFullLines < desiredLineCount && signedDesiredLineCount < 0 && startPosition > 0) {
        // if needed and reading backward, read more lines from earlier
        range = expandRange(range, pagedLines(file, range.getMinimumLong() - 1,
                signedDesiredLineCount + foundFullLines, lines, bufferSize / foundFullLines));

    }

    lines.addAll(foundLines);

    if (signedDesiredLineCount < 0 && range.getMaximumLong() < position) {
        // did not get line containining start position
        range = expandRange(range, pagedLines(file, partialLine, 1, lines, bufferSize / foundFullLines));
    }

    if (signedDesiredLineCount > 0 && foundFullLines < desiredLineCount && range.getMaximumLong() < fileEnd) {
        // need more forward lines
        range = expandRange(range, pagedLines(file, range.getMaximumLong(), desiredLineCount - foundFullLines,
                lines, bufferSize / foundFullLines));
    }

    return range;
}

From source file:view.visualization.TXTVisualization.java

public static void drawChart(String a, String b, String txt) {
    String[] boje = null;//ww w. j a  va  2s . c o m
    LinkedList<String> atributi = new LinkedList<String>();
    LinkedList<String> sviAtributi = new LinkedList<String>();
    String[] vrAtribut = null;
    XYSeries[] xy = null;
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    int brojac = 0;
    boolean kraj = false;
    LinkedList<Integer> numeric = new LinkedList<Integer>();

    try {
        BufferedReader in = new BufferedReader(new FileReader(txt));
        int br = Integer.parseInt(in.readLine().split(" ")[1]);
        for (int j = 0; j < br + 1; j++) {

            String pom = in.readLine();
            if (pom.contains("@attribute")) {
                if (pom.contains("numeric")) {
                    sviAtributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
                } else {
                    sviAtributi.add(pom.split(" ")[1]);
                }
            }
            if (pom.contains("@attribute") && pom.contains("numeric")) {
                atributi.add(pom.substring(11, pom.lastIndexOf("n") - 1));
            }
            if (!pom.contains("numeric")) {
                brojac++;
                numeric.add(j - 2);
            }

        }
        String s = in.readLine();
        boje = s.substring(s.indexOf("{") + 1, s.lastIndexOf("}")).split(",");
        xy = new XYSeries[boje.length];
        for (int i = 0; i < boje.length; i++) {

            xy[i] = new XYSeries(boje[i]);

        }
        while (!kraj) {
            String pom2 = in.readLine();

            if (!(pom2.contains("@data"))) {
                vrAtribut = pom2.split(",");
                for (int i = 0; i < xy.length; i++) {
                    if (xy[i].getKey().equals(vrAtribut[vrAtribut.length - 1])) {

                        xy[i].add(Double.parseDouble(vrAtribut[sviAtributi.indexOf(a)]),
                                Double.parseDouble(vrAtribut[sviAtributi.indexOf(b)]));

                    }
                }
            }
        }
        in.close();
    } catch (Exception e) {
        e.getMessage();
    }
    for (int i = 0; i < xy.length; i++) {
        xySeriesCollection.addSeries(xy[i]);
    }

    JFreeChart grafik = ChartFactory.createScatterPlot("Vizuelizacija", a, b, xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    ChartFrame proba = new ChartFrame("DataMiner", grafik);

    proba.setVisible(true);
    proba.setSize(500, 600);

}

From source file:com.frostwire.android.LollipopFileSystem.java

private static List<String> buildFixedSdCardPaths() {
    LinkedList<String> l = new LinkedList<>();

    l.add("/storage/sdcard1"); // Motorola Xoom
    l.add("/storage/extsdcard"); // Samsung SGS3
    l.add("/storage/sdcard0/external_sdcard"); // user request
    l.add("/mnt/extsdcard");
    l.add("/mnt/sdcard/external_sd"); // Samsung galaxy family
    l.add("/mnt/external_sd");
    l.add("/mnt/media_rw/sdcard1"); // 4.4.2 on CyanogenMod S3
    l.add("/removable/microsd"); // Asus transformer prime
    l.add("/mnt/emmc");
    l.add("/storage/external_SD"); // LG
    l.add("/storage/ext_sd"); // HTC One Max
    l.add("/storage/removable/sdcard1"); // Sony Xperia Z1
    l.add("/data/sdext");
    l.add("/data/sdext2");
    l.add("/data/sdext3");
    l.add("/data/sdext4");

    return Collections.unmodifiableList(l);
}

From source file:eu.stratosphere.test.operators.CoGroupITCase.java

@Parameters
public static Collection<Object[]> getConfigurations() throws FileNotFoundException, IOException {

    LinkedList<Configuration> tConfigs = new LinkedList<Configuration>();

    String[] localStrategies = { PactCompiler.HINT_LOCAL_STRATEGY_SORT_BOTH_MERGE };

    String[] shipStrategies = { PactCompiler.HINT_SHIP_STRATEGY_REPARTITION_HASH, };

    for (String localStrategy : localStrategies) {
        for (String shipStrategy : shipStrategies) {

            Configuration config = new Configuration();
            config.setString("CoGroupTest#LocalStrategy", localStrategy);
            config.setString("CoGroupTest#ShipStrategy", shipStrategy);
            config.setInteger("CoGroupTest#NoSubtasks", 4);

            tConfigs.add(config);
        }//from  www . j av a2  s  . c o m
    }

    return toParameterList(tConfigs);
}

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * Filters all pages in the Wikipedia XML2DB dump from the given file and
 * creates a list of page names belonging to certain categories.
 * //from  ww w  .  ja va  2 s  .  c om
 * @param filename
 * @param args
 * 
 * @throws RuntimeException
 * @throws IOException
 * @throws SAXException
 * @throws FileNotFoundException
 */
private static void doDumpdbFilter(String filename, String[] args)
        throws RuntimeException, IOException, SAXException, FileNotFoundException {
    int i = 0;
    int recursionLvl = 1;
    if (args.length > i) {
        try {
            recursionLvl = Integer.parseInt(args[i]);
        } catch (NumberFormatException e) {
            System.err.println("no number: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    String pageListFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        pageListFileName = args[i];
    } else {
        System.err.println("need a pagelist file name for filter; arguments given: " + Arrays.toString(args));
        System.exit(-1);
    }
    ++i;

    Set<String> allowedPages0 = new HashSet<String>();
    allowedPages0.add("Main Page");
    String allowedPagesFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        allowedPagesFileName = args[i];
        addFromFile(allowedPages0, allowedPagesFileName);
    }
    ++i;

    LinkedList<String> rootCategories = new LinkedList<String>();
    if (args.length > i) {
        for (String rCat : Arrays.asList(args).subList(i, args.length)) {
            if (!rCat.isEmpty()) {
                rootCategories.add(rCat);
            }
        }
    }
    WikiDumpHandler.println(System.out, "filtering by categories " + rootCategories.toString() + " ...");
    WikiDumpHandler.println(System.out, " wiki dump     : " + filename);
    WikiDumpHandler.println(System.out, " allowed pages : " + allowedPagesFileName);
    WikiDumpHandler.println(System.out, " recursion lvl : " + recursionLvl);

    WikiDumpHandler.println(System.out,
            "creating list of pages to import (recursion level: " + recursionLvl + ") ...");
    Set<String> allowedCats0 = new HashSet<String>(rootCategories);

    WikiDumpSQLiteLinkTables handler = new WikiDumpSQLiteLinkTables(filename);
    handler.setUp();
    SortedSet<String> pages = handler.getPagesInCategories(allowedCats0, allowedPages0, recursionLvl, false);
    handler.tearDown();

    do {
        FileWriter outFile = new FileWriter(pageListFileName);
        PrintWriter out = new PrintWriter(outFile);
        for (String page : pages) {
            out.println(page);
        }
        out.close();
    } while (false);
    exitCheckHandler(handler);
}

From source file:com.github.lindenb.jvarkit.util.vcf.VCFUtils.java

public static List<String> parseHeaderLines(LineReader r) throws IOException {
    LinkedList<String> stack = new LinkedList<String>();
    String line;//from w w  w  .  j a v  a2 s  . c  o  m
    while ((line = r.readLine()) != null && line.startsWith("#")) {
        stack.add(line);
        if (line.startsWith("#CHROM\t"))
            break;
    }
    return stack;
}

From source file:com.github.lindenb.jvarkit.util.vcf.VCFUtils.java

public static List<String> parseHeaderLines(BufferedReader r) throws IOException {
    LinkedList<String> stack = new LinkedList<String>();
    String line;/* w ww .ja  v  a  2  s . c om*/
    while ((line = r.readLine()) != null && line.startsWith("#")) {
        stack.add(line);
        if (line.startsWith("#CHROM\t"))
            break;
    }
    return stack;
}

From source file:com.ikanow.aleph2.management_db.controllers.actors.BucketDeletionActor.java

/** Deletes the data in all data services
 *  TODO (ALEPH-26): assume default ones for now 
 * @param bucket - the bucket to cleanse
 *///from   w  w w  .j  a  va2  s  . c om
public static CompletableFuture<Collection<BasicMessageBean>> deleteAllDataStoresForBucket(
        final DataBucketBean bucket, final IServiceContext service_context, boolean delete_bucket) {

    // Currently the only supported data service is the search index
    try {
        final LinkedList<CompletableFuture<BasicMessageBean>> vals = new LinkedList<>();

        service_context.listServiceProviders().stream().map(t3 -> t3._1().get())
                .filter(s -> IDataServiceProvider.class.isAssignableFrom(s.getClass()))
                .map(s -> (IDataServiceProvider) s).distinct().forEach(service -> {
                    if (!(delete_bucket && IStorageService.class.isAssignableFrom(service.getClass()))) {
                        // if deleting the bucket then don't need to remove the storage path
                        service.getDataService().ifPresent(ds -> vals
                                .add(ds.handleBucketDeletionRequest(bucket, Optional.empty(), delete_bucket)));
                    }
                });

        return CompletableFuture.allOf(vals.toArray(new CompletableFuture[0])).thenApply(__ -> {
            return vals.stream().map(x -> x.join()).collect(Collectors.toList());
        });
    } catch (Throwable t) {
        return CompletableFuture.completedFuture(
                Arrays.asList(ErrorUtils.buildErrorMessage(BucketDeletionActor.class.getSimpleName(),
                        "deleteAllDataStoresForBucket", ErrorUtils.getLongForm("{0}", t))));
    }
}

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * Filters all pages in the Wikipedia XML dump from the given file and
 * creates a list of page names belonging to certain categories.
 * //  w  w  w  .  ja v  a2 s.  c  o  m
 * @param filename
 * @param args
 * 
 * @throws RuntimeException
 * @throws IOException
 * @throws SAXException
 * @throws FileNotFoundException
 */
private static void doFilter(String filename, String[] args)
        throws RuntimeException, IOException, SAXException, FileNotFoundException {
    int i = 0;
    int recursionLvl = 1;
    if (args.length > i) {
        try {
            recursionLvl = Integer.parseInt(args[i]);
        } catch (NumberFormatException e) {
            System.err.println("no number: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    // a timestamp in ISO8601 format
    Calendar maxTime = null;
    if (args.length > i && !args[i].isEmpty()) {
        try {
            maxTime = Revision.stringToCalendar(args[i]);
        } catch (IllegalArgumentException e) {
            System.err.println("no date in ISO8601: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    String pageListFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        pageListFileName = args[i];
    } else {
        System.err.println("need a pagelist file name for filter; arguments given: " + Arrays.toString(args));
        System.exit(-1);
    }
    ++i;

    Set<String> allowedPages = new HashSet<String>();
    allowedPages.add("Main Page");
    String allowedPagesFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        allowedPagesFileName = args[i];
        addFromFile(allowedPages, allowedPagesFileName);
    }
    ++i;

    LinkedList<String> rootCategories = new LinkedList<String>();
    if (args.length > i) {
        for (String rCat : Arrays.asList(args).subList(i, args.length)) {
            if (!rCat.isEmpty()) {
                rootCategories.add(rCat);
            }
        }
    }
    WikiDumpHandler.println(System.out, "filtering by categories " + rootCategories.toString() + " ...");
    WikiDumpHandler.println(System.out, " wiki dump     : " + filename);
    WikiDumpHandler.println(System.out, " max time      : " + maxTime);
    WikiDumpHandler.println(System.out, " allowed pages : " + allowedPagesFileName);
    WikiDumpHandler.println(System.out, " recursion lvl : " + recursionLvl);
    SortedSet<String> pages = getPageList(filename, maxTime, allowedPages, rootCategories, recursionLvl);

    do {
        FileWriter outFile = new FileWriter(pageListFileName);
        PrintWriter out = new PrintWriter(outFile);
        for (String page : pages) {
            out.println(page);
        }
        out.close();
    } while (false);
}