Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

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

Prototype

public LinkedList() 

Source Link

Document

Constructs an empty list.

Usage

From source file:com.jivesoftware.os.jive.utils.shell.utils.Untar.java

public static List<File> unTar(boolean verbose, final File outputDir, final File inputFile,
        boolean deleteOriginal) throws FileNotFoundException, IOException, ArchiveException {

    if (verbose) {
        System.out.println(String.format("untaring %s to dir %s.", inputFile.getAbsolutePath(),
                outputDir.getAbsolutePath()));
    }/* ww  w . j a  va  2  s.c  o  m*/

    final List<File> untaredFiles = new LinkedList<>();
    final InputStream is = new FileInputStream(inputFile);
    final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory()
            .createArchiveInputStream("tar", is);
    TarArchiveEntry entry = null;
    while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
        String entryName = entry.getName();
        entryName = entryName.substring(entryName.indexOf("/") + 1);
        final File outputFile = new File(outputDir, entryName);
        if (entry.isDirectory()) {
            if (verbose) {
                System.out.println(String.format("Attempting to write output directory %s.",
                        getRelativePath(outputDir, outputFile)));
            }
            if (!outputFile.exists()) {
                if (verbose) {
                    System.out.println(String.format("Attempting to create output directory %s.",
                            getRelativePath(outputDir, outputFile)));
                }
                if (!outputFile.mkdirs()) {
                    throw new IllegalStateException(String.format("Couldn't create directory %s.",
                            getRelativePath(outputDir, outputFile)));
                }
            }
        } else {
            try {
                if (verbose) {
                    System.out.println(
                            String.format("Creating output file %s.", getRelativePath(outputDir, outputFile)));
                }
                outputFile.getParentFile().mkdirs();
                final OutputStream outputFileStream = new FileOutputStream(outputFile);
                IOUtils.copy(debInputStream, outputFileStream);
                outputFileStream.close();

                if (getRelativePath(outputDir, outputFile).contains("bin/")
                        || outputFile.getName().endsWith(".sh")) { // Hack!
                    if (verbose) {
                        System.out.println(
                                String.format("chmod +x file %s.", getRelativePath(outputDir, outputFile)));
                    }
                    outputFile.setExecutable(true);
                }

            } catch (Exception x) {
                System.err.println("failed to untar " + getRelativePath(outputDir, outputFile) + " " + x);
            }
        }
        untaredFiles.add(outputFile);
    }
    debInputStream.close();

    if (deleteOriginal) {
        FileUtils.forceDelete(inputFile);
        if (verbose) {
            System.out.println(String.format("deleted original file %s.", inputFile.getAbsolutePath()));
        }
    }
    return untaredFiles;
}

From source file:com.splout.db.common.GetIPAddresses.java

/**
 * Returns all available IP addresses./* www  .j av  a  2  s  .  c  o  m*/
 * <p/>
 * In error case or if no network connection is established, we return an empty list here.
 * <p/>
 * Loopback addresses are excluded - so 127.0.0.1 will not be never returned.
 * <p/>
 * The "primary" IP might not be the first one in the returned list.
 *
 * @return Returns all IP addresses (can be an empty list in error case or if network connection is missing).
 * @throws SocketException
 * @since 0.1.0
 */
public static Collection<InetAddress> getAllLocalIPs() throws SocketException {
    LinkedList<InetAddress> listAdr = new LinkedList<InetAddress>();

    Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
    if (nifs == null)
        return listAdr;

    while (nifs.hasMoreElements()) {
        NetworkInterface nif = nifs.nextElement();
        // We ignore subinterfaces - as not yet needed.
        Enumeration<InetAddress> adrs = nif.getInetAddresses();
        while (adrs.hasMoreElements()) {
            InetAddress adr = adrs.nextElement();
            if (adr != null && !adr.isLoopbackAddress()
                    && (nif.isPointToPoint() || !adr.isLinkLocalAddress())) {
                log.info("Available site local address: " + adr);
                listAdr.add(adr);
            }
        }
    }
    return listAdr;
}

From source file:edu.iu.daal_linreg.LinRegUtil.java

public static List<List<double[]>> loadPoints(List<String> fileNames, int pointsPerFile, int cenVecSize,
        int labelSize, Configuration conf, int numThreads) {
    long startTime = System.currentTimeMillis();
    List<PointLoadTask> tasks = new LinkedList<>();
    List<List<double[]>> arrays = new LinkedList<List<double[]>>();
    for (int i = 0; i < numThreads; i++) {
        tasks.add(new PointLoadTask(pointsPerFile, cenVecSize, labelSize, conf));
    }//from   w w  w . ja v  a 2 s.  c  o  m
    DynamicScheduler<String, List<double[]>, PointLoadTask> compute = new DynamicScheduler<>(tasks);
    for (String fileName : fileNames) {
        compute.submit(fileName);
    }
    compute.start();
    compute.stop();
    while (compute.hasOutput()) {
        List<double[]> output = compute.waitForOutput();
        if (output != null) {
            arrays.add(output);
        }
    }
    long endTime = System.currentTimeMillis();
    System.out
            .println("File read (ms): " + (endTime - startTime) + ", number of point arrays: " + arrays.size());
    return arrays;
}

From source file:com.handcraftedbits.bamboo.plugin.go.parser.GoTestParser.java

@SuppressWarnings("unchecked")
public static List<PackageTestResults> parseTests(final InputStream input) throws Exception {
    final List<String> lines = IOUtils.readLines(input, "UTF-8");
    final List<PackageTestResults> packageTestResults = new LinkedList<>();
    final Stack<SingleTestResult> testResults = new Stack<>();

    for (final String line : lines) {
        // A test has finished.  Parse it out and push it on the stack until we know which package it belongs to.

        if (line.startsWith("---")) {
            final Matcher matcher = GoTestParser.patternTestFinish.matcher(line);

            if (matcher.matches()) {
                TestStatus status = null;

                switch (matcher.group(1)) {
                case "FAIL": {
                    status = TestStatus.FAILED;

                    break;
                }//from   w w w .  j  a  v a 2  s .  co  m

                case "PASS": {
                    status = TestStatus.PASSED;

                    break;
                }

                case "SKIP": {
                    status = TestStatus.SKIPPED;

                    break;
                }
                }

                if (status != null) {
                    testResults.push(new SingleTestResult(matcher.group(2), status,
                            Double.parseDouble(matcher.group(3))));
                }
            }
        }

        // This is either noise or a finished set of package tests.

        else {
            final Matcher matcher = GoTestParser.patternPackageFinish.matcher(line);

            // We have a finished set of package tests, so create the model for it and clear the stack of tests.

            if (matcher.matches()) {
                final PackageTestResults packageResults = new PackageTestResults(matcher.group(2));

                // In this case, either the go test run did not specify -v or there are no tests in the
                // package.  We'll create a single "AllTests" test and assign it the correct status.  In the
                // case of no tests existing for the package, the status will be "skipped".

                if (testResults.empty()) {
                    double duration = 0.0d;
                    final String durationStr = matcher.group(3);
                    TestStatus testStatus = TestStatus.SKIPPED;

                    switch (matcher.group(1)) {
                    case "FAIL": {
                        testStatus = TestStatus.FAILED;

                        break;
                    }

                    case "ok  ": {
                        testStatus = TestStatus.PASSED;

                        break;
                    }
                    }

                    // If there are tests in the package, we should be able to extract the duration.

                    if (durationStr.endsWith("s")) {
                        duration = Double.parseDouble(durationStr.substring(0, durationStr.length() - 1));
                    }

                    packageResults.addTestResult(new SingleTestResult("AllTests", testStatus, duration));
                }

                while (!testResults.empty()) {
                    packageResults.addTestResult(testResults.pop());
                }

                packageTestResults.add(packageResults);
            }
        }
    }

    IOUtils.closeQuietly(input);

    return packageTestResults;
}

From source file:de.quadrillenschule.azocamsyncd.astromode_old.PhotoProjectProfile.java

public PhotoProjectProfile() {
    photoSeries = new LinkedList<>();
}

From source file:pl.edu.agh.iosr.lsf.dao.DatabaseHelper.java

public static List<String> getTestStatemets() {
    List<String> ls = new LinkedList<>();

    for (String s : statementStore.keySet()) {
        if (s.startsWith("T_")) {
            ls.add(s);//w ww.j  av a 2 s  . c  om
        }
    }

    return ls;
}

From source file:LogToFile.java

private static HttpPost Post(String url, HashMap<String, String> params,
        HashMap<String, ArrayList<String>> arrayParams) {
    try {//from w  w w  . j  a v a  2  s. c  o  m
        if (!url.endsWith("/"))
            url += "/";
        List<NameValuePair> params_list = null;
        if (params != null) {
            params_list = new LinkedList<NameValuePair>();
            for (Entry<String, String> entry : params.entrySet())
                params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        if (arrayParams != null) {
            if (params_list == null)
                params_list = new LinkedList<NameValuePair>();
            for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet())
                for (String value : entry.getValue())
                    params_list.add(new BasicNameValuePair(entry.getKey(), value));
        }
        HttpPost request = new HttpPost(url);
        if (params != null)
            request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8"));
        return request;
    } catch (Exception e) {
        Log.e("", e.getClass().getName() + "\n" + e.getMessage());
    }
    return null;
}

From source file:de.tor.tribes.util.AttackToTextWriter.java

public static boolean writeAttacks(Attack[] pAttacks, File pPath, int pAttacksPerFile, boolean pExtendedInfo,
        boolean pZipResults) {

    HashMap<Tribe, List<Attack>> attacks = new HashMap<>();

    for (Attack a : pAttacks) {
        Tribe t = a.getSource().getTribe();
        List<Attack> attsForTribe = attacks.get(t);
        if (attsForTribe == null) {
            attsForTribe = new LinkedList<>();
            attacks.put(t, attsForTribe);
        }/*from   www.  j  ava 2 s.  co  m*/
        attsForTribe.add(a);
    }

    Set<Entry<Tribe, List<Attack>>> entries = attacks.entrySet();
    for (Entry<Tribe, List<Attack>> entry : entries) {
        Tribe t = entry.getKey();
        List<Attack> tribeAttacks = entry.getValue();
        List<String> blocks = new LinkedList<>();

        while (!tribeAttacks.isEmpty()) {
            List<Attack> attsForBlock = new LinkedList<>();
            for (int i = 0; i < pAttacksPerFile; i++) {
                if (!tribeAttacks.isEmpty()) {
                    attsForBlock.add(tribeAttacks.remove(0));
                }
            }

            String fileContent = new AttackListFormatter().formatElements(attsForBlock, pExtendedInfo);
            blocks.add(fileContent);
        }
        if (!pZipResults) {
            writeBlocksToFiles(blocks, t, pPath);
        } else {
            writeBlocksToZip(blocks, t, pPath);
        }

    }
    return true;
}

From source file:net.dv8tion.jda.player.Playlist.java

public static Playlist getPlaylist(String url) {
    List<String> infoArgs = new LinkedList<>();
    infoArgs.addAll(YOUTUBE_DL_PLAYLIST_ARGS);
    infoArgs.add("--"); //Url separator. Deals with YT ids that start with --
    infoArgs.add(url);/*from   ww w.j a  v  a 2 s.com*/

    //Fire up Youtube-dl and get all sources from the provided url.
    List<AudioSource> sources = new ArrayList<>();
    Scanner scan = null;
    try {
        Process infoProcess = new ProcessBuilder().command(infoArgs).start();
        byte[] infoData = IOUtils.readFully(infoProcess.getInputStream(), -1, false);
        if (infoData == null || infoData.length == 0)
            throw new NullPointerException(
                    "The YT-DL playlist process resulted in a null or zero-length INFO!");

        String sInfo = new String(infoData);
        scan = new Scanner(sInfo);

        JSONObject source = new JSONObject(scan.nextLine());
        if (source.has("_type"))//Is a playlist
        {
            sources.add(new RemoteSource(source.getString("url")));
            while (scan.hasNextLine()) {
                source = new JSONObject(scan.nextLine());
                sources.add(new RemoteSource(source.getString("url")));
            }
        } else //Single source link
        {
            sources.add(new RemoteSource(source.getString("webpage_url")));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (scan != null)
            scan.close();
    }

    //Now that we have all the sources we can create our Playlist object.
    Playlist playlist = new Playlist("New Playlist");
    playlist.sources = sources;
    return playlist;
}

From source file:Utils.java

/** 
 * Renders multiple paragraphs of text in an array to an image (created and returned). 
 *
 * @param font The font to use//from   w w w.j  av  a  2  s .c o m
 * @param textColor The color of the text
 * @param text The message in an array of strings (one paragraph in each
 * @param width The width the text should be limited to
 * @return An image with the text rendered into it
 */
public static BufferedImage renderTextToImage(Font font, Color textColor, String text[], int width) {
    LinkedList<BufferedImage> images = new LinkedList<BufferedImage>();

    int totalHeight = 0;

    for (String paragraph : text) {
        BufferedImage paraImage = renderTextToImage(font, textColor, paragraph, width);
        totalHeight += paraImage.getHeight();
        images.add(paraImage);
    }

    BufferedImage image = createCompatibleImage(width, totalHeight);
    Graphics2D graphics = (Graphics2D) image.createGraphics();

    int y = 0;

    for (BufferedImage paraImage : images) {
        graphics.drawImage(paraImage, 0, y, null);
        y += paraImage.getHeight();
    }

    graphics.dispose();
    return image;
}