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:edu.cmu.cs.lti.util.uima.UimaConvenience.java

public static List<String> casStringListToList(StringList sl) {
    LinkedList<String> retval = new LinkedList<String>();
    while (sl instanceof NonEmptyStringList) {
        NonEmptyStringList nesl = (NonEmptyStringList) sl;
        retval.add(nesl.getHead());
        sl = nesl.getTail();/*  w  w  w . ja va  2s.  c o  m*/
    }
    return retval;
}

From source file:com.erudika.para.rest.RestUtils.java

/**
 * Batch delete response as JSON/*from w  w  w . jav a 2  s  .c  om*/
 * @param app the current App object
 * @param ids list of ids to delete
 * @return a status code 200 or 400
 */
public static Response getBatchDeleteResponse(App app, List<String> ids) {
    LinkedList<ParaObject> objects = new LinkedList<ParaObject>();
    if (ids != null && !ids.isEmpty()) {
        if (ids.size() <= Config.MAX_ITEMS_PER_PAGE) {
            for (ParaObject pobj : Para.getDAO().readAll(app.getAppIdentifier(), ids, false).values()) {
                if (pobj != null && pobj.getId() != null && pobj.getType() != null) {
                    objects.add(pobj);
                }
            }
            Para.getDAO().deleteAll(app.getAppIdentifier(), objects);
        } else {
            return getStatusResponse(Response.Status.BAD_REQUEST,
                    "Limit reached. Maximum number of items to delete is " + Config.MAX_ITEMS_PER_PAGE);
        }
    } else {
        return getStatusResponse(Response.Status.BAD_REQUEST, "Missing ids.");
    }
    return Response.ok().build();
}

From source file:com.granita.icloudcalsync.resource.LocalCalendar.java

public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient)
        throws RemoteException {
    @Cleanup//from   w w  w. j a v a  2 s .co  m
    Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME },
            Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);

    LinkedList<LocalCalendar> calendars = new LinkedList<>();
    while (cursor != null && cursor.moveToNext())
        calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1)));
    return calendars.toArray(new LocalCalendar[0]);
}

From source file:com.zimbra.cs.imap.ImapMessage.java

static void serializeStructure(PrintStream ps, MimeMessage root, boolean extensions)
        throws IOException, MessagingException {
    LinkedList<LinkedList<MPartInfo>> queue = new LinkedList<LinkedList<MPartInfo>>();
    LinkedList<MPartInfo> level = new LinkedList<MPartInfo>();
    level.add(Mime.getParts(root).get(0));
    queue.add(level);/*from   w  w w.  j ava  2 s  .  c  o m*/

    boolean pop = false;
    while (!queue.isEmpty()) {
        level = queue.getLast();
        if (level.isEmpty()) {
            queue.removeLast();
            pop = true;
            continue;
        }

        MPartInfo mpi = level.getFirst();
        MimePart mp = mpi.getMimePart();
        boolean hasChildren = mpi.getChildren() != null && !mpi.getChildren().isEmpty();

        // we used to force unset charsets on text/plain parts to US-ASCII, but that always seemed unwise...
        ContentType ctype = new ContentType(mp.getHeader("Content-Type", null))
                .setContentType(mpi.getContentType());
        String primary = nATOM(ctype.getPrimaryType()), subtype = nATOM(ctype.getSubType());

        if (!pop)
            ps.write('(');
        if (primary.equals("\"MULTIPART\"")) {
            if (!pop) {
                // 7.4.2: "Multiple parts are indicated by parenthesis nesting.  Instead of a body type
                //         as the first element of the parenthesized list, there is a sequence of one
                //         or more nested body structures.  The second element of the parenthesized
                //         list is the multipart subtype (mixed, digest, parallel, alternative, etc.)."
                if (!hasChildren) {
                    ps.print("NIL");
                } else {
                    queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren()));
                    continue;
                }
            }
            ps.write(' ');
            ps.print(subtype);
            if (extensions) {
                // 7.4.2: "Extension data follows the multipart subtype.  Extension data is never
                //         returned with the BODY fetch, but can be returned with a BODYSTRUCTURE
                //         fetch.  Extension data, if present, MUST be in the defined order.  The
                //         extension data of a multipart body part are in the following order:
                //         body parameter parenthesized list, body disposition, body language,
                //         body location"
                ps.write(' ');
                nparams(ps, ctype);
                ps.write(' ');
                ndisposition(ps, mp.getHeader("Content-Disposition", null));
                ps.write(' ');
                nlist(ps, mp.getContentLanguage());
                ps.write(' ');
                nstring(ps, mp.getHeader("Content-Location", null));
            }
        } else {
            if (!pop) {
                // 7.4.2: "The basic fields of a non-multipart body part are in the following order:
                //         body type, body subtype, body parameter parenthesized list, body id, body
                //         description, body encoding, body size."
                String cte = mp.getEncoding();
                cte = (cte == null || cte.trim().equals("") ? "7bit" : cte);
                aSTRING(ps, ctype.getPrimaryType());
                ps.write(' ');
                aSTRING(ps, ctype.getSubType());
                ps.write(' ');
                nparams(ps, ctype);
                ps.write(' ');
                nstring(ps, mp.getContentID());
                ps.write(' ');
                nstring2047(ps, mp.getDescription());
                ps.write(' ');
                aSTRING(ps, cte);
                ps.write(' ');
                ps.print(Math.max(mp.getSize(), 0));
            }
            boolean rfc822 = primary.equals("\"MESSAGE\"") && subtype.equals("\"RFC822\"");
            if (rfc822) {
                // 7.4.2: "A body type of type MESSAGE and subtype RFC822 contains, immediately
                //         after the basic fields, the envelope structure, body structure, and
                //         size in text lines of the encapsulated message."
                if (!pop) {
                    if (!hasChildren) {
                        ps.print(" NIL NIL");
                    } else {
                        MimeMessage mm = (MimeMessage) mpi.getChildren().get(0).getMimePart();
                        ps.write(' ');
                        serializeEnvelope(ps, mm);
                        ps.write(' ');
                        queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren()));
                        continue;
                    }
                }
                ps.write(' ');
                ps.print(getLineCount(mp));
            } else if (primary.equals("\"TEXT\"")) {
                // 7.4.2: "A body type of type TEXT contains, immediately after the basic fields, the
                //         size of the body in text lines.  Note that this size is the size in its
                //         content transfer encoding and not the resulting size after any decoding."
                ps.write(' ');
                ps.print(getLineCount(mp));
            }
            if (extensions) {
                // 7.4.2: "Extension data follows the basic fields and the type-specific fields
                //         listed above.  Extension data is never returned with the BODY fetch,
                //         but can be returned with a BODYSTRUCTURE fetch.  Extension data, if
                //         present, MUST be in the defined order.  The extension data of a
                //         non-multipart body part are in the following order: body MD5, body
                //         disposition, body language, body location"
                ps.write(' ');
                nstring(ps, mp.getContentMD5());
                ps.write(' ');
                ndisposition(ps, mp.getHeader("Content-Disposition", null));
                ps.write(' ');
                nlist(ps, mp.getContentLanguage());
                ps.write(' ');
                nstring(ps, mp.getHeader("Content-Location", null));
            }
        }
        ps.write(')');

        level.removeFirst();
        pop = false;
    }
}

From source file:com.basho.riak.client.raw.http.ConversionUtil.java

/**
 * Converts a {@link WalkResponse} -> {@link WalkResult}
 * //from w  ww  .jav a 2  s .  c o m
 * Creates an anonymous implementation of {@link WalkResult} that exposes an
 * {@link UnmodifiableIterator} view of the results.
 * 
 * @param walkResponse
 *            An http.{@link RiakClient} {@link WalkResponse}
 * @return a new {@link WalkResult}
 */
static WalkResult convert(WalkResponse walkResponse) {
    final Collection<Collection<IRiakObject>> convertedSteps = new LinkedList<Collection<IRiakObject>>();

    for (List<com.basho.riak.client.http.RiakObject> step : walkResponse.getSteps()) {
        final LinkedList<IRiakObject> objects = new LinkedList<IRiakObject>();
        for (com.basho.riak.client.http.RiakObject o : step) {
            objects.add(convert(o));
        }
        convertedSteps.add(objects);
    }

    return new WalkResult() {
        public Iterator<Collection<IRiakObject>> iterator() {
            return new UnmodifiableIterator<Collection<IRiakObject>>(convertedSteps.iterator());
        }
    };
}

From source file:eu.stratosphere.pact.test.contracts.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 w  ww  .  j  av  a 2  s .  c o  m*/
    }

    return toParameterList(CoGroupITCase.class, tConfigs);
}

From source file:com.android.dumprendertree2.FsUtils.java

public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse, boolean mode) {
    String modeString = (mode ? "folders" : "files");

    URL url = null;/*w  w w. ja  v  a  2 s.  com*/
    try {
        url = new URL(SCRIPT_URL + "?path=" + dirRelativePath + "&recurse=" + recurse + "&mode=" + modeString);
    } catch (MalformedURLException e) {
        Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" + modeString, e);
        return new LinkedList<String>();
    }

    HttpGet httpRequest = new HttpGet(url.toString());
    ResponseHandler<LinkedList<String>> handler = new ResponseHandler<LinkedList<String>>() {
        @Override
        public LinkedList<String> handleResponse(HttpResponse response) throws IOException {
            LinkedList<String> lines = new LinkedList<String>();

            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                return lines;
            }
            HttpEntity entity = response.getEntity();
            if (entity == null) {
                return lines;
            }

            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            String line;
            try {
                while ((line = reader.readLine()) != null) {
                    lines.add(line);
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }

            return lines;
        }
    };

    try {
        return getHttpClient().execute(httpRequest, handler);
    } catch (IOException e) {
        Log.e(LOG_TAG, "getLayoutTestsDirContents(): HTTP GET failed for URL " + url);
        return null;
    }
}

From source file:canreg.client.analysis.Tools.java

public static LinkedList<String> generateRChart(Collection<CancerCasesCount> casesCounts, String fileName,
        String header, FileTypes fileType, ChartType chartType, boolean includeOther, Double restCount,
        String rpath, boolean sortByCount, String xlab) {
    LinkedList<String> generatedFiles = new LinkedList<String>();

    RFileBuilder rff = new RFileBuilder();

    File script = new File(Globals.R_SCRIPTS_PATH + "/makeSureGgplot2IsInstalled.r");
    rff.appendHeader(script.getAbsolutePath());

    rff.appendFileTypePart(fileType, fileName);

    generatedFiles.add(fileName);

    rff.appendData(casesCounts, restCount, includeOther);

    int numberOfCategories = casesCounts.size();
    if (includeOther) {
        numberOfCategories += 1;//from w  w  w. j  a  v  a 2 s  .co m
    }
    if (sortByCount) {
        rff.appendSort(chartType, numberOfCategories, includeOther, restCount);
    }

    rff.appendPlots(chartType, header, xlab);
    rff.appendWriteOut();

    System.out.println(rff.getScript());

    try {
        File tempFile = File.createTempFile("script", ".r");
        // generatedFiles.add(tempFile.getPath());
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(tempFile), "UTF8"));
        writer.append(rff.getScript());
        writer.close();
        Tools.callR(tempFile.getAbsolutePath(), rpath, fileName + "-report.txt");
    } catch (TableErrorException ex) {
        Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(TopNChartTableBuilder.class.getName()).log(Level.SEVERE, null, ex);
    }
    return generatedFiles;
}

From source file:at.bitfire.davdroid.resource.LocalCalendar.java

public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient)
        throws RemoteException {
    @Cleanup/*from w w  w.  j  a  va2 s .  c om*/
    Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME },
            Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);

    LinkedList<LocalCalendar> calendars = new LinkedList<>();
    while (cursor != null && cursor.moveToNext())
        calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1)));
    return calendars.toArray(new LocalCalendar[calendars.size()]);
}

From source file:org.opencastproject.loadtest.engage.Main.java

/**
 * Parse the episode xml to retrieve all of the episode ids.
 * /*from  w ww. j  a  v  a  2 s.  c  om*/
 * @param is
 *          This is the input stream representation of the xml.
 * @return A linked list of ids for the episodes on the engage server as Strings.
 **/
public static LinkedList<String> parseEpisodeXml(InputStream is) {
    LinkedList<String> episodes = new LinkedList<String>();
    try {
        // Parse document
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document document = docBuilder.parse(is);

        // Process results
        Node result = null;
        Node id = null;

        for (int i = 0; i < document.getElementsByTagName("result").getLength(); i++) {
            result = document.getElementsByTagName("result").item(i);
            id = result.getAttributes().getNamedItem("id");
            episodes.add(id.getNodeValue());
        }
    } catch (ParserConfigurationException pce) {
        logger.error(
                "The list of episodes could not be parsed from the xml received from the engage server because of:",
                pce);
    } catch (IOException ioe) {
        logger.error(
                "The list of episodes could not be parsed from the xml received from the engage server because of:",
                ioe);
    } catch (SAXException sae) {
        logger.error(
                "The list of episodes could not be parsed from the xml received from the engage server because of:",
                sae);
    }

    return episodes;
}