Example usage for java.util LinkedList remove

List of usage examples for java.util LinkedList remove

Introduction

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

Prototype

public E remove(int index) 

Source Link

Document

Removes the element at the specified position in this list.

Usage

From source file:com.github.lindenb.jvarkit.tools.misc.BamTile.java

@Override
public Collection<Throwable> call(final String inputName) throws Exception {
    SAMRecordIterator iter = null;/*from w w  w .j av  a2  s.  c o  m*/
    SamReader sfr = null;
    SAMFileWriter sfw = null;
    try {
        sfr = openSamReader(inputName);

        SAMFileHeader header1 = sfr.getFileHeader();
        if (header1 == null) {
            return wrapException("File header missing");
        }

        if (header1.getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
            return wrapException("File header not sorted on coordinate");
        }

        SAMFileHeader header2 = header1.clone();
        header2.addComment(getName() + ":" + getVersion() + ":" + getProgramCommandLine());

        sfw = openSAMFileWriter(header2, true);

        SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header1);
        iter = sfr.iterator();
        LinkedList<SAMRecord> buffer = new LinkedList<>();
        for (;;) {
            SAMRecord rec = null;
            if (iter.hasNext()) {
                rec = progress.watch(iter.next());
                if (rec.getReadUnmappedFlag())
                    continue;
                if (!buffer.isEmpty()) {
                    SAMRecord last = buffer.getLast();
                    if (last.getReferenceIndex() == rec.getReferenceIndex()
                            && last.getAlignmentStart() <= rec.getAlignmentStart()
                            && last.getAlignmentEnd() >= rec.getAlignmentEnd()) {
                        continue;
                    }
                }
            }
            if (rec == null
                    || (!buffer.isEmpty() && buffer.getLast().getReferenceIndex() != rec.getReferenceIndex())) {
                while (!buffer.isEmpty()) {
                    sfw.addAlignment(buffer.removeFirst());
                }
                if (rec == null)
                    break;
            }
            buffer.add(rec);

            if (buffer.size() > 2) {
                int index = buffer.size();
                SAMRecord prev = buffer.get(index - 3);
                SAMRecord curr = buffer.get(index - 2);
                SAMRecord next = buffer.get(index - 1);

                if (prev.getAlignmentEnd() >= next.getAlignmentStart()
                        || curr.getAlignmentEnd() <= prev.getAlignmentEnd()) {
                    buffer.remove(index - 2);
                } else if (curr.getAlignmentStart() == prev.getAlignmentStart()
                        && curr.getAlignmentEnd() > prev.getAlignmentEnd()) {
                    buffer.remove(index - 3);
                }

            }
            while (buffer.size() > 3) {
                sfw.addAlignment(buffer.removeFirst());
            }

        }
        progress.finish();
        LOG.info("done");
        return Collections.emptyList();
    } catch (Exception err) {
        return wrapException(err);
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(sfr);
        CloserUtil.close(sfw);
    }
}

From source file:org.ocsoft.rosetto.models.base.elements.values.ListValue.java

/**
 * ????????./*from  ww  w.  j  a v a 2  s  .c  o m*/
 * ????????????????.
 * ???????????.
 * ????ActionCall??.
 * @param func ??
 * @return ????
 */
public Map<String, RosettoValue> bind(RosettoFunction func, Scope currentScope) {
    if (func == null)
        throw new IllegalArgumentException("???null??");

    //??
    Map<String, RosettoValue> result = new HashMap<String, RosettoValue>();
    //????
    LinkedList<String> funcArgs = new LinkedList<String>();

    //???????????
    int requiredArgsCount = 0;

    //????????
    for (String s : func.getArguments()) {
        int eqIndex = s.indexOf("=");
        if (eqIndex == -1) {
            //?????????
            funcArgs.add(s);
            //????????
            requiredArgsCount++;
        } else {
            //????
            String key = s.substring(0, eqIndex);
            RosettoValue value = Values.create(s.substring(eqIndex + 1, s.length()));
            //?
            funcArgs.add(key);
            //???????
            result.put(key, value);
        }
    }

    //??????

    //??
    for (Entry<String, RosettoValue> e : getMap().entrySet()) {
        //?Entry??funcArgs?????funcArg
        boolean removed = funcArgs.remove(e.getKey());
        //????
        if (removed)
            requiredArgsCount--;
        //??
        result.put(e.getKey(), e.getValue());
    }

    //??
    String mutableArg = searchMutableArg(funcArgs);
    if (mutableArg != null) {
        //????????

        //????????
        //??????????-1
        if (requiredArgsCount - 1 > getList().size()) {
            throw new IllegalArgumentException("???????: "
                    + getList().toString() + "|" + func.getArguments());
        }

        //????????????????
        //??
        List<RosettoValue> margs = new LinkedList<RosettoValue>();
        for (int i = 0; i < getList().size(); i++) {
            RosettoValue v = getList().get(i);
            if (!funcArgs.isEmpty()) {
                //???????????pop?????????
                String farg = funcArgs.pollFirst();
                //??????????
                if (farg.equals(mutableArg)) {
                    //??????????????
                    if (!funcArgs.isEmpty()) {
                        throw new IllegalArgumentException("mutable args must be last element");
                    }
                    //??
                    margs.add(v);
                }
                //????????
                result.put(farg, v);
            } else {
                //??
                margs.add(v);
            }
        }

        //?????
        if (margs.size() > 0) {
            //?????
            String margName = mutableArg.substring(1);
            //listvalue???
            result.put(margName, new ListValue(margs));
        }

    } else {
        //???????
        if (requiredArgsCount > getList().size()) {
            throw new IllegalArgumentException("???????: "
                    + getList().toString() + "|" + func.getArguments());
        } else if (funcArgs.size() < getList().size()) {
            throw new IllegalArgumentException(
                    "?????: " + getList().toString() + "|" + func.getArguments());
        }
        for (RosettoValue value : getList()) {
            //?????????
            if (value.getType() == ValueType.ACTION_CALL) {
                //ActionCall??????
                result.put(funcArgs.pollFirst(), ((ActionCall) value).evaluate(currentScope));
            } else {
                result.put(funcArgs.pollFirst(), value);
            }
        }
    }
    return result;
}

From source file:edu.cornell.med.icb.clustering.QTClusterer.java

/**
 * Eliminate any instances that will never cluster with anything else.
 * @param calculator The distance calculator to use.
 * @param qualityThreshold The threshold that determines whether or not an instance will cluster
 * @param instanceList The list of instance to check
 * @param clusterProgressLogger Where to log progress
 * @return A non-null but possibly empty list of clusters that each contain a single instance
 *///from   w  ww .j a  v a 2s  . c o m
private IntList identifySingletonClusters(final SimilarityDistanceCalculator calculator,
        final double qualityThreshold, final LinkedList<Integer> instanceList,
        final ProgressLogger clusterProgressLogger) {
    LOGGER.info("Searching for instances that will form singleton clusters");
    final IntArrayList singletonClusters = new IntArrayList();

    for (int i = 0; i < instanceCount; i++) {
        boolean singleton = true;
        for (final int j : instanceList) {
            if (i != j) {
                final double distance = calculator.distance(i, j);
                if (distance <= qualityThreshold) {
                    // the instance i is likely to be clustered with some j
                    singleton = false;
                    break;
                }
            }
        }

        // instance i is too far from anything else to ever cluster so it's a singleton cluster
        if (singleton) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("adding singleton instance " + i + " to cluster " + clusterCount);
            }

            // i is a singleton cluster
            singletonClusters.add(i);

            // and we can remove it from further consideration later
            // note: we have to remove the "element i" and not the "element at i"
            instanceList.remove(Integer.valueOf(i));

            if (logClusterProgress) {
                clusterProgressLogger.update();
            }
        }
    }

    LOGGER.info(singletonClusters.size() + " singleton instances found");
    // save the singletons for last since we ideally want to return clusters in size order
    singletonClusters.trim();

    return singletonClusters;
}

From source file:org.openconcerto.sql.element.SQLElement.java

public synchronized final void removeFromMDPath(final String mdVariant) {
    final LinkedList<String> newL = new LinkedList<String>(this.mdPath);
    if (newL.remove(mdVariant))
        this.mdPath = Collections.unmodifiableList(newL);
}

From source file:org.guzz.GuzzContextImpl.java

protected void initUnOrderedService(Map services, LinkedList queuedServices, ServiceInfo serviceInfo) {
    if (serviceInfo.hasDependedServices()) {
        queuedServices.addLast(serviceInfo);

        String[] dependsOn = serviceInfo.getDependedServices();

        for (int k = 0; k < dependsOn.length; k++) {
            for (int i = 0; i < queuedServices.size(); i++) {
                String queueServiceName = ((ServiceInfo) queuedServices.get(i)).getServiceName();

                if (queueServiceName.equals(dependsOn[k])) {
                    throw new InvalidConfigurationException("cycle dependencies found in guzz services. From ["
                            + queueServiceName + "] to [" + dependsOn[k] + "].");
                }//from  w  ww  . j a va  2  s .co m
            }

            //add depended-services from un-inited-services to the queuedServices
            ServiceInfo si = (ServiceInfo) services.remove(dependsOn[k]);
            if (si != null) {
                //process the depended service first.
                initUnOrderedService(services, queuedServices, si);
            } else {
                //the service may have already been registered to the ServiceManager
            }
        }

        //Depended services have been inited. Start the current one.
        Service s = ServiceManagerImpl.createNewService(this, configServer, serviceInfo);
        serviceManager.registerService(s);

        queuedServices.remove(serviceInfo);
    } else {
        Service s = ServiceManagerImpl.createNewService(this, configServer, serviceInfo);
        serviceManager.registerService(s);
    }
}

From source file:Interfaces.EstadisticaConocioGui.java

/**
 * Creates new form EstadisticaConocioGui
 *//*from w w w .j  a  v  a  2 s  .  co  m*/
public EstadisticaConocioGui(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    abrirBase();
    LazyList<Socio> socios = Socio.findAll();
    Iterator<Socio> it = socios.iterator();
    Socio s;
    String nosConocio;
    Boolean activo;
    Integer[] nosConocioSuma = { 0, 0, 0, 0, 0, 0 };
    LinkedList<Pair<Integer, Integer>> actividadesRealizan = new LinkedList<>();
    LazyList<Arancel> aranceles = Arancel.findAll();
    Iterator<Arancel> itArancel = aranceles.iterator();
    while (itArancel.hasNext()) {
        Pair<Integer, Integer> par = new Pair<>(itArancel.next().getInteger("id"), 0);
        actividadesRealizan.add(par);
    }
    while (it.hasNext()) {
        s = it.next();
        nosConocio = s.getString("NOSCONOCIOPOR");
        activo = s.getBoolean("ACTIVO");
        switch (nosConocio) {
        case "NO ESPECIFICA":
            nosConocioSuma[0]++;
            break;
        case "VIO EL GIMNASIO":
            nosConocioSuma[1]++;
            break;
        case "POR RADIO":
            nosConocioSuma[2]++;
            break;
        case "POR TV":
            nosConocioSuma[3]++;
            break;
        case "REDES SOCIALES":
            nosConocioSuma[4]++;
            break;
        case "UN AMIGO/A":
            nosConocioSuma[5]++;
            break;
        }
        if (activo) {
            LazyList<Socioarancel> arancelesSocio = Socioarancel.where("id_socio = ?", s.getId());
            Iterator<Socioarancel> itAr = arancelesSocio.iterator();
            while (itAr.hasNext()) {
                Socioarancel ar = itAr.next();
                boolean sume = false;
                int i = 0;
                while (i < actividadesRealizan.size() && !sume) {
                    if (actividadesRealizan.get(i).first() == ar.getInteger("id_arancel")) {
                        Pair<Integer, Integer> aux = new Pair<>(actividadesRealizan.get(i).first(),
                                actividadesRealizan.get(i).second() + 1);
                        actividadesRealizan.remove(i);
                        actividadesRealizan.add(i, aux);
                        sume = true;
                    }
                    i++;
                }
            }
        }
    }
    DefaultCategoryDataset datasetConocio = new DefaultCategoryDataset();
    datasetConocio.setValue(nosConocioSuma[0], "nos conocieron", "NO ESPECIFICA");
    datasetConocio.setValue(nosConocioSuma[1], "nos conocieron", "VIO EL GIMNASIO");
    datasetConocio.setValue(nosConocioSuma[2], "nos conocieron", "POR RADIO");
    datasetConocio.setValue(nosConocioSuma[3], "nos conocieron", "POR TV");
    datasetConocio.setValue(nosConocioSuma[4], "nos conocieron", "REDES SOCIALES");
    datasetConocio.setValue(nosConocioSuma[5], "nos conocieron", "UN AMIGO/A");
    JFreeChart chart = ChartFactory.createBarChart3D("Estadisticas por donde nos conocieron", "donde",
            "cantidad de personas", datasetConocio, PlotOrientation.VERTICAL, true, true, false);
    // Creacin del panel con el grfico
    ChartPanel panelGrafico = new ChartPanel(chart);
    pnlConocio.add(panelGrafico);

    DefaultCategoryDataset datasetAct = new DefaultCategoryDataset();
    for (int i = 0; i < actividadesRealizan.size(); i++) {
        String nombreAct = Arancel.findById(actividadesRealizan.get(i).first()).getString("nombre");
        datasetAct.setValue(actividadesRealizan.get(i).second(), "actividad", nombreAct);

    }
    JFreeChart chartAct = ChartFactory.createBarChart3D("Estadisticas que actividad realizan", "actividad",
            "cantidad de personas", datasetAct, PlotOrientation.VERTICAL, true, true, false);
    // Creacin del panel con el grfico
    ChartPanel panelGraficoAc = new ChartPanel(chartAct);
    pnlAct.add(panelGraficoAc);

}

From source file:uk.ac.diamond.scisoft.analysis.rcp.inspector.InspectionTab.java

final public int[] getOrder(int rank) {
    if (rank == 1)
        return new int[] { 0 };

    LinkedList<Integer> orders = new LinkedList<Integer>();
    for (int i = 0; i < rank; i++)
        orders.add(i);//from w ww .j av  a2  s . c o m

    int[] cOrder = new int[rank];
    int i = 0;
    for (PlotAxisProperty p : paxes) {
        if (!p.isInSet())
            continue;

        int d = p.getDimension();
        cOrder[i++] = d;
        orders.remove((Integer) d);
    }

    for (; i < rank; i++) {
        int d = orders.removeFirst();
        cOrder[i] = d;
    }
    return cOrder;
}

From source file:net.lightbody.bmp.proxy.jetty.http.HttpContext.java

/** Get the file classpath of the context.
 * This method makes a best effort to return a complete file
 * classpath for the context.//w ww. ja va2  s. c o m
 * It is obtained by walking the classloader hierarchy and looking for
 * URLClassLoaders.  The system property java.class.path is also checked for
 * file elements not already found in the loader hierarchy.
 * @return Path of files and directories for loading classes.
 * @exception IllegalStateException HttpContext.initClassLoader
 * has not been called.
 */
public String getFileClassPath() throws IllegalStateException {

    ClassLoader loader = getClassLoader();
    if (loader == null)
        throw new IllegalStateException("Context classloader not initialized");

    LinkedList paths = new LinkedList();
    LinkedList loaders = new LinkedList();

    // Walk the loader hierarchy
    while (loader != null) {
        loaders.add(0, loader);
        loader = loader.getParent();
    }

    // Try to handle java2compliant modes
    loader = getClassLoader();
    if (loader instanceof ContextLoader && !((ContextLoader) loader).isJava2Compliant()) {
        loaders.remove(loader);
        loaders.add(0, loader);
    }

    for (int i = 0; i < loaders.size(); i++) {
        loader = (ClassLoader) loaders.get(i);

        if (log.isDebugEnabled())
            log.debug("extract paths from " + loader);
        if (loader instanceof URLClassLoader) {
            URL[] urls = ((URLClassLoader) loader).getURLs();
            for (int j = 0; urls != null && j < urls.length; j++) {
                try {
                    Resource path = Resource.newResource(urls[j]);
                    if (log.isTraceEnabled())
                        log.trace("path " + path);
                    File file = path.getFile();
                    if (file != null)
                        paths.add(file.getAbsolutePath());
                } catch (Exception e) {
                    LogSupport.ignore(log, e);
                }
            }
        }
    }

    // Add the system classpath elements from property.
    String jcp = System.getProperty("java.class.path");
    if (jcp != null) {
        StringTokenizer tok = new StringTokenizer(jcp, File.pathSeparator);
        while (tok.hasMoreTokens()) {
            String path = tok.nextToken();
            if (!paths.contains(path)) {
                if (log.isTraceEnabled())
                    log.trace("PATH=" + path);
                paths.add(path);
            } else if (log.isTraceEnabled())
                log.trace("done=" + path);
        }
    }

    StringBuffer buf = new StringBuffer();
    Iterator iter = paths.iterator();
    while (iter.hasNext()) {
        if (buf.length() > 0)
            buf.append(File.pathSeparator);
        buf.append(iter.next().toString());
    }

    if (log.isDebugEnabled())
        log.debug("fileClassPath=" + buf);
    return buf.toString();
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.inspector.InspectionTab.java

@Override
protected void repopulateCombos(String oldName, String newName) {
    if (combos == null)
        return;/*from ww w .  ja v  a2 s. c  om*/

    if (daxes != null && daxes.size() != 1) {
        super.repopulateCombos(oldName, newName);
        return;
    }

    // cascade through plot axes strings and indices
    // reduce choice each time
    int cSize = combos.size() - comboOffset;
    LinkedList<String> sAxes = getAllAxisNames();

    int jmax = daxes.size();
    if (jmax == 0)
        return;

    boolean fromAxisSelection = oldName != null && newName != null;
    String a = null;
    for (int i = 0; i < cSize; i++) {
        Combo c = combos.get(i + comboOffset);
        a = (fromAxisSelection && i < jmax) ? daxes.get(i).getSelectedName() : c.getItem(c.getSelectionIndex());
        c.removeAll();

        if (!sAxes.contains(a)) {
            a = sAxes.get(0);
        }
        if (!fromAxisSelection) {
            if (i < jmax)
                daxes.get(i).selectAxis(a, false);
        }
        for (String p : sAxes)
            c.add(p);

        c.setText(a);
        sAxes.remove(a);
        if (paxes != null) {
            PlotAxisProperty p = paxes.get(i + comboOffset);
            if (p.isInSet()) {
                p.setName(a, false);
            }
        }

    }
    if (a != null && paxes != null) {
        if (paxes.get(cSize - 1 + comboOffset).isInSet()) {
            paxes.get(cSize - 1 + comboOffset).setName(a);
        }
    }

}

From source file:uk.ac.diamond.scisoft.analysis.rcp.inspector.InspectionTab.java

@Override
protected void populateCombos() {
    Combo c = combos.get(0);//from  w  w w  .  j  a v  a2s.  co m
    c.removeAll();
    c.add(CONSTANT);
    String name = dataset == null ? null : dataset.getName();
    if (name == null || name.length() == 0)
        c.add(DATA);
    else
        c.add(name);
    c.setText(CONSTANT);
    if (paxes != null) {
        PlotAxisProperty p = paxes.get(0);
        p.setName(CONSTANT, false);
    }

    if (daxes != null && daxes.size() != 1) {
        super.populateCombos();
        return;
    }

    int cSize = combos.size() - comboOffset;
    LinkedList<String> sAxes = getAllAxisNames();
    int jmax = daxes.size();

    for (int i = 0; i < cSize; i++) {
        c = combos.get(i + comboOffset);
        c.removeAll();
        PlotAxisProperty p = paxes.get(i + comboOffset);

        String a;
        if (i < jmax) {
            a = daxes.get(i).getSelectedName();
            if (!sAxes.contains(a)) {
                a = sAxes.getLast();
            }
        } else {
            a = sAxes.getLast();
        }

        p.clear();
        int pmax = sAxes.size();
        for (int j = 0; j < pmax; j++) {
            String n = sAxes.get(j);
            p.put(j, n);
            c.add(n);
        }
        c.setText(a);
        sAxes.remove(a);
        p.setName(a, false);
        p.setInSet(true);
    }
}