Example usage for java.util List remove

List of usage examples for java.util List remove

Introduction

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

Prototype

E remove(int index);

Source Link

Document

Removes the element at the specified position in this list (optional operation).

Usage

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java

private static HashMap<String, DefaultCategoryDataset> dataSetToJFreeChartDefaultCategoryDataset(
        DataSet dataset) {//from   www .  j  a  va2  s .c om
    HashMap<String, DefaultCategoryDataset> ret = new HashMap<String, DefaultCategoryDataset>();

    List<String> columns = new ArrayList(dataset.getHeader());
    //List<String> neededColumns = new ArrayList<String>();
    columns.remove(dataset.getIndependent());

    //Processing independent variable first.
    DefaultCategoryDataset pactualDS = new DefaultCategoryDataset();
    List<Double> independent = dataset.getCol(CoreConfiguration.PACTUAL_LABEL);
    for (int i = 0; i < independent.size(); i++) {
        pactualDS.addValue(independent.get(i), CoreConfiguration.PACTUAL_LABEL, Integer.toString(i));
    }
    ret.put(CoreConfiguration.PACTUAL_LABEL, pactualDS);

    //Adding rest of variables
    DefaultCategoryDataset metricDS = new DefaultCategoryDataset();
    //        for(String metric : columns) {
    //
    //            List<Double> values = dataset.getCol(metric);
    //            for(int i = 0; i < values.size(); i++) {
    //                metricDS.addValue(values.get(i), metric, Integer.toString(i));
    //            }
    //        }
    addColumnToDefaultCategoryDataSet(metricDS, CoreConfiguration.PIDLE_LABEL,
            dataset.getCol(CoreConfiguration.PIDLE_LABEL));
    addColumnToDefaultCategoryDataSet(metricDS, CoreConfiguration.PCPU_LABEL,
            dataset.getCol(CoreConfiguration.PCPU_LABEL));
    addColumnToDefaultCategoryDataSet(metricDS, CoreConfiguration.PMEM_LABEL,
            dataset.getCol(CoreConfiguration.PMEM_LABEL));
    addColumnToDefaultCategoryDataSet(metricDS, CoreConfiguration.PDISK_LABEL,
            dataset.getCol(CoreConfiguration.PDISK_LABEL));
    addColumnToDefaultCategoryDataSet(metricDS, CoreConfiguration.PNET_LABEL,
            dataset.getCol(CoreConfiguration.PNET_LABEL));

    ret.put(CoreConfiguration.PPREDICTED_LABEL, metricDS);

    return ret;
}

From source file:Test.java

private static void startUpdatingThread(final List<String> list) {
    updatingThread = new Thread(new Runnable() {
        long counter = 0;

        public void run() {
            while (!Thread.interrupted()) {
                int size = list.size();
                Random random = new Random();
                if (random.nextBoolean()) {
                    if (size > 1) {
                        list.remove(random.nextInt(size - 1));
                    }/*from  ww  w .  ja v a 2  s.  c  o  m*/
                } else {
                    if (size < 20) {
                        list.add("Random string " + counter);
                    }
                }
                counter++;
            }
        }

    });
    updatingThread.start();
}

From source file:Main.java

public static <T> List<List<T>> getAllCombinations(final List<T> pList) {
    final List<List<T>> result = new ArrayList<List<T>>(pList.size());
    // if it has only one element, the resulting list
    // is a list with the single element
    if (pList.size() == 1) {
        final List<T> temp = new ArrayList<T>();
        temp.add(pList.get(0));/*from  www  . j a v  a  2  s .co  m*/
        result.add(temp);
    } else {
        for (final T element : pList) {
            // create a new sublist
            final List<T> temp = new ArrayList<T>(pList);
            // remove the current item
            temp.remove(element);
            // get the all combinations for the sublist
            final List<List<T>> sublist = getAllCombinations(temp);
            for (final List<T> item : sublist) {
                item.add(element);
            }

            result.addAll(sublist);
        }
    }

    return result;
}

From source file:lanchon.dexpatcher.Parser.java

public static Configuration parseCommandLine(String[] args) throws ParseException {

    Configuration config = new Configuration();

    Options options = getOptions();/*from   www.  ja v a  2  s.  c  om*/
    CommandLine cl = new PosixParser().parse(options, args);

    if (cl.hasOption("help")) {
        printUsage();
        return null;
    }

    if (cl.hasOption("version")) {
        System.out.println(Main.getVersion());
        return null;
    }

    @SuppressWarnings("unchecked")
    List<String> files = cl.getArgList();
    if (files.isEmpty())
        throw new ParseException("Missing argument: <source-dex-apk-or-dir>");
    config.sourceFile = files.remove(0);
    config.patchFiles = files;
    config.patchedFile = cl.getOptionValue("output");

    Number apiLevel = (Number) cl.getParsedOptionValue("api-level");
    if (apiLevel != null)
        config.apiLevel = apiLevel.intValue();

    config.multiDex = cl.hasOption("multi-dex");
    if (cl.hasOption("multi-dex-threaded")) {
        config.multiDex = true;
        config.multiDexJobs = 0;
    }
    Number multiDexJobs = (Number) cl.getParsedOptionValue("multi-dex-jobs");
    if (multiDexJobs != null) {
        config.multiDex = true;
        config.multiDexJobs = multiDexJobs.intValue();
    }

    Number maxDexPoolSize = (Number) cl.getParsedOptionValue("max-dex-pool-size");
    if (maxDexPoolSize != null)
        config.maxDexPoolSize = maxDexPoolSize.intValue();

    config.annotationPackage = cl.getOptionValue("annotations", Context.DEFAULT_ANNOTATION_PACKAGE);
    config.dexTagSupported = cl.hasOption("compat-dextag");

    config.logLevel = WARN;
    if (cl.hasOption("quiet"))
        config.logLevel = ERROR;
    if (cl.hasOption("verbose"))
        config.logLevel = INFO;
    if (cl.hasOption("debug"))
        config.logLevel = DEBUG;

    if (cl.hasOption("path"))
        config.sourceCodeRoot = "";
    config.sourceCodeRoot = cl.getOptionValue("path-root", config.sourceCodeRoot);
    config.timingStats = cl.hasOption("stats");

    config.dryRun = cl.hasOption("dry-run");

    return config;

}

From source file:com.redhat.rhtracking.persistance.services.Queries.java

public static <T extends Catalog, K extends Serializable> void initCatalog(List<String> catalogue,
        CrudRepository<T, K> repository, Class<T> type) {
    logger.info("Starting " + type.getSimpleName() + " catalog");
    Iterable<T> typeItr = repository.findAll();
    for (T t : typeItr) {
        if (catalogue.contains(t.toString())) {
            catalogue.remove(t.toString());
        }/*w  w w. j  a v a  2s  .  com*/
    }
    if (!catalogue.isEmpty()) {
        try {
            for (String s : catalogue) {
                T missing = type.newInstance();
                missing.setType(s);
                repository.save(missing);
            }
        } catch (IllegalAccessException | InstantiationException ex) {
            logger.error(ex);
        }
    }
}

From source file:Main.java

public static <T> Collection<T> move(List<T> collection, int fromPosition, int toPosition) {
    int maxPosition = collection.size() - 1;
    if (fromPosition == toPosition || fromPosition > maxPosition || toPosition > maxPosition)
        return collection;

    if (fromPosition < toPosition) {
        T fromModel = collection.get(fromPosition);
        T toModel = collection.get(toPosition);

        collection.remove(fromPosition);
        collection.add(collection.indexOf(toModel) + 1, fromModel);
    } else {//w w  w .j a  v  a2 s .  com
        T fromModel = collection.get(fromPosition);
        collection.remove(fromPosition);
        collection.add(toPosition, fromModel);
    }

    return collection;
}

From source file:PackageUtils.java

public static String getPackageNameByNameSpaceURI(String nameSpaceURI) {
    int idx = nameSpaceURI.indexOf(':');
    String scheme = "";
    if (idx >= 0) {
        scheme = nameSpaceURI.substring(0, idx);
        if ("http".equalsIgnoreCase(scheme) || "urn".equalsIgnoreCase(scheme)) {
            nameSpaceURI = nameSpaceURI.substring(idx + 1);
        }/*from   w  w w.ja v a  2s  .  c o  m*/
    }

    List<String> tokens = tokenize(nameSpaceURI, "/: ");
    if (tokens.size() == 0) {
        return null;
    }

    if (tokens.size() > 1) {
        String lastToken = tokens.get(tokens.size() - 1);
        idx = lastToken.lastIndexOf('.');
        if (idx > 0) {
            lastToken = lastToken.substring(0, idx);
            tokens.set(tokens.size() - 1, lastToken);
        }
    }

    String domain = tokens.get(0);
    idx = domain.indexOf(':');
    if (idx >= 0) {
        domain = domain.substring(0, idx);
    }
    List<String> r = reverse(tokenize(domain, "urn".equals(scheme) ? ".-" : "."));
    if ("www".equalsIgnoreCase(r.get(r.size() - 1))) {
        // remove leading www
        r.remove(r.size() - 1);
    }

    // replace the domain name with tokenized items
    tokens.addAll(1, r);
    tokens.remove(0);

    // iterate through the tokens and apply xml->java name algorithm
    for (int i = 0; i < tokens.size(); i++) {

        // get the token and remove illegal chars
        String token = tokens.get(i);
        token = removeIllegalIdentifierChars(token);

        // this will check for reserved keywords
        if (containsReservedKeywords(token)) {
            token = '_' + token;
        }

        tokens.set(i, token.toLowerCase());
    }

    // concat all the pieces and return it
    return combine(tokens, '.');
}

From source file:Main.java

/**
 * remove duplicate entries in list//from  w ww  .  j av  a2s.co  m
 * 
 * @param <V>
 * @param sourceList
 * @return the count of entries be removed
 */
public static <V> int distinctList(List<V> sourceList) {
    if (isEmpty(sourceList)) {
        return 0;
    }

    int sourceCount = sourceList.size();
    int sourceListSize = sourceList.size();
    for (int i = 0; i < sourceListSize; i++) {
        for (int j = (i + 1); j < sourceListSize; j++) {
            if (sourceList.get(i).equals(sourceList.get(j))) {
                sourceList.remove(j);
                sourceListSize = sourceList.size();
                j--;
            }
        }
    }
    return sourceCount - sourceList.size();
}

From source file:main.RankerOCR.java

/**
 * Show the help on CLI./*from w ww. ja v a  2s.com*/
 * <p>
 * Help is from <br>
 * -The file help.txt in the JAR <br>
 * -The HelpFormatter <br>
 * -Options.
 */
private static void showHelp(HelpFormatter hf, Options options) {
    try {
        //First, print the header of help and brief summary of the behaviour
        //<editor-fold defaultstate="collapsed" desc="Print summary">
        InputStream f = RankerOCR.class.getResourceAsStream("/resources/help.txt");
        InputStreamReader fr = new InputStreamReader(f);
        BufferedReader b = new BufferedReader(fr);
        StringBuilder s = new StringBuilder();
        while (true) {
            String line = b.readLine();
            if (line == null) {
                break;
            } else {
                s.append(line);
                s.append("\n");
            }
        }
        printFormated(s.toString());
        //</editor-fold>
        //Second, print the options list
        hf.printHelp("java -jar Ranker-OCR [options]", options);
        //Finnaly print the rankers list
        //<editor-fold defaultstate="collapsed" desc="Print rankers">
        try {

            System.out.println("\nRankers list:");
            List<Class> lst = PackageClassList.getClasses("ranking");
            lst.remove(ranking.Ranker.class);
            lst.stream().forEach((c) -> {
                if (!c.isInterface()) {
                    System.out.println(" -" + c.getSimpleName());
                }
            });
        } catch (ClassNotFoundException | IOException ex) {
            printFormated(ex.getLocalizedMessage());
            System.exit(-101);
        }
        //</editor-fold>
    } catch (IOException ex) {
        printFormated(ex.getLocalizedMessage());
        System.exit(-102);
    }
}

From source file:com.norconex.commons.lang.io.IOUtil.java

/**
 * Gets the last lines from an input stream, using the specified encoding.  
 * This method is null-safe./*  ww  w  . j a v  a  2s . c  o  m*/
 * If the input stream is null or empty, an empty string array will
 * be returned.  
 * <br><br>
 * Use of this method can often be a bad idea (especially on large streams)
 * since it needs to read the entire stream to return the last lines. 
 * If you are dealing with files, use 
 * {@link com.norconex.commons.lang.file.FileUtil#tail(
 * File, String, int)} instead, which can read
 * a file starting from the end. 
 * @param is input stream
 * @param encoding character encoding
 * @param lineQty maximum number of lines to return
 * @return lines as a string array
 * @throws IOException problem reading lines
 * @since 1.5.0
 */
public static String[] tail(final InputStream is, String encoding, final int lineQty) throws IOException {
    if (is == null) {
        return EMPTY_STRINGS;
    }
    String safeEncoding = encoding;
    if (StringUtils.isBlank(safeEncoding)) {
        safeEncoding = CharEncoding.UTF_8;
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(is, safeEncoding));
    List<String> lines = new ArrayList<String>(lineQty);
    String line;
    while ((line = br.readLine()) != null) {
        lines.add(0, line);
        if (lines.size() > lineQty) {
            lines.remove(lineQty);
        }
    }
    br.close();
    Collections.reverse(lines);
    return lines.toArray(EMPTY_STRINGS);
}