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:de.tudarmstadt.ukp.dkpro.core.io.web1t.util.Web1TFileSplitter.java

private List<File> generateListOfUniqueFiles(Map<String, File> fileMap) {
    // Generate unique Filelist
    Map<String, String> uniqeFiles = new HashMap<String, String>();
    for (File file : fileMap.values()) {
        String absPath = file.getAbsolutePath();
        if (uniqeFiles.get(absPath) == null) {
            uniqeFiles.put(absPath, "");
        }/* www . j a  v  a  2 s .  c  om*/
    }

    LinkedList<File> listOfUniqueFiles = new LinkedList<File>();
    for (String path : uniqeFiles.keySet()) {
        listOfUniqueFiles.add(new File(path));
    }
    return listOfUniqueFiles;
}

From source file:mil.nga.giat.geowave.datastore.accumulo.DeleteWriterTest.java

private void startMiniAccumulo(final MiniAccumuloConfigImpl config) throws IOException, InterruptedException {

    final LinkedList<String> jvmArgs = new LinkedList<>();
    jvmArgs.add("-XX:CompressedClassSpaceSize=512m");
    jvmArgs.add("-XX:MaxMetaspaceSize=512m");
    jvmArgs.add("-Xmx512m");

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override// w ww .j  a va 2 s .  c  om
        public void run() {
            tearDown();
        }
    });
    final Map<String, String> siteConfig = config.getSiteConfig();
    siteConfig.put(Property.INSTANCE_ZK_HOST.getKey(), zookeeper);
    config.setSiteConfig(siteConfig);
    miniAccumulo.start();
}

From source file:com.hp.alm.ali.idea.services.DevMotiveService.java

public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) {
    HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>();

    Integer workspaceId = workspaceConfiguration.getWorkspaceId();
    if (workspaceId == null) {
        return noResponse(ret, commits);
    }/* www  .  j  av a  2s.  c  om*/

    Element commitsElem = new Element("commits");
    for (Commit commit : commits) {
        Element commitElem = new Element("commit");
        setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName());
        setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName());
        commitElem.setAttribute("revision", commit.getRevisionString());
        commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate()));
        Element messageElem = new Element("message");
        messageElem.setText(commit.getMessage());
        commitElem.addContent(messageElem);
        commitsElem.addContent(commitElem);
    }
    String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem));

    MyResultInfo result = new MyResultInfo();
    int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId);

    if (code != HttpStatus.SC_OK) {
        return noResponse(ret, commits);
    }

    Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator();
    for (Commit commit : commits) {
        CommitInfo next = commitInfoIterator.next();
        LinkedList<EntityRef> list;
        if (next.getId() != null) {
            list = new LinkedList<EntityRef>();
            for (int id : next.getDefects()) {
                list.add(new EntityRef("defect", id));
            }
            for (int id : next.getRequirements()) {
                list.add(new EntityRef("requirement", id));
            }
        } else {
            list = null;
        }
        ret.put(commit, list);
    }

    return ret;
}

From source file:com.act.reachables.CladeTraversal.java

/**
 * The function creates a ordered list of chemicals from src to dst.
 *
 * @param src - The src id/*from   w w  w  .jav a  2 s  .c  om*/
 * @param dst - The dst id
 * @return Returns a list of ids from src to dst.
 */
public LinkedList<Long> pathFromSrcToDerivativeOfSrc(Long src, Long dst) {
    LinkedList<Long> result = new LinkedList<>();
    Long id = dst;
    result.add(id);

    while (!id.equals(src)) {
        Long newId = this.actData.getActTree().parents.get(id);
        result.add(newId);
        id = newId;
    }

    Collections.reverse(result);
    return result;
}

From source file:fr.aliasource.webmail.pool.impl.KeepAliveTask.java

@Override
public void run() {
    LinkedList<T> dead = new LinkedList<T>();

    for (T t : availableObjects) {
        boolean isAlive = t.keepAlive();
        if (!isAlive) {
            logger.warn("Dead poolable item (" + t + "). will recycle.");
            dead.add(t);
        }/*from w w  w  . j a v  a 2s  . c  om*/
    }

    if (!dead.isEmpty()) {
        logger.warn("pool usage report: " + pool.getUsageReport());
    }

    for (T t : dead) {
        availableObjects.remove(t);
        recycle();
    }

    if (availableObjects.remainingCapacity() - pool.getUsageCount() > 0) {
        logger.error("Pool refilling failed this time: " + pool.getUsageReport());
    }
}

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

/**
 * Batch update response as JSON//from w  w  w. j  av a2 s  .  c o  m
 * @param app the current App object
 * @param is entity input stream
 * @return a status code 200 or 400
 */
public static Response getBatchUpdateResponse(App app, InputStream is) {
    LinkedList<ParaObject> objects = new LinkedList<ParaObject>();
    Response entityRes = getEntity(is, List.class);
    if (entityRes.getStatusInfo() == Response.Status.OK) {
        List<Map<String, Object>> items = (List<Map<String, Object>>) entityRes.getEntity();
        // WARN: objects will not be validated here as this would require them to be read first
        for (Map<String, Object> item : items) {
            if (item != null && item.containsKey(Config._ID) && item.containsKey(Config._TYPE)) {
                ParaObject pobj = ParaObjectUtils.setAnnotatedFields(null, item, Locked.class);
                if (pobj != null) {
                    pobj.setId((String) item.get(Config._ID));
                    pobj.setType((String) item.get(Config._TYPE));
                    objects.add(pobj);
                }
            }
        }
        Para.getDAO().updateAll(app.getAppIdentifier(), objects);
    } else {
        return entityRes;
    }
    return Response.ok(objects).build();
}

From source file:com.cloud.agent.resource.virtualnetwork.ConfigHelper.java

private static List<ConfigItem> generateConfig(LoadBalancerConfigCommand cmd) {
    LinkedList<ConfigItem> cfg = new LinkedList<>();

    String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
    LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();

    String[] config = cfgtr.generateConfiguration(cmd);
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < config.length; i++) {
        buff.append(config[i]);/*  w w w.  ja v a2 s.  co m*/
        buff.append("\n");
    }
    String tmpCfgFilePath = "/etc/haproxy/";
    String tmpCfgFileName = "haproxy.cfg.new." + String.valueOf(System.currentTimeMillis());
    cfg.add(new FileConfigItem(tmpCfgFilePath, tmpCfgFileName, buff.toString()));

    String[][] rules = cfgtr.generateFwRules(cmd);

    String[] addRules = rules[LoadBalancerConfigurator.ADD];
    String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
    String[] statRules = rules[LoadBalancerConfigurator.STATS];

    String args = " -f " + tmpCfgFilePath + tmpCfgFileName;
    StringBuilder sb = new StringBuilder();
    if (addRules.length > 0) {
        for (int i = 0; i < addRules.length; i++) {
            sb.append(addRules[i]).append(',');
        }
        args += " -a " + sb.toString();
    }

    sb = new StringBuilder();
    if (removeRules.length > 0) {
        for (int i = 0; i < removeRules.length; i++) {
            sb.append(removeRules[i]).append(',');
        }

        args += " -d " + sb.toString();
    }

    sb = new StringBuilder();
    if (statRules.length > 0) {
        for (int i = 0; i < statRules.length; i++) {
            sb.append(statRules[i]).append(',');
        }

        args += " -s " + sb.toString();
    }

    if (cmd.getVpcId() == null) {
        args = " -i " + routerIp + args;
        cfg.add(new ScriptConfigItem(VRScripts.LB, args));
    } else {
        args = " -i " + cmd.getNic().getIp() + args;
        cfg.add(new ScriptConfigItem(VRScripts.VPC_LB, args));
    }

    return cfg;
}

From source file:com.github.r351574nc3.amex.assignment1.csv.DefaultInterpreter.java

/**
 * Convert records to {@link TestData}.//from  www . ja  va 2  s  . c o  m
 *
 * @return {@link Hashtable} instance which makes record lookup by name much easier. Records that belong to a given name are indexed
 * within the {@link Hashtable} instance. In case there is more than one instance, the object in the {@link Hashtable} is
 * a {@link LinkedList} which can be quickly iterated
 */
public Hashtable interpret(final File input) throws IOException {
    final CSVParser parser = CSVParser.parse(input, Charset.defaultCharset(),
            CSVFormat.RFC4180.withDelimiter('|'));

    // Using a {@link Hashtable with the name field on the CSV record as the key. A lower load factor is used to give more
    // priority to the time cost for looking up values. 
    final Hashtable<String, LinkedList<TestData>> index = new Hashtable<String, LinkedList<TestData>>(2, 0.5f);

    for (final CSVRecord record : parser) {
        final EmailNotificationTestData data = toTestData(record);

        LinkedList<TestData> data_ls = index.get(data.getName());
        if (data_ls == null) {
            data_ls = new LinkedList<TestData>();
            index.put(data.getName(), data_ls);
        }
        data_ls.add(data);
    }

    return index;
}

From source file:com.projity.strings.Messages.java

private static String getStringFromBundles(String key) {
    if (key == null)
        return null;
    LinkedList<ResourceBundle> buns = new LinkedList<ResourceBundle>();
    LinkedList<String> foundBundles = new LinkedList<String>();
    ;/*from w  ww .  ja v a  2  s .com*/
    if (bundles == null) {
        lock.lock(); //use lock to avoid useless synchronized when it's already initialized
        try {
            if (bundles == null) { //if it hasn't been initialized by an other thread
                String bundleNames[] = getMetaString("ResourceBundles").split(";");
                String directoryBundleNames[] = getMetaString("DirectoryResourceBundles").split(";");
                if (directoryClassLoader.isValid()) {
                    //foundBundles=new ArrayList<String>(bundleNames.length+directoryBundleNames.length);

                    for (int i = 0; i < directoryBundleNames.length; i++) {
                        try {
                            ResourceBundle bundle = ResourceBundle.getBundle(directoryBundleNames[i],
                                    Locale.getDefault(), directoryClassLoader);
                            buns.add(bundle);
                            foundBundles.add("com.projity.strings." + directoryBundleNames[i]);
                        } catch (Exception e) {
                        }
                    }
                } else
                    buns = new LinkedList<ResourceBundle>();
                for (int i = bundleNames.length - 1; i >= 0; i--) { // reverse order since the later ones should be searched first
                    String bname = bundleNames[i];

                    //find right position to insert in bundles
                    int j = 0;
                    int pos = 0;
                    for (String b : foundBundles) {
                        if (bname.equals(b))
                            break;
                        pos++;
                    }
                    buns.add(pos, ResourceBundle.getBundle(bname, Locale.getDefault(),
                            ClassLoaderUtils.getLocalClassLoader()/*Messages.class.getClassLoader()*/));
                    foundBundles.add(pos, bname);
                }
            }
        } finally {
            bundles = buns;
            lock.unlock();
        }
    }
    for (ResourceBundle bundle : bundles) {
        try {
            return bundle.getString(key);
        } catch (MissingResourceException e) {
        }
    }
    return null;
}

From source file:com.servioticy.queueclient.SimpleQueueClient.java

@Override
protected boolean putImpl(Object item) {
    LinkedList<Object> queue;

    try {/*from  w ww. j  a  va2 s.  c  o m*/
        queue = readQueue();
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        return false;
    }
    queue.add(item);

    try {
        writeQueue(queue);
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
        return false;
    }
    return true;
}