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:com.hp.mqm.clt.TestSupportClient.java

protected <E> PagedList<E> getEntities(URI uri, int offset, EntityFactory<E> factory) {
    HttpGet request = new HttpGet(uri);
    CloseableHttpResponse response = null;
    try {// w  w w  .j  a  v a  2  s .  c om
        response = execute(request);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new RuntimeException("Entity retrieval failed");
        }
        String entitiesJson = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
        JSONObject entities = JSONObject.fromObject(entitiesJson);

        LinkedList<E> items = new LinkedList<E>();
        for (JSONObject entityObject : getJSONObjectCollection(entities, "data")) {
            items.add(factory.create(entityObject.toString()));
        }
        return new PagedList<E>(items, offset, entities.getInt("total_count"));
    } catch (IOException e) {
        throw new RuntimeException("Cannot retrieve entities from MQM.", e);
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.web.widgets.BrowseWidget.java

/**
 * Gets a list of all VClassGroups with vclasses with individual counts.
 *//*w  w  w .  j  a  v  a2  s  .com*/
protected Map<String, Object> getAllClassGroupData(HttpServletRequest request, Map params,
        ServletContext context) {
    Map<String, Object> map = new HashMap<String, Object>();

    VitroRequest vreq = new VitroRequest(request);

    VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(request);
    List<VClassGroup> cgList = vcgc.getGroups();

    //        List<VClassGroup> classGroups =
    //            vreq.getWebappDaoFactory().getVClassGroupDao().getPublicGroupsWithVClasses();
    //        
    LinkedList<VClassGroupTemplateModel> cgtmList = new LinkedList<VClassGroupTemplateModel>();
    for (VClassGroup classGroup : cgList) {
        cgtmList.add(new VClassGroupTemplateModel(classGroup));
    }
    map.put("vclassGroupList", cgtmList);
    return map;
}

From source file:jtabwb.launcher.CmdLineOptions.java

void defineCmdLineOptions() {
    LinkedList<Option> lo = new LinkedList<Option>();

    // HELP/*w w  w.  java  2  s . com*/
    lo.add(Option.builder(OptNames.HELP).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.HELP).build());
    // INPUT
    lo.add(Option.builder(OptNames.INPUT).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.INPUT_FORMULA)
            .build());
    // LATEX_CTREE
    lo.add(Option.builder().longOpt(OptNames.LATEX_CTREE)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LATEX_CTREE_FILE).build());
    // LATEX_PROOF
    lo.add(Option.builder().longOpt(OptNames.LATEX_PROOF)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LATEX_PROOF_FILE).build());
    if (configuration.availableProvers.size() > 1) {
        // LIST_PROVERS
        lo.add(Option.builder().longOpt(OptNames.LIST_PROVERS)
                .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LIST_PROVERS).build());
        // PROVER
        if (configuration.availableProvers.size() > 1)
            lo.add(Option.builder(OptNames.PROVER).hasArg().argName("name")
                    .desc(String.format(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.PROVER,
                            configuration.availableProvers.getNames()))
                    .build());
    }
    if (configuration.availableReaders.size() > 1) {
        // READER
        lo.add(Option.builder(OptNames.READER).hasArg().argName("name")
                .desc(String.format(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.READER,
                        configuration.availableReaders.getNames()))
                .build());
        // LIST_READERS
        lo.add(Option.builder().longOpt(OptNames.LIST_READERS)
                .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LIST_READER).build());
    }
    // LOG
    lo.add(Option.builder().longOpt(OptNames.LOG).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOG_FILE)
            .build());
    // LOG_TIME
    lo.add(Option.builder().longOpt(OptNames.LOG_TIME).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOG_TIME)
            .build());
    // SAVE_TRACE
    lo.add(Option.builder().longOpt(OptNames.SAVE_TRACE)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.PTRACE_FILE).build());
    // VERBOSE
    lo.add(Option.builder(OptNames.VERBOSE).desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.VERBOSE).build());
    // TESTSET
    lo.add(Option.builder().longOpt(OptNames.TESTSET).hasArg(true).argName("test-name")
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.TESTSET).build());
    // LOGDIR
    lo.add(Option.builder().longOpt(OptNames.LOG_DIR).hasArg(true).argName("filename")
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.LOGDIR).build());
    // F3_TIME_STR
    lo.add(Option.builder().longOpt(OptNames.F3_TIME_STR).hasArg(false)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.F3_TIME_STR).build());
    // JTABWB_TIME_STR 
    lo.add(Option.builder().longOpt(OptNames.JTABWB_TIME_STR).hasArg(false)
            .desc(MSG.CMD_LINE_OPTIONS.OPTIONS_DESCRIPTIONS.JTABWB_TIME_STR).build());

    for (Option opt : lo)
        if (configuration.cmdLineOptions.getOption(opt.getOpt()) != null
                || configuration.cmdLineOptions.getOption(opt.getLongOpt()) != null)
            throw new LauncherOptionDefinitionException(String.format(
                    MSG.CMD_LINE_OPTIONS.EXCEPTIONS.LAUNCHER_OPTION_NAME_REDEFINITION_ERROR, opt.getOpt()));
        else
            configuration.cmdLineOptions.addOption(opt);
}

From source file:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.BrowseDataGetter.java

private Map<String, Object> getCommonValues(ServletContext context, VitroRequest vreq) {
    Map<String, Object> values = new HashMap<String, Object>();

    VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
    List<VClassGroup> cgList = vcgc.getGroups();
    LinkedList<VClassGroupTemplateModel> cgtmList = new LinkedList<VClassGroupTemplateModel>();
    for (VClassGroup classGroup : cgList) {
        cgtmList.add(new VClassGroupTemplateModel(classGroup));
    }//  w w  w  . j  a va  2s.c  om
    values.put("vClassGroups", cgtmList);

    return values;
}

From source file:mulavito.algorithms.shortestpath.disjoint.SuurballeTarjan.java

private List<E> recombinePaths(List<E> path, V target, List<E> union) {
    LinkedList<E> p = new LinkedList<E>(); // provides getLast
    p.add(path.get(0));
    union.remove(path.get(0));/*from www.  j av  a  2s.  c  om*/

    V curDest;
    while (!(curDest = graph.getDest(p.getLast())).equals(target)) {
        boolean progress = false;
        for (E e : union)
            if (graph.isSource(curDest, e)) {
                p.add(e);
                progress = true;
                union.remove(e);
                break;
            }

        if (!progress)
            return null;

        if (union.isEmpty()) {
            if (!graph.isDest(target, p.getLast())) {
                throw new AssertionError("bug");
            } else
                break;
        }
    }
    return p;
}

From source file:com.pinterest.secor.common.ZookeeperConnector.java

public List<String> getCommittedOffsetTopics() throws Exception {
    ZooKeeper zookeeper = mZookeeperClient.get();
    String offsetPath = getCommittedOffsetGroupPath();
    List<String> topics = zookeeper.getChildren(offsetPath, false);
    LinkedList<String> result = new LinkedList<String>();
    for (String topicPath : topics) {
        String[] elements = topicPath.split("/");
        String topic = elements[elements.length - 1];
        result.add(topic);
    }/* w w  w.j a  v a 2 s.c om*/
    return result;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

private byte[] toBytes(Certificate[] certificates) throws CertificateEncodingException {
    /* //from  w  ww  .  java  2s  . c om
     * we need to make encodedCerts a LinkedList and not a List because SerializationUtils.serialize 
     * requires the implementation to be serializable.
     */
    LinkedList<EncodedCertificate> encodedCerts = new LinkedList<EncodedCertificate>();

    for (Certificate certificate : certificates) {
        encodedCerts.add(new EncodedCertificate(certificate));
    }

    return SerializationUtils.serialize(encodedCerts);
}

From source file:com.xorcode.andtweet.net.ConnectionOAuth.java

@Override
public JSONObject updateStatus(String message, long inReplyToId) throws ConnectionException {
    HttpPost post = new HttpPost(STATUSES_UPDATE_URL);
    LinkedList<BasicNameValuePair> out = new LinkedList<BasicNameValuePair>();
    out.add(new BasicNameValuePair("status", message));
    if (inReplyToId > 0) {
        out.add(new BasicNameValuePair("in_reply_to_status_id", String.valueOf(inReplyToId)));
    }// w ww.  j a v  a 2 s  . c  o m
    try {
        post.setEntity(new UrlEncodedFormEntity(out, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, e.toString());
    }
    return postRequest(post);
}

From source file:net.dv8tion.jda.core.MessageHistory.java

public synchronized RestAction<List<Message>> retrievePast(int amount) {
    if (amount > 100 || amount < 0)
        throw new IllegalArgumentException(
                "Message retrieval limit is between 1 and 100 messages. No more, no less. Limit provided: "
                        + amount);/*from ww w.  j a v  a 2s  .  c o  m*/

    Route.CompiledRoute route;
    if (history.isEmpty())
        route = Route.Messages.GET_MESSAGE_HISTORY.compile(channel.getId(), Integer.toString(amount));
    else
        route = Route.Messages.GET_MESSAGE_HISTORY_BEFORE.compile(channel.getId(), Integer.toString(amount),
                history.lastKey());
    return new RestAction<List<Message>>(api, route, null) {
        @Override
        protected void handleResponse(Response response, Request request) {
            if (!response.isOk())
                request.onFailure(response);

            EntityBuilder builder = EntityBuilder.get(api);
            LinkedList<Message> msgs = new LinkedList<>();
            JSONArray historyJson = response.getArray();

            for (int i = 0; i < historyJson.length(); i++)
                msgs.add(builder.createMessage(historyJson.getJSONObject(i)));

            if (history.isEmpty())

                msgs.forEach(msg -> history.put(msg.getId(), msg));
            request.onSuccess(msgs);
        }
    };
}

From source file:eu.planets_project.pp.plato.services.action.crib_integration.CRiBActionServiceLocator.java

/**
 * Migrates sample record <code>sampleObject</code>  with the migration action  defined in <code>action</code>.
 *  //  w  ww. j a v a2  s.c  om
 */
public boolean perform(PreservationActionDefinition action, SampleObject sampleObject)
        throws PlatoServiceException {
    try {
        // all migration actions are done via the metaconverter
        metaconverterService = metaconverterServiceLocator.getMetaconverter();

        // prepare the data of the sample record for migration
        FileObject sampleFile = new FileObject(sampleObject.getData().getData(), sampleObject.getFullname());
        RepresentationObject representationObject = new RepresentationObject(new FileObject[] { sampleFile });

        // the action parameters specify which migration service is called
        MigrationPath migrationPath = new MigrationPath();
        LinkedList<String> urls = new LinkedList<String>();
        for (Parameter param : action.getParams()) {
            urls.add(param.getValue());
        }
        String[] urlArr = urls.toArray(new String[] {});
        migrationPath.setAccessPoints(urlArr);
        /*
         * convert source object
         */
        eu.planets_project.pp.plato.services.crib_integration.remoteclient.MigrationResult migrationResult = metaconverterService
                .convert(representationObject, migrationPath);
        /*
         * collect migration results
         */
        MigrationResult result = new MigrationResult();
        lastResult = result;

        /*
         * if the migration was successful is indicated by two flags:
         * "process::availability" and "process::stability"
         * - which are float values (!)
         */
        Criterion[] criteria = migrationResult.getReport().getCriteria();
        double availability = Double.parseDouble(getCriterion(criteria, "process::availability"));
        double stability = Double.parseDouble(getCriterion(criteria, "process::stability"));
        result.setSuccessful((availability > 0.0) && (stability > 0.0));

        if (!result.isSuccessful()) {
            result.setReport(String.format("Service '%s' failed to migrate sample '%s'.", action.getShortname(),
                    sampleObject.getFullname()));//+ getCriterion(criteria, "message::reason"));
            log.debug(String.format("Service '%s' failed to migrate sample '%s': %s", action.getShortname(),
                    sampleObject.getFullname(), getCriterion(criteria, "message::reason")));
            return true;
        } else {
            result.setReport(String.format("Migrated object '%s' to format '%s'. Completed at %s.",
                    sampleObject.getFullname(), action.getTargetFormat(),
                    migrationResult.getReport().getDatetime()));
        }
        result.getMigratedObject().getData()
                .setData(migrationResult.getRepresentation().getFiles()[0].getBitstream().clone());

        /*
         * message::filename contains the name of the source-file, NOT the migrated
         */
        String filename = migrationResult.getRepresentation().getFiles()[0].getFilename();

        /*
         * if filename is missing, use name from the source object (without extension)
         */
        if ((filename == null) || "".equals(filename)) {
            filename = sampleObject.getFullname();
            int bodyEnd = filename.lastIndexOf(".");
            if (bodyEnd >= 0)
                filename = filename.substring(0, bodyEnd);
        }
        result.getMigratedObject().setFullname(filename);
        int bodyEnd;

        /*
         * CRiB does not provide forther information about the format of the migrated object,
         * therfore the file extension of the migrated object is derived from the action's target formats 
         */
        bodyEnd = filename.lastIndexOf(".");
        if ((bodyEnd < 0) && ((result.getTargetFormat().getDefaultExtension() == null)
                || "".equals(result.getTargetFormat().getDefaultExtension()))) {
            FormatInfo targetFormat = new FormatInfo();
            setFormatFromCRiBID(action.getTargetFormat(), targetFormat);
            result.setTargetFormat(targetFormat);
            filename = filename + "." + result.getTargetFormat().getDefaultExtension();
            result.getMigratedObject().setFullname(filename);
        }
        lastResult = result;
        return true;
    } catch (NumberFormatException e) {
        throw new PlatoServiceException("Migration failed, CRiB returned an invalid result.", e);
    } catch (RemoteException e) {
        throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
    } catch (ServiceException e) {
        throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
    } catch (EJBException e) {
        throw new PlatoServiceException("Migration failed, could not access CRiB.", e);
    }
}