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:fi.smaa.libror.MaximalVectorComputation.java

/**
 * Implements the Best algorithm as described in Godfrey & al., VLDB Journal, 2007.
 * /* w w  w  .ja va 2s.c o  m*/
 * Returns indices of the rows from the original matrix.
 * 
 * @param mat The matrix of values (each row = 1 vector of input)
 * 
 * @return Matrix containing rows from the input s.t. none are dominated
 */
public static int[] computeBESTindices(RealMatrix mat) {
    LinkedList<Integer> list = matrixToListOfIndices(mat);
    LinkedList<Integer> results = new LinkedList<Integer>();

    while (list.size() > 0) {
        Iterator<Integer> iter = list.iterator();
        Integer b = iter.next(); // Get the first
        iter.remove();
        while (iter.hasNext()) { // Find a max
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            } else if (dominates(mat.getRowVector(t), mat.getRowVector(b))) {
                iter.remove();
                b = t;
            }
        }
        results.add(b);
        iter = list.iterator();
        while (iter.hasNext()) { // Clean up
            Integer t = iter.next();
            if (dominates(mat.getRowVector(b), mat.getRowVector(t))) {
                iter.remove();
            }
        }
    }

    return listOfIntegersToIntArray(results);
}

From source file:gr.abiss.calipso.tiers.specifications.GenericSpecifications.java

protected static void addNestedJunctionPredicates(final Class clazz, Root<Persistable> root, CriteriaBuilder cb,
        LinkedList<Predicate> predicates, Map<String, Map<String, String[]>> andJunctions, String mode) {
    if (!CollectionUtils.isEmpty(andJunctions)) {
        String[] searchMode = { mode };
        for (Map<String, String[]> params : andJunctions.values()) {
            params.put(SEARCH_MODE, searchMode);
            // TODO
            Predicate nestedPredicate = buildRootPredicate(clazz, params, root, cb/*, true*/);
            if (nestedPredicate != null) {
                predicates.add(nestedPredicate);
            }//from  w  w  w . ja  va2 s .co  m
        }
    }
}

From source file:io.hops.common.INodeUtil.java

public static void findPathINodesById(long inodeId, boolean inTree, LinkedList<INode> preTxResolvedINodes,
        boolean[] isPreTxPathFullyResolved) throws StorageException {
    if (inTree) {
        INode inode = indexINodeScanById(inodeId);
        if (inode == null) {
            isPreTxPathFullyResolved[0] = false;
            return;
        }//from www  .j  av a  2 s .c om
        preTxResolvedINodes.add(inode);
        readFromLeafToRoot(inode, preTxResolvedINodes);
    }
    isPreTxPathFullyResolved[0] = true;
    //reverse the list
    int firstCounter = 0;
    int lastCounter = preTxResolvedINodes.size() - 1 - firstCounter;
    INode firstNode = null;
    INode lastNode = null;
    while (firstCounter < (preTxResolvedINodes.size() / 2)) {
        firstNode = preTxResolvedINodes.get(firstCounter);
        lastNode = preTxResolvedINodes.get(lastCounter);
        preTxResolvedINodes.remove(firstCounter);
        preTxResolvedINodes.add(firstCounter, lastNode);
        preTxResolvedINodes.remove(lastCounter);
        preTxResolvedINodes.add(lastCounter, firstNode);
        firstCounter++;
        lastCounter = preTxResolvedINodes.size() - 1 - firstCounter;
    }
}

From source file:eu.stratosphere.test.operators.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);
        }/*www  .  ja v a2 s. c o m*/
    }

    return toParameterList(tConfigs);
}

From source file:gr.abiss.calipso.jpasearch.specifications.GenericSpecifications.java

protected static void addJunctionedParams(final Class clazz, Root<Persistable> root, CriteriaBuilder cb,
        LinkedList<Predicate> predicates, Map<String, Map<String, String[]>> andJunctions, String mode) {
    if (!CollectionUtils.isEmpty(andJunctions)) {
        String[] searchMode = { mode };
        for (Map<String, String[]> params : andJunctions.values()) {
            params.put(SEARCH_MODE, searchMode);
            Predicate nestedPredicate = getRootPredicate(clazz, params, root, cb, true);
            if (nestedPredicate != null) {
                predicates.add(nestedPredicate);
            }/*from ww  w  .j  a v a  2 s .  co  m*/
        }
    }
}

From source file:com.k42b3.aletheia.protocol.http.Util.java

public static LinkedList<Header> parseHeader(String rawHeader, String delimiter) {
    LinkedList<Header> headers = new LinkedList<Header>();

    String[] lines = rawHeader.split(delimiter);

    if (lines.length > 0) {
        // headers
        for (int i = 0; i < lines.length; i++) {
            int pos = lines[i].indexOf(':');

            if (pos != -1) {
                String key = lines[i].substring(0, pos).trim();
                String value = lines[i].substring(pos + 1).trim();

                if (!key.isEmpty() && !value.isEmpty()) {
                    headers.add(new BasicHeader(key, value));
                }//from w w w .ja v a  2 s.c  om
            }
        }
    }

    return headers;
}

From source file:com.stimulus.archiva.domain.EmailID.java

public static synchronized String generateUniqueID(Email email) {
    try {/*from  w  ww .  j a v a 2s  .c  o m*/
        MimeMessage raw = email;
        // we need a backup plan here
        if (raw == null) {
            return DateUtil.convertDatetoString(new Date());
        }
        Enumeration<Header> headers = raw.getAllHeaders();
        LinkedList<String> orderedHeaders = new LinkedList<String>();
        while (headers.hasMoreElements()) {
            Header header = headers.nextElement();

            if (Compare.equalsIgnoreCase(header.getName(), "Date")
                    || Compare.equalsIgnoreCase(header.getName(), "CC")
                    || Compare.equalsIgnoreCase(header.getName(), "BCC")
                    || Compare.equalsIgnoreCase(header.getName(), "Subject")
                    || Compare.equalsIgnoreCase(header.getName(), "To")
                    || Compare.equalsIgnoreCase(header.getName(), "From"))
                orderedHeaders.add(header.getName() + header.getValue());

        }
        Collections.sort(orderedHeaders);
        StringBuffer allHeaders = new StringBuffer();
        for (String header : orderedHeaders)
            allHeaders.append(header);
        MessageDigest sha = MessageDigest.getInstance("SHA-1");
        byte[] bytes = allHeaders.toString().getBytes();
        InputStream is = new ByteArrayInputStream(bytes);
        DigestInputStream dis = new DigestInputStream(is, sha);
        while (dis.read() != -1)
            ;
        dis.close();
        byte[] digest = sha.digest();
        return toHex(digest);
    } catch (Exception e) {
        logger.error("failed to generate a uniqueid for a message");
        return null;
    }
}

From source file:org.hsweb.web.service.impl.quartz.QuartzJobServiceImpl.java

public static List<Date> computeFireTimesBetween(OperableTrigger trigger, org.quartz.Calendar cal, Date from,
        Date to, int num) {
    LinkedList<Date> lst = new LinkedList<>();
    OperableTrigger t = (OperableTrigger) trigger.clone();
    if (t.getNextFireTime() == null) {
        t.setStartTime(from);//  www. j a  v a  2 s. com
        t.setEndTime(to);
        t.computeFirstFireTime(cal);
    }
    for (int i = 0; i < num; i++) {
        Date d = t.getNextFireTime();
        if (d != null) {
            if (d.before(from)) {
                t.triggered(cal);
                continue;
            }
            if (d.after(to)) {
                break;
            }
            lst.add(d);
            t.triggered(cal);
        } else {
            break;
        }
    }
    return java.util.Collections.unmodifiableList(lst);
}

From source file:de.tu_dortmund.ub.data.dswarm.TaskProcessingUnit.java

private static String executeTPUTask(final String[] watchFolderFiles, final String resourceWatchFolder,
        final Optional<String> optionalOutputDataModelID, final Optional<String> optionalExportMimeType,
        final Optional<String> optionalExportFileExtension, final Integer engineThreads,
        final String serviceName, final Properties config) throws Exception {

    // create job list
    final LinkedList<Callable<String>> transforms = new LinkedList<>();

    int cnt = 1;/*from w  w  w .ja v a  2s. c  om*/

    for (final String watchFolderFile : watchFolderFiles) {

        LOG.info("[{}][{}] do TPU task execution '{}' for file '{}'", serviceName, cnt, cnt, watchFolderFile);

        transforms.add(new TPUTask(config, watchFolderFile, resourceWatchFolder, optionalOutputDataModelID,
                optionalExportMimeType, optionalExportFileExtension, serviceName, cnt));

        cnt++;
    }

    // work on jobs
    final ThreadPoolExecutor pool = new ThreadPoolExecutor(engineThreads, engineThreads, 0L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>());

    try {

        final List<Future<String>> futureList = pool.invokeAll(transforms);

        final StringBuilder resultSB = new StringBuilder();

        for (final Future<String> f : futureList) {

            final String message = f.get();

            LOG.info(message);

            resultSB.append(message).append("\n");
        }

        return resultSB.toString();
    } catch (final Exception e) {

        LOG.error("something went wrong", e);

        throw e;
    } finally {

        pool.shutdown();
    }
}

From source file:controllers.SnLocationsController.java

public static void discoverFsqLocations(String lat, String lng) {

    String appid = params._contains(PARAM_APPID) ? params.get(PARAM_APPID) : "";
    String limit = params._contains(PARAM_LIMIT) ? params.get(PARAM_LIMIT) : "";
    limit = verifyRecordLimit(limit);//  ww  w.  ja v a2s .com
    String radius = params._contains(PARAM_RADIUS) ? params.get(PARAM_RADIUS) : "";
    radius = verifyRadius(radius);
    String herenow = params._contains(PARAM_HERENOW) ? params.get(PARAM_HERENOW) : "true";// by default : true
    String query = params._contains(PARAM_QUERY) ? params.get(PARAM_QUERY) : "";

    Logger.info("PARAMS -> appid:%s ; lat,lng:%s,%s ; radius:%s ; limit:%s ; herenow:%s ; query:%s", appid, lat,
            lng, radius, limit, herenow, query);

    ResponseModel responseModel = new ResponseModel();
    ResponseMeta responseMeta = new ResponseMeta();
    LinkedList<Object> dataList = new LinkedList<Object>();

    HashMap params = new HashMap();
    String cacheKey = CACHE_KEYPREFIX_NEARBY + "geo:" + lat + "," + lng;
    if (!StringUtils.isEmpty(limit))
        cacheKey += "|" + limit;
    if (!StringUtils.isEmpty(query))
        cacheKey += "|" + query;

    try {

        //dataList = (LinkedList<Object>) Cache.get(cacheKey);
        dataList = Cache.get(cacheKey, LinkedList.class);
        if (dataList == null) {

            dataList = new LinkedList<Object>();

            params.clear();
            if (!StringUtils.isEmpty(lat) && !StringUtils.isEmpty(lng))
                params.put("ll", lat + "," + lng);
            if (!StringUtils.isEmpty(limit))
                params.put(PARAM_LIMIT, limit);

            if (!StringUtils.isEmpty(radius))
                params.put(PARAM_RADIUS, radius);
            /*params.put(PARAM_RADIUS,
                  !StringUtils.isEmpty(radius)?
                radius
                :Play.configuration.getProperty("fsqdiscovery.discovery.API_LOCO_SEARCHDISTANCE")
                  );*/
            if (!StringUtils.isEmpty(query))
                params.put(PARAM_QUERY, query);

            FoursquareDiscoverPoiJob mFoursquarePoiJob = new FoursquareDiscoverPoiJob();
            mFoursquarePoiJob.setReqParams(params);
            dataList.addAll((LinkedList<Object>) mFoursquarePoiJob.doJobWithResult());

            if (dataList.size() > 0) {
                Logger.info("adding to cache!!! %s", dataList.size());
                Cache.set(cacheKey, dataList, CACHE_TTL_NEARBY);
            } else {
                Logger.info("NO NEED to cache, dataList.size(): 0");

                response.status = Http.StatusCode.OK;
                responseMeta.code = response.status;
                responseModel.meta = responseMeta;
                responseModel.data = dataList;

                renderJSON(LocoUtils.getGson().toJson(responseModel));
            }
        } else {
            Logger.info("Found in CACHE!!! %s", dataList.size());
        }

        if ("true".equalsIgnoreCase(herenow)) {
            // HereNow part
            params.clear();
            FoursquareDiscoverHereNowJob mFoursquareDiscoverHereNowJob = new FoursquareDiscoverHereNowJob();
            mFoursquareDiscoverHereNowJob.setReqParams(params);
            mFoursquareDiscoverHereNowJob.setPoiList(dataList);
            dataList = new LinkedList<Object>();//dataList.clear();
            dataList.addAll((LinkedList<Object>) mFoursquareDiscoverHereNowJob.doJobWithResult());

            // remove items which doesn't have any hereNow in it!!!
            try {
                PoiModelFoursquare fsqPoi = null;
                LinkedList<Object> dataListFiltered = new LinkedList<Object>();
                for (Object obj : dataList) {
                    fsqPoi = (PoiModelFoursquare) obj;

                    //if (fsqPoi.herenow==null || fsqPoi.herenow.size()==0) dataList.remove(obj);
                    if (fsqPoi.herenow != null && fsqPoi.herenow.size() > 0)
                        dataListFiltered.add(obj);
                }
                Logger.info("dataList.size(): %s | dataListFiltered.size(): %s", dataList.size(),
                        dataListFiltered.size());
                dataList = new LinkedList<Object>();//dataList.clear();
                dataList.addAll(dataListFiltered);
            } catch (Exception ex) {
                Logger.warn("exception while filtering out hereNow : %s", ex.toString());
            }
        } else {
            Logger.info("herenow param is NOT set true, skip loading hereNow!!! herenow: %s", herenow);
        }

        response.status = Http.StatusCode.OK;
        responseMeta.code = response.status;
        responseModel.meta = responseMeta;
        responseModel.data = dataList;

        renderJSON(LocoUtils.getGson().toJson(responseModel));
    } catch (Exception ex) {

        responseMeta.code = Http.StatusCode.INTERNAL_ERROR;
        gotError(responseMeta, ex);
        //renderJSON(responseModel);
    }
}