Example usage for java.util LinkedList get

List of usage examples for java.util LinkedList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:org.accelio.jxio.WorkerCache.java

Worker getCachedWorker(String clientId) {
    Worker w;//from   w  ww. j av  a  2 s.com
    LinkedList<Worker> clientWorkers = workersCache.get(clientId);
    // first time this client connects or wasn't connected for a long time and was removed by LRU
    if (clientWorkers == null) {
        if (LOG.isDebugEnabled())
            LOG.debug("client id " + clientId + " wasn't found in hash");
        w = wp.getWorker();
        if (w != null) {
            LinkedList<Worker> list = new LinkedList<Worker>();
            list.add(w);
            workersCache.put(clientId, list);
        }
        return w;
    }
    // look for free worker in client's previously connected workers
    int pos = 0;
    while (pos < clientWorkers.size()) {
        w = clientWorkers.get(pos);
        if (w.isFree()) {
            if (LOG.isDebugEnabled())
                LOG.debug("found free worker" + w + " for client id " + clientId);
            clientWorkers.remove(pos);
            clientWorkers.addFirst(w);
            return w;
        }
        pos++;
    }
    // no free workers to use from previously connected, get a new one
    w = wp.getWorker();
    if (w != null) {
        clientWorkers.addFirst(w);
        if (clientWorkers.size() > MAX_ENTRY_WORKERS) {
            clientWorkers.removeLast();
        }
    }
    return w;
}

From source file:org.apache.kylin.engine.spark.SparkCubing.java

private void writeToHFile2(final JavaPairRDD<byte[], byte[]> javaPairRDD, final String[] dataTypes,
        final int measureSize, final MeasureAggregators aggs, final byte[][] splitKeys,
        final Configuration conf, final String hFileLocation) {
    javaPairRDD.repartitionAndSortWithinPartitions(new Partitioner() {
        @Override/*w  w w  .java 2 s.c  o  m*/
        public int numPartitions() {
            return splitKeys.length + 1;
        }

        @Override
        public int getPartition(Object key) {
            Preconditions.checkArgument(key instanceof byte[]);
            for (int i = 0, n = splitKeys.length; i < n; ++i) {
                if (UnsignedBytes.lexicographicalComparator().compare((byte[]) key, splitKeys[i]) < 0) {
                    return i;
                }
            }
            return splitKeys.length;
        }
    }, UnsignedBytes.lexicographicalComparator())
            .mapPartitions(new FlatMapFunction<Iterator<Tuple2<byte[], byte[]>>, Tuple2<byte[], byte[]>>() {
                @Override
                public Iterable<Tuple2<byte[], byte[]>> call(
                        final Iterator<Tuple2<byte[], byte[]>> tuple2Iterator) throws Exception {
                    return new Iterable<Tuple2<byte[], byte[]>>() {
                        final BufferedMeasureCodec codec = new BufferedMeasureCodec(dataTypes);
                        final Object[] input = new Object[measureSize];
                        final Object[] result = new Object[measureSize];

                        @Override
                        public Iterator<Tuple2<byte[], byte[]>> iterator() {
                            return IteratorUtils.merge(tuple2Iterator,
                                    UnsignedBytes.lexicographicalComparator(),
                                    new Function<Iterable<byte[]>, byte[]>() {
                                        @Override
                                        public byte[] call(Iterable<byte[]> v1) throws Exception {
                                            final LinkedList<byte[]> list = Lists.newLinkedList(v1);
                                            if (list.size() == 1) {
                                                return list.get(0);
                                            }
                                            aggs.reset();
                                            for (byte[] v : list) {
                                                codec.decode(ByteBuffer.wrap(v), input);
                                                aggs.aggregate(input);
                                            }
                                            aggs.collectStates(result);
                                            ByteBuffer buffer = codec.encode(result);
                                            byte[] bytes = new byte[buffer.position()];
                                            System.arraycopy(buffer.array(), buffer.arrayOffset(), bytes, 0,
                                                    buffer.position());
                                            return bytes;
                                        }
                                    });
                        }
                    };
                }
            }, true).mapToPair(new PairFunction<Tuple2<byte[], byte[]>, ImmutableBytesWritable, KeyValue>() {
                @Override
                public Tuple2<ImmutableBytesWritable, KeyValue> call(Tuple2<byte[], byte[]> tuple2)
                        throws Exception {
                    ImmutableBytesWritable key = new ImmutableBytesWritable(tuple2._1());
                    KeyValue value = new KeyValue(tuple2._1(), "F1".getBytes(), "M".getBytes(), tuple2._2());
                    return new Tuple2(key, value);
                }
            }).saveAsNewAPIHadoopFile(hFileLocation, ImmutableBytesWritable.class, KeyValue.class,
                    HFileOutputFormat.class, conf);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationReportPanel.java

protected void updateView() {
    // clear// w w  w. j  a v  a2 s  .  com
    //for( int i=1; i<theDataset.getSeriesCount(); i++ )
    //theDataset.removeSeries(theDataset.getSeriesKey(i-1));

    for (int l = 0; l < theDocument.getNoStructures(); l++)
        theDataset.removeSeries("series" + l);

    for (int l = 0; l < theDocument.getNoStructures(); l++) {

        double[][] data = new double[2][];
        data[0] = new double[theDocument.getNoPeaks()];
        data[1] = new double[theDocument.getNoPeaks()];

        // get intensities and order them
        LinkedList<Double> sortedList = new LinkedList<Double>();
        for (int i = 0; i < theDocument.getNoPeaks(); i++) {
            double intensity = theDocument.getPeak(i).getIntensity();
            if (theDocument.getAnnotations(i, l).size() == 0)
                intensity = 0.;

            int index = Collections.binarySearch(sortedList, intensity);
            if (index < 0)
                index = -index - 1;
            sortedList.add(index, intensity);
        }

        // set data
        for (int i = 0; i < theDocument.getNoPeaks(); i++) {
            data[0][i] = i;
            data[1][i] = sortedList.get(theDocument.getNoPeaks() - i - 1);
        }
        theDataset.addSeries("series" + l, data);
    }
}

From source file:org.nekorp.workflow.desktop.view.BitacoraView.java

@Override
public void updateModel(Object origen, String property, Object value) {
    if (!ignore.remove(value)) {
        LinkedList<EventoVB> param = (LinkedList<EventoVB>) value;
        LinkedList<EventoVB> borrar = new LinkedList<>();
        for (EventoVB obj : modelo) {
            if (!param.contains(obj)) {
                borrar.add(obj);/* ww  w. j av  a 2 s.  co  m*/
            }
        }
        for (EventoVB x : borrar) {
            removeEvento(x);
        }
        for (int i = 0; i < param.size(); i++) {
            if (this.modelo.size() > i) {
                if (!param.get(i).equals(this.modelo.get(i))) {
                    this.modelo.add(i, param.get(i));
                    addEventoView(this.modelo.get(i), i);
                }
            } else {
                this.modelo.add(param.get(i));
                addEventoView(this.modelo.get(i), i);
            }
        }
        this.updateUI();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
            }
        });
    }
}

From source file:util.method.java

public static LinkedList<LinkedList<LinkedList<String>>> generateConcreteSeparationPolicyFromVMList(
        LinkedList<ArrayList> VMPolicyList, LinkedList<VM> VMList) throws COrbacException {

    LinkedList totalConcreteSeparationPolicyList = new LinkedList();

    for (int i = 0; i < VMPolicyList.size(); i++) {

        ArrayList currentVMRule = (ArrayList) VMPolicyList.get(i);

        String policyType = (String) currentVMRule.get(0);
        HashMap VM1Property = (HashMap) currentVMRule.get(1);
        HashMap VM2Property = (HashMap) currentVMRule.get(2);

        if (policyType.equals("separation")) {
            LinkedList<String> VMID1List = findRelatedVMID(VM1Property, VMList);

            LinkedList<String> VMID2List = findRelatedVMID(VM2Property, VMList);

            if ((VMID1List.size() == 0) || (VMID2List.size() == 0))
                return null;

            LinkedList seperationConflictPairList = new LinkedList<LinkedList<String>>();
            seperationConflictPairList.add(VMID1List);
            seperationConflictPairList.add(VMID2List);

            totalConcreteSeparationPolicyList.add(seperationConflictPairList);

        }//from   w  w  w.j a v a  2  s  .co  m
    }

    return totalConcreteSeparationPolicyList;

}

From source file:com.mirth.connect.plugins.serverlog.ServerLogProvider.java

public LinkedList<String[]> getServerLogs(String sessionId) {
    // work with deep copied clone of the static server logs object in
    // order to avoid multiple threads ConcurrentModificationException.
    LinkedList<String[]> serverLogsCloned = new LinkedList<String[]>();

    try {//from  w w  w.  java2 s.com
        serverLogsCloned = (LinkedList<String[]>) SerializationUtils.clone(serverLogs);
    } catch (SerializationException e) {
        // ignore
    }

    if (lastDisplayedServerLogIdBySessionId.containsKey(sessionId)) {
        // client exist with the sessionId.
        // -> only display new log entries.
        long lastDisplayedServerLogId = lastDisplayedServerLogIdBySessionId.get(sessionId);

        LinkedList<String[]> newServerLogEntries = new LinkedList<String[]>();
        // FYI, channelLog.size() will never be larger than LOG_SIZE =
        // 100.
        for (String[] aServerLog : serverLogsCloned) {
            if (lastDisplayedServerLogId < Long.parseLong(aServerLog[0])) {
                newServerLogEntries.addLast(aServerLog);
            }
        }

        if (newServerLogEntries.size() > 0) {
            // put the lastDisplayedLogId into the HashMap. index 0 is
            // the most recent entry, and index0 of that entry contains
            // the logId.
            lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(newServerLogEntries.get(0)[0]));
        }

        try {
            return SerializationUtils.clone(newServerLogEntries);
        } catch (SerializationException e) {
            logger.error(e);
        }
    } else {
        // brand new client. i.e. brand new session id, and all log
        // entries are new.
        // -> display all log entries.
        if (serverLogsCloned.size() > 0) {
            lastDisplayedServerLogIdBySessionId.put(sessionId, Long.parseLong(serverLogsCloned.get(0)[0]));
        } else {
            // no log exist at all. put the currentLogId-1, which is the
            // very latest logId.
            lastDisplayedServerLogIdBySessionId.put(sessionId, logId - 1);
        }

        try {
            return SerializationUtils.clone(serverLogsCloned);
        } catch (SerializationException e) {
            logger.error(e);
        }
    }

    return null;
}

From source file:report.mainReport.java

public static LinkedList addpointsList(String acId, String dvId, LinkedList pList, double lat, double lon,
        Timestamp dateEV, double vitesse, double odometerKM, double odometerOffsetKM, int statusCode,
        int speedLimit, int heading) {
    double distance;

    LinkedList<Events> pListnw = new LinkedList<Events>();
    Events evtnxt = null;/*from w w  w . j av a 2s.  co  m*/
    int i = pList.size() - 1;
    Events evt = (Events) pList.get(i);
    if (evt.getDeviceID().equalsIgnoreCase(dvId)) {
        String request = "";
        request = "loc=" + evt.getLatitude() + "," + evt.getLongitude() + "loc=" + lat + "," + lon;
        request = osrm + request + "&instructions=false&alt=false";
        //System.out.println(":" +request);
        ArrayList<Location> polyline = sendGetLoc(request, "viaroute");
        if (polyline != null) {
            double tempsnv = (dateEV.getTime() - evt.getDateEvt().getTime()) / polyline.size();
            //System.out.println("dateEV:"+new SimpleDateFormat("yyy-MM-dd HH:mm:ss").format(dateEV)+" evt.getDateEvt():"+new SimpleDateFormat("yyy-MM-dd HH:mm:ss").format(evt.getDateEvt()));
            double temps = ((dateEV.getTime() - evt.getDateEvt().getTime()) / 1000.0) / 3600;
            //System.out.println("Nombre de point nv:" + polyline.size()+ " tmps a ajouter = "+ tempsnv+ " dif:"+temps);
            for (int ip = 0; ip < polyline.size(); ip++) {
                double tmps = evt.getDateEvt().getTime() + (tempsnv * (ip + 1));
                int dist = Integer.parseInt(((Location) polyline.get(ip)).getDistance()) / 1000;
                double vitessenv = dist / temps;
                double la = ((Location) polyline.get(ip)).getLatitude();
                double lo = ((Location) polyline.get(ip)).getLongitude();
                Timestamp tm = new Timestamp((long) (evt.getDateEvt().getTime() + (tempsnv * (ip + 1))));
                //System.out.println("ip:" + ip+ "tmps = "+ tmps + " vitessenv: "+vitessenv);
                //System.out.println("donne  l'indice " + ip + " = " +lat+ "," +lon+", "+tm.getTime()+" vit: "+vitessenv);
                pList.add(new Events(acId, dvId, la, lo, (int) vitessenv, tm,
                        evt.getOdometerKM() + (dist * (ip + 1)), 0.0, -1, speedLimit, heading));
                Events evtds = (Events) pList.get(pList.size() - 1);
                //System.out.println(evtds.getAccountID() + " " + evtds.getDeviceID() + " " + new SimpleDateFormat("yyy-MM-dd HH:mm:ss").format(evtds.getDateEvt()) + " " +evtds.getLatitude() + " "+ evtds.getLongitude() + " " + evtds.getSpeed() + " " + evtds.getOdometerKM() + " " + evtds.getSpeedMax() + " "+evtds.getStatusCode());
            }
            //pList.addAll(pList.size() - 1, pListnw);
        } else {
            pList.add(new Events(acId, dvId, lat, lon, (int) vitesse, dateEV, odometerKM, odometerOffsetKM,
                    statusCode, speedLimit, heading));
            //System.out.println(acId + " " + dvId + " " + new SimpleDateFormat("yyy-MM-dd HH:mm:ss").format(dateEV) + " " + lat  + " "+ lon + " " + vitesse + " " + odometerKM + " " + odometerOffsetKM + " "+speedLimit);
        }
        pListnw = pList;
    }
    //pList.addAll(startIndex, pListnw);
    return pListnw;
}

From source file:report.mainReport.java

public static LinkedList addpoints(String acId, String dvId, LinkedList pList) {
    String secuInfos = "";
    int nbrarret = 0;
    int nbrpoints = 0;
    double distance;
    int startIndex = 0;
    int startIndexEnd = 0;

    LinkedList<Events> pListnw = new LinkedList<Events>();
    Events evtnxt = null;/*w w  w  .j ava  2s  .c  o  m*/
    for (int i = 0; i < pList.size(); i++) {
        Events evt = (Events) pList.get(i);
        if (evt.getDeviceID().equalsIgnoreCase(dvId)) {
            String request = "";
            int k = i + 2;
            if (k >= pList.size())
                k = pList.size();
            for (int j = i; j < k; j++) {
                evtnxt = (Events) pList.get(j);
                if (evtnxt.getDeviceID().equals(dvId)) {
                    request = request + "loc=" + evtnxt.getLatitude() + "," + evtnxt.getLongitude();
                    nbrpoints++;
                    startIndexEnd = j;
                }
            }
            if (nbrpoints > 1) {
                request = osrm + request + "&instructions=false&alt=false";
                ArrayList<Location> polyline = sendGetLoc(request, "viaroute");
                //distance = Double.parseDouble(rep[0])/1000.0;

                if (polyline != null) {
                    double tempsnv = (evtnxt.getDateEvt().getTime() - evt.getDateEvt().getTime())
                            / polyline.size();
                    double temps = ((evtnxt.getDateEvt().getTime() - evt.getDateEvt().getTime()) / 1000.0)
                            / 3600;
                    //System.out.println("Nombre de point nv:" + polyline.size()+ " tmps a ajouter = "+ tempsnv);
                    for (int ip = 0; ip < polyline.size(); ip++) {
                        double tmps = evt.getDateEvt().getTime() + (tempsnv * (ip + 1));
                        int dist = Integer.parseInt(((Location) polyline.get(ip)).getDistance()) / 1000;
                        double vitessenv = dist / temps;
                        double lat = ((Location) polyline.get(ip)).getLatitude();
                        double lon = ((Location) polyline.get(ip)).getLongitude();
                        Timestamp tm = new Timestamp(
                                (long) (evt.getDateEvt().getTime() + (tempsnv * (ip + 1))));
                        //System.out.println("ip:" + ip+ "tmps = "+ tmps + " vitessenv: "+vitessenv);
                        //System.out.println("donne  l'indice " + ip + " = " +lat+ "," +lon+", "+tm.getTime()+" vit: "+vitessenv);
                        pListnw.add(new Events(acId, dvId, lat, lon, vitessenv, tm, 0.0, 0.0, -1,
                                (int) evt.getSpeedMax(), 0));
                        if (startIndex < 1)
                            startIndex = i;
                    }
                }
            }
            request = "";
            nbrpoints = 0;
            i = k - 1;
        }
    }
    //pList.addAll(startIndex, pListnw);
    return pListnw;
}

From source file:eu.power_switch.gui.fragment.configure_receiver.ConfigureReceiverDialogPage3SetupFragment.java

private void initData(DipReceiver receiver) {
    LinkedList<DipSwitch> dips = receiver.getDips();

    int i;//from w ww  .j ava  2s. co  m
    for (i = 0; i < receiver.getDipNames().size(); i++) {
        SwitchCompat currentSwitch = dipViewList.get(i);
        currentSwitch.setText(receiver.getDipNames().get(i));
        currentSwitch.setVisibility(View.VISIBLE);
        currentSwitch.setChecked(dips.get(i).isChecked());
    }
    while (i < 10) {
        SwitchCompat currentSwitch = dipViewList.get(i);
        currentSwitch.setVisibility(View.INVISIBLE);
        i++;
    }

    dipSwitchArrayList = new ArrayList<>();
    for (SwitchCompat switchCompat : dipViewList) {
        if (switchCompat.getVisibility() == View.VISIBLE) {
            dipSwitchArrayList.add(new DipSwitch(switchCompat.getText().toString(), switchCompat.isChecked()));
        }
    }
}

From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.TelemetryResource.java

/**
 * In this method, usage made is calculated on per resource basis in the cumulative meters
 * <p/>/*from   w w w.  j av  a 2s  .  co  m*/
 * Pseudo Code<br/>
 * 1. Traverse through the linkedlist<br/>
 * 2. Treat the first point subtracting the last inserted value to the current point one.<br/>
 * 3. Treat the N points with the last volumes.<br/>
 * 4. Add the updates sample object into an arraylist
 *
 * @param cMeterArr  This is an arrayList of type CumulativeMeterData containing sample object with the usage information
 * @param linkedList This is a Linked List of type CumulativeMeterData containing elements from a particular resource
 * @return An arrayList of type CumulativeMeterData containing sample objects with the usage information
 */
private ArrayList<CumulativeMeterData> calculateCumulativeMeterUsage(ArrayList<CumulativeMeterData> cMeterArr,
        LinkedList<CumulativeMeterData> linkedList) {
    logger.trace(
            "BEGIN ArrayList<CumulativeMeterData> calculateCumulativeMeterUsage(ArrayList<CumulativeMeterData> cMeterArr, LinkedList<CumulativeMeterData> linkedList)");
    long diff;
    //BigInteger maxMeterValue ;

    long oldVolume = 0;
    long newVolume;
    long lastUsage = 0;
    TSDBResource dbResource = new TSDBResource();
    for (int i = 0; i < linkedList.size(); i++) {
        if (i == 0) {
            //First point Treatment
            oldVolume = dbResource.getLastVolume(linkedList.get(i).getMeter(),
                    linkedList.get(i).getResource_id(), linkedList.get(i).getUser_id());
        } else
            //N point Treatment
            oldVolume = lastUsage;
        newVolume = linkedList.get(i).getVolume();
        if (newVolume >= oldVolume) {
            //Normal use case where the new usage is greater or equals than the last inserted point.
            //TODO: what if the value is higher but it's coz the counter reset and get higher? (if we have message queues or event based and they advise before reset, that's solved
            lastUsage = newVolume - oldVolume;
        } else {
            //TODO: if the volume is lower than the lastInserted get the maximum for that meter and operate on it.
            lastUsage = newVolume;
        }
        linkedList.get(i).setUsage(lastUsage);
        cMeterArr.add(linkedList.get(i));
    }
    cMeterArr.add(linkedList.getLast());
    logger.trace(
            "END ArrayList<CumulativeMeterData> calculateCumulativeMeterUsage(ArrayList<CumulativeMeterData> cMeterArr, LinkedList<CumulativeMeterData> linkedList)");
    return cMeterArr;
}