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:Main.java

/**
 * @see #getAllFiles(File)/* w ww  .j  av  a 2  s.  c  o m*/
 */
public static List<File> getAllFiles(File directory, FileFilter filter) {
    final List<File> fileList = getAllFiles(directory);
    if (filter == null)
        return fileList;

    final Iterator<File> fileIterator = fileList.iterator();
    while (fileIterator.hasNext()) {
        final File file = fileIterator.next();
        if (!filter.accept(file))
            fileList.remove(file);
    }
    return fileList;
}

From source file:com.thruzero.common.core.locator.LocatorUtils.java

/**
 * For a given childClass, start at the root base class and read the sections of each sub-class, walking down the class hierarchy
 * to the given childClass. The result is that all parameters from all inherited sections, including the given childClass,
 * are read with each subclass overwriting the common keys of any parent section. If given, optionalBaseInterface will be used as the
 * root base and placed at the top of the inheritance stack.
 *
 * @param sectionName//from   w  ww  . j a v  a2 s  .com
 * @param initStrategy
 * @param childClass
 */
public static StringMap getInheritedParameters(final InitializationStrategy initStrategy,
        final Class<?> childClass, final Class<?> optionalBaseInterface) {
    StringMap result = new StringMap();
    List<Class<?>> inheritanceList = new ArrayList<Class<?>>();

    Class<?> nextClass = childClass;
    while (nextClass != null) {
        inheritanceList.add(nextClass);
        nextClass = nextClass.getSuperclass();
    }
    inheritanceList.remove(inheritanceList.size() - 1); // remove java.lang.Object

    if (optionalBaseInterface != null) {
        inheritanceList.add(optionalBaseInterface);
    }

    ListIterator<Class<?>> iter = inheritanceList.listIterator(inheritanceList.size());
    StringMap params;
    while (iter.hasPrevious()) {
        params = initStrategy.getSectionAsStringMap(iter.previous().getName());
        if (params != null) {
            result.putAll(params);
        }
    }

    return result;
}

From source file:hk.newsRecommender.Classify.java

public static void test(Configuration conf, String testFile, int labelIndex) throws IOException {
    System.out.println("~~~ begin to test ~~~");
    AbstractNaiveBayesClassifier classifier = new StandardNaiveBayesClassifier(naiveBayesModel);

    FileSystem fsopen = FileSystem.get(conf);
    FSDataInputStream in = fsopen.open(new Path(testFile));
    CSVReader csv = new CSVReader(new InputStreamReader(in));
    csv.readNext(); // skip header

    String[] line = null;//from   ww w  .j  a  va  2 s.  c o m
    double totalSampleCount = 0.;
    double correctClsCount = 0.;
    //       String str="10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,14,0,8";
    //       List<String> newsList=new ArrayList<String>();
    //       newsList.add(str);
    //       for(int j=0;j<newsList.size();j++){
    //          line=newsList.get(j).split(",");
    while ((line = csv.readNext()) != null) {
        //          ??ID???ID?
        //          ????
        List<String> tmpList = Lists.newArrayList(line);
        String label = tmpList.get(labelIndex);
        tmpList.remove(labelIndex);
        totalSampleCount++;
        Vector vector = new RandomAccessSparseVector(tmpList.size(), tmpList.size());
        for (int i = 0; i < tmpList.size(); i++) {
            String tempStr = tmpList.get(i);
            if (StringUtils.isNumeric(tempStr)) {
                vector.set(i, Double.parseDouble(tempStr));
            } else {
                Long id = strOptionMap.get(tempStr);
                if (id != null)
                    vector.set(i, id);
                else {
                    System.out.println(StringUtils.join(tempStr, ","));
                    continue;
                }
            }
        }
        Vector resultVector = classifier.classifyFull(vector);
        int classifyResult = resultVector.maxValueIndex();
        if (StringUtils.equals(label, strLabelList.get(classifyResult))) {
            correctClsCount++;
        } else {
            //             line[labelIndex]????ID??
            //             ???????
            //             
            System.out.println("CorrectORItem=" + label + "\tClassify=" + strLabelList.get(classifyResult));
        }
    }
    //       System.out.println("Correct Ratio:" + (correctClsCount / totalSampleCount));
}

From source file:com.u2apple.tool.util.StaticMapFileUtils.java

/**
 * Merage after sorting. ?Values?Modal TODO:
 * ??ValueModal??.//w w w  .ja  v  a 2  s  .co  m
 *
 * @param models
 */
private static void fastMergeModels(List<Modal> models) {
    for (int i = 0; i < models.size() - 1;) {
        if (models.get(i).getValues().equals(models.get(i + 1).getValues())) {
            models.get(i).getProductId().addAll(models.get(i + 1).getProductId());
            models.remove(i + 1);
        } else {
            i++;
        }
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.run.task.RandomTaskCreator.java

public static void createTaskRandomSelection(int numberOfMutations, int seed, String fileName)
        throws IOException {
    Random r = new Random(seed);
    Set<Long> coveredSet = MutationCoverageFile.getCoveredMutations();
    List<Long> covered = new ArrayList<Long>(coveredSet);
    Set<Long> selected = new HashSet<Long>();
    List<String> lines = new ArrayList<String>();
    for (int i = 0; i < numberOfMutations && covered.size() > 0; i++) {
        int index = r.nextInt(covered.size());
        Long id = covered.get(index);
        covered.remove(index);
        selected.add(id);/* w  w  w. java 2s. c o  m*/
        lines.add(id + "");
    }
    // List<Mutation> mutations = QueryManager.getMutationsByIds(selected
    // .toArray(new Long[0]));
    // Collections.sort(mutations);
    File file = new File(fileName);
    FileUtils.writeLines(file, lines);

}

From source file:com.google.codelab.networkmanager.CodelabUtil.java

public static void deleteTaskItemFromFile(Context context, TaskItem taskItem) {
    List<TaskItem> taskItems = getTaskItemsFromFile(context);
    for (int i = 0; i < taskItems.size(); i++) {
        TaskItem ti = taskItems.get(i);//from w  ww. j  a va  2  s  . c  o m
        if (ti.getId().equals(taskItem.getId())) {
            taskItems.remove(i);
            break;
        }
    }
    saveTaskItemsToFile(context, taskItems);
}

From source file:cpcc.vvrte.services.task.AcoTspSimple.java

/**
 * @param index the index number to be first in the resulting array.
 * @param path the path to fix./*from w w  w. jav a  2  s. c o m*/
 */
public static void fixPath(int index, List<Integer> path) {
    int shift = path.indexOf(index);

    if (shift <= 0) {
        return;
    }

    while (shift-- > 0) {
        Integer v = path.remove(0);
        path.add(v);
    }
}

From source file:org.elasticsearch.client.RestClientTestCase.java

/**
 * Assert that the actual headers are the expected ones given the original default and request headers. Some headers can be ignored,
 * for instance in case the http client is adding its own automatically.
 *
 * @param defaultHeaders the default headers set to the REST client instance
 * @param requestHeaders the request headers sent with a particular request
 * @param actualHeaders the actual headers as a result of the provided default and request headers
 * @param ignoreHeaders header keys to be ignored as they are not part of default nor request headers, yet they
 *                      will be part of the actual ones
 *//*ww  w . j  a  va  2  s . co m*/
protected static void assertHeaders(final Header[] defaultHeaders, final Header[] requestHeaders,
        final Header[] actualHeaders, final Set<String> ignoreHeaders) {
    final Map<String, List<String>> expectedHeaders = new HashMap<>();
    final Set<String> requestHeaderKeys = new HashSet<>();
    for (final Header header : requestHeaders) {
        final String name = header.getName();
        addValueToListEntry(expectedHeaders, name, header.getValue());
        requestHeaderKeys.add(name);
    }
    for (final Header defaultHeader : defaultHeaders) {
        final String name = defaultHeader.getName();
        if (requestHeaderKeys.contains(name) == false) {
            addValueToListEntry(expectedHeaders, name, defaultHeader.getValue());
        }
    }
    Set<String> actualIgnoredHeaders = new HashSet<>();
    for (Header responseHeader : actualHeaders) {
        final String name = responseHeader.getName();
        if (ignoreHeaders.contains(name)) {
            expectedHeaders.remove(name);
            actualIgnoredHeaders.add(name);
            continue;
        }
        final String value = responseHeader.getValue();
        final List<String> values = expectedHeaders.get(name);
        assertNotNull("found response header [" + name + "] that wasn't originally sent: " + value, values);
        assertTrue("found incorrect response header [" + name + "]: " + value, values.remove(value));
        if (values.isEmpty()) {
            expectedHeaders.remove(name);
        }
    }
    assertEquals("some headers meant to be ignored were not part of the actual headers", ignoreHeaders,
            actualIgnoredHeaders);
    assertTrue("some headers that were sent weren't returned " + expectedHeaders, expectedHeaders.isEmpty());
}

From source file:cn.crawin.msg.gateway.http.SignUtil.java

/**
 * ??Http//from www.  j a v  a  2s  .  c  o m
 *
 * @param headers Http
 * @param signHeaderPrefixList ???Header?
 * @return ??Http
 */
private static String buildHeaders(Map<String, String> headers, List<String> signHeaderPrefixList) {
    StringBuilder sb = new StringBuilder();

    if (null != signHeaderPrefixList) {
        signHeaderPrefixList.remove(SystemHeader.X_CA_SIGNATURE);
        signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_ACCEPT);
        signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_CONTENT_MD5);
        signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_CONTENT_TYPE);
        signHeaderPrefixList.remove(HttpHeader.HTTP_HEADER_DATE);
        Collections.sort(signHeaderPrefixList);
        if (null != headers) {
            Map<String, String> sortMap = new TreeMap<String, String>();
            sortMap.putAll(headers);
            StringBuilder signHeadersStringBuilder = new StringBuilder();
            for (Map.Entry<String, String> header : sortMap.entrySet()) {
                if (isHeaderToSign(header.getKey(), signHeaderPrefixList)) {
                    sb.append(header.getKey());
                    sb.append(Constants.SPE2);
                    if (!StringUtils.isBlank(header.getValue())) {
                        sb.append(header.getValue());
                    }
                    sb.append(Constants.LF);
                    if (0 < signHeadersStringBuilder.length()) {
                        signHeadersStringBuilder.append(Constants.SPE1);
                    }
                    signHeadersStringBuilder.append(header.getKey());
                }
            }
            headers.put(SystemHeader.X_CA_SIGNATURE_HEADERS, signHeadersStringBuilder.toString());
        }
    }

    return sb.toString();
}

From source file:data.intelligence.platform.yarn.etl.io.CodecPool.java

private static <T> T borrow(Map<Class<T>, List<T>> pool, Class<? extends T> codecClass) {
    T codec = null;/*  www  . j  ava 2s  . co m*/

    // Check if an appropriate codec is available
    synchronized (pool) {
        if (pool.containsKey(codecClass)) {
            List<T> codecList = pool.get(codecClass);

            if (codecList != null) {
                synchronized (codecList) {
                    if (!codecList.isEmpty()) {
                        codec = codecList.remove(codecList.size() - 1);
                    }
                }
            }
        }
    }

    return codec;
}