Example usage for java.util LinkedList size

List of usage examples for java.util LinkedList size

Introduction

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

Prototype

int size

To view the source code for java.util LinkedList size.

Click Source Link

Usage

From source file:bicat.gui.GraphicPane.java

public void visualizeAll(LinkedList list, float[][] data, int x_table) { // ,
    // int//ww  w  . j  a v a2 s  . com
    // y_table)
    // {

    // create table view of the GraphicPane
    // for all (B)Cs, visualize it in the next window ...

    JPanel contentPane = new JPanel(new GridLayout(0, x_table));

    try {

        int row_cnt = 0;
        int col_cnt = 0;
        //
        for (int i = 0; i < list.size(); i++) {

            // get (b)c,
            bicat.biclustering.Bicluster bc = (bicat.biclustering.Bicluster) list.get(i);
            Vector genes = new Vector();
            Vector bcData = new Vector();
            //
            for (int g = 0; g < bc.getGenes().length; g++) {
                genes.add(new Integer(bc.getGenes()[g]));
                bcData.add(data[bc.getGenes()[g]]);
            }
            Vector chips = new Vector();
            for (int c = 0; c < bc.getChips().length; c++)
                chips.add(new Integer(bc.getChips()[c]));

            // get (corresponding) data
            setGraphDataList(bcData, genes, chips);

            // visualize the graph(ik) in the corresponding cell
            chart = newSimpleGraphic(Double.NaN, false);

            org.jfree.chart.ChartPanel cP = new org.jfree.chart.ChartPanel(chart);
            contentPane.add(cP);

            // old: cP.setPreferredSize(new Dimension(100, 10));
            // old: cP.setMaximumDrawHeight(2*xStep);
            // old: cP.setMaximumDrawWidth(6*xStep);

            // ... management stuff:
            col_cnt++;
            if (col_cnt == 3) {
                col_cnt = 0;
                row_cnt++;
            }
        }

        this.removeAll();
        this.add(contentPane);
        this.setVisible(true);
    } catch (Exception ee) {
        ee.printStackTrace();
    }
}

From source file:gr.seab.r2rml.beans.Parser.java

@SuppressWarnings("unchecked")
public MappingDocument parse() {

    init();//from w w w .j  a  va2s .c o m

    log.info("Initialized.");

    try {
        DatabaseType databaseType = util.findDatabaseType(properties.getProperty("db.driver"));
        mappingDocument.setDatabaseType(databaseType);
        //First find the logical table views
        LinkedList<LogicalTableView> logicalTableViews = findLogicalTableViews();
        mappingDocument.setLogicalTableViews(logicalTableViews);
        log.info("Mapping document has " + logicalTableViews.size() + " logical table views.");

        LinkedList<LogicalTableMapping> logicalTableMappings = findLogicalTableMappings();
        mappingDocument.setLogicalTableMappings(logicalTableMappings);
        log.info("Mapping document has " + logicalTableMappings.size() + " logical table mappings.");

        for (int i = 0; i < mappingDocument.getLogicalTableMappings().size(); i++) {
            LogicalTableMapping logicalTableMapping = mappingDocument.getLogicalTableMappings().get(i);
            logicalTableMapping.setSubjectMap(
                    createSubjectMapForResource(mapModel.getResource(logicalTableMapping.getUri())));
            logicalTableMapping.setPredicateObjectMaps(
                    createPredicateObjectMapsForResource(mapModel.getResource(logicalTableMapping.getUri())));
            mappingDocument.getLogicalTableMappings().set(i, logicalTableMapping);
        }

        //Sorting: evaluate first the logical table mappings without reference to a parent triples map
        @SuppressWarnings("rawtypes")
        Comparator c = new LogicalTableMappingComparator();
        Collections.sort(mappingDocument.getLogicalTableMappings(), c);

        if (verbose) {
            log.info("Logical table mappings will be parsed in the following order:");
            for (LogicalTableMapping ltm : mappingDocument.getLogicalTableMappings()) {
                log.info(" Table mapping uri: " + ltm.getUri());
            }
        }
        //resultModel.write(System.out, "TURTLE");

        //sparql("SELECT ?s ?p ?o FROM <" + baseNs + "> WHERE { ?s ?p ?o }", resultModel);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return mappingDocument;
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

static com.bilibili.magicasakura.utils.TintInfo parseColorStateList(ColorStateList origin) {
    if (origin == null)
        return null;

    boolean hasDisable = false;
    int originDefaultColor = origin.getDefaultColor();
    LinkedList<int[]> stateList = new LinkedList<>();
    LinkedList<Integer> colorList = new LinkedList<>();

    int disableColor = origin.getColorForState(DISABLED_STATE_SET, 0);
    if (disableColor != originDefaultColor) {
        hasDisable = true;//w  ww.j  av a  2  s  .c o  m
        stateList.add(DISABLED_STATE_SET);
        colorList.add(disableColor);
    }

    int pressedColor = origin.getColorForState(wrapState(hasDisable, PRESSED_STATE_SET), 0);
    if (pressedColor != originDefaultColor) {
        stateList.add(PRESSED_STATE_SET);
        colorList.add(pressedColor);
    }

    int focusColor = origin.getColorForState(wrapState(hasDisable, FOCUSED_STATE_SET), 0);
    if (focusColor != originDefaultColor) {
        stateList.add(FOCUSED_STATE_SET);
        colorList.add(focusColor);
    }

    int checkedColor = origin.getColorForState(wrapState(hasDisable, CHECKED_STATE_SET), 0);
    if (checkedColor != originDefaultColor) {
        stateList.add(CHECKED_STATE_SET);
        colorList.add(checkedColor);
    }

    int selectedColor = origin.getColorForState(wrapState(hasDisable, SELECTED_STATE_SET), 0);
    if (selectedColor != originDefaultColor) {
        stateList.add(SELECTED_STATE_SET);
        colorList.add(selectedColor);
    }

    int normalColor = origin.getColorForState(wrapState(hasDisable, EMPTY_STATE_SET), 0);
    if (normalColor != 0) {
        stateList.add(EMPTY_STATE_SET);
        colorList.add(normalColor);
    }

    if (colorList.size() > 1) {
        return new com.bilibili.magicasakura.utils.TintInfo(stateList, colorList);
    } else {
        return null;
    }
}

From source file:com.marketplace.io.Fetcher.java

/**
 * Reads the content of a file and stores each line of the file in a list.
 * // www.ja v  a  2 s.com
 * @param fileName
 *            the file name to read
 * @return contents of a file in a list.
 */
public List<String> readFile(String fileName) {
    LinkedList<String> list = new LinkedList<String>();

    if (fileName.isEmpty() || fileName.equals(" ")) {
        System.out.println("Please specify file name.");
        System.exit(1);
    } else {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));

            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                list.add(line);
            }
            bufferedReader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    log.info("Read " + list.size() + " lines");
    return list;
}

From source file:com.oltpbenchmark.benchmarks.seats.SEATSWorker.java

private boolean executeNewReservation(NewReservation proc) throws SQLException {
    Reservation reservation = null;/*from ww  w. j a  v  a2  s.co m*/
    BitSet seats = null;
    LinkedList<Reservation> cache = CACHE_RESERVATIONS.get(CacheType.PENDING_INSERTS);
    assert (cache != null) : "Unexpected " + CacheType.PENDING_INSERTS;

    if (LOG.isDebugEnabled())
        LOG.debug(String.format("Attempting to get a new pending insert Reservation [totalPendingInserts=%d]",
                cache.size()));
    while (reservation == null) {
        Reservation r = cache.poll();
        if (r == null) {
            if (LOG.isDebugEnabled())
                LOG.warn("Unable to execute " + proc + " - No available reservations to insert");
            break;
        }

        seats = getSeatsBitSet(r.flight_id);

        if (isFlightFull(seats)) {
            if (LOG.isDebugEnabled())
                LOG.debug(String.format("%s is full", r.flight_id));
            continue;
        }
        // PAVLO: Not sure why this is always coming back as reserved? 
        //            else if (seats.get(r.seatnum)) {
        //                if (LOG.isDebugEnabled())
        //                    LOG.debug(String.format("Seat #%d on %s is already booked", r.seatnum, r.flight_id));
        //                continue;
        //            }
        else if (isCustomerBookedOnFlight(r.customer_id, r.flight_id)) {
            if (LOG.isDebugEnabled())
                LOG.debug(String.format("%s is already booked on %s", r.customer_id, r.flight_id));
            continue;
        }
        reservation = r;
    } // WHILE
    if (reservation == null) {
        if (LOG.isDebugEnabled())
            LOG.warn("Failed to find a valid pending insert Reservation\n" + this.toString());
        return (false);
    }

    // Generate a random price for now
    double price = 2.0 * rng.number(SEATSConstants.RESERVATION_PRICE_MIN, SEATSConstants.RESERVATION_PRICE_MAX);

    // Generate random attributes
    long attributes[] = new long[9];
    for (int i = 0; i < attributes.length; i++) {
        attributes[i] = rng.nextLong();
    } // FOR

    if (LOG.isTraceEnabled())
        LOG.trace("Calling " + proc);
    proc.run(conn, reservation.id, reservation.customer_id.encode(), reservation.flight_id.encode(),
            reservation.seatnum, price, attributes);
    conn.commit();

    // Mark this seat as successfully reserved
    seats.set(reservation.seatnum);

    // Set it up so we can play with it later
    this.requeueReservation(reservation);

    return (true);
}

From source file:controllers.SnLocationsController.java

public static void trendingFsqLocations(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);//from  w ww. j  a  va2  s. c  om
    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, thats 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);

    // using Async jobs
    ResponseModel responseModel = new ResponseModel();
    ResponseMeta responseMeta = new ResponseMeta();
    LinkedList<Object> dataList = new LinkedList<Object>();

    HashMap params = new HashMap();
    String cacheKey = CACHE_KEYPREFIX_TRENDING + "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.trending.API_LOCO_SEARCHDISTANCE")
                  );*/
            if (!StringUtils.isEmpty(query))
                params.put(PARAM_QUERY, query);

            FoursquareTrendingPoiJob mFoursquareTrendingPoiJob = new FoursquareTrendingPoiJob();
            mFoursquareTrendingPoiJob.setReqParams(params);
            dataList.addAll((LinkedList<Object>) mFoursquareTrendingPoiJob.doJobWithResult());

            //Logger.info("adding to cache!!! %s", dataList.size());
            //Cache.set(cacheKey, dataList, CACHE_TTL_TRENDING);
            if (dataList.size() > 0) {
                Logger.info("adding to cache!!! %s", dataList.size());
                Cache.set(cacheKey, dataList, CACHE_TTL_TRENDING);
            } 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());
        } 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);
    }
}

From source file:com.google.ie.business.service.impl.IdeaServiceImpl.java

@SuppressWarnings("unchecked")
public void addIdeaToListInCache(Idea originalIdea, String keyOfTheList, int noOfIdeas, int expiryDelay) {
    LinkedList<Idea> listOfIdeas = (LinkedList<Idea>) CacheHelper.getObject(CacheConstants.IDEA_NAMESPACE,
            keyOfTheList);/*  w w w.ja  v a 2 s  . com*/
    if (listOfIdeas != null) {
        if (listOfIdeas.size() >= noOfIdeas) {
            /* Remove the last element which is also the oldest */
            listOfIdeas.pollLast();
        }
    } else {
        listOfIdeas = new LinkedList<Idea>();
    }
    /* Create a new idea object to contain the required data only */
    Idea ideaWithTheRequiredDataOnly = new Idea();
    ideaWithTheRequiredDataOnly
            .setTitle(StringUtils.abbreviate(originalIdea.getTitle(), ServiceConstants.FIFTY));
    /* Limit the description to hundred characters */
    ideaWithTheRequiredDataOnly
            .setDescription(StringUtils.abbreviate(originalIdea.getDescription(), ServiceConstants.HUNDRED));
    ideaWithTheRequiredDataOnly.setKey(originalIdea.getKey());
    /* Add the idea to the head of the list */
    listOfIdeas.addFirst(ideaWithTheRequiredDataOnly);
    /* Put the updated list back to the cache */
    CacheHelper.putObject(CacheConstants.IDEA_NAMESPACE, keyOfTheList, listOfIdeas, expiryDelay);
}

From source file:model.utilities.stats.collectors.PeriodicMarketObserver.java

private void outputToFile() {
    Preconditions.checkState(writer != null);
    LinkedList<String> row = new LinkedList<>();

    row.add(Double.toString(getLastPriceObserved()));
    row.add(Double.toString(getLastQuantityTradedObserved()));
    row.add(Double.toString(getLastQuantityProducedObserved()));
    row.add(Double.toString(getLastQuantityConsumedObserved()));
    row.add(Double.toString(getLastDayObserved()));
    row.add(Double.toString(// ww  w. j av a  2 s  .c  o  m
            market.getObservationRecordedThisDay(MarketDataType.DEMAND_GAP, days.get(days.size() - 1))));
    row.add(Double.toString(
            market.getObservationRecordedThisDay(MarketDataType.SUPPLY_GAP, days.get(days.size() - 1))));

    writer.writeNext(row.toArray(new String[row.size()]));
    try {
        writer.flush();
    } catch (IOException e) {

    }

}

From source file:com.google.ie.business.service.impl.IdeaServiceImpl.java

@SuppressWarnings("unchecked")
@Override/*from w ww  .j  a v  a 2 s.  c o m*/
public LinkedList<Idea> getPopularIdeas() {
    /* First check the cache for the data */
    LinkedList<Idea> popularIdeas = (LinkedList<Idea>) CacheHelper.getObject(CacheConstants.IDEA_NAMESPACE,
            CacheConstants.POPULAR_IDEAS);
    if (popularIdeas != null && popularIdeas.size() > ServiceConstants.ZERO) {
        logger.info("Popular ideas successfully fetched from cache");
        return popularIdeas;
    }
    /* If not in cache ,fetch from data store */
    RetrievalInfo retrievalInfo = new RetrievalInfo();
    /* Set the RetrievalInfo object to contain query parameters */
    retrievalInfo.setNoOfRecords(DEFAULT_NO_OF_POPULAR_IDEAS);
    retrievalInfo.setOrderBy(ServiceConstants.IDEA_ORDERING_FIELD_TOTAL_POSITIVE_VOTES);
    retrievalInfo.setOrderType(ServiceConstants.ORDERING_DESCENDING);
    /* Create the set of status conditions to be matched in the query */
    Set<String> statusOfIdeas = new HashSet<String>();
    statusOfIdeas.add(Idea.STATUS_PUBLISHED);
    /*
     * Fetch the ideas from the datastore and create a linked list from the
     * fetched ideas
     */
    popularIdeas = createLinkedListFromTheFetchedData(ideaDao.getIdeas(retrievalInfo, statusOfIdeas));
    if (popularIdeas.size() > ServiceConstants.ZERO) {
        /* Put popular ideas into cache */
        CacheHelper.putObject(CacheConstants.IDEA_NAMESPACE, CacheConstants.POPULAR_IDEAS, popularIdeas,
                CacheConstants.POPULAR_IDEAS_EXPIRATION_DELAY);
        logger.info("Popular ideas successfully added to the cache");
    }
    return popularIdeas;
}