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:net.minecraftforge.fml.relauncher.libraries.LibraryManager.java

public static List<Artifact> flattenLists(File mcDir) {
    List<Artifact> merged = new ArrayList<>();
    for (ModList list : ModList.getBasicLists(mcDir)) {
        for (Artifact art : list.flatten()) {
            Optional<Artifact> old = merged.stream().filter(art::matchesID).findFirst();
            if (!old.isPresent()) {
                merged.add(art);//from ww  w . j a  va  2s . c o m
            } else if (old.get().getVersion().compareTo(art.getVersion()) < 0) {
                merged.add(merged.indexOf(old.get()), art);
                merged.remove(old.get());
            }
        }
    }
    return merged;
}

From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java

public static List<String> generateList(File file) {
    List<String> tempList = new ArrayList<String>();
    if (file != null && (file.getName().endsWith(".txt") || file.getName().endsWith(".TXT"))) {
        try {/*www .ja v  a 2 s. c  o  m*/
            BufferedReader in = new BufferedReader(new FileReader(file));
            String inputLine = null;
            do {
                inputLine = in.readLine();

                if (inputLine != null) {
                    if (isAscii(inputLine)) { // make sure all data is ASCII                                                        
                        tempList.add(inputLine);
                    }
                } else {
                    System.out.println("null line");
                    while (tempList.contains("")) {
                        tempList.remove("");
                    }
                    in.close();
                    break;
                }

            } while (true);
        } catch (EOFException eof) {
            logger.error("Errors when reading empty lines in file:" + eof.getMessage());
        } catch (IOException ex) {
            logger.error("Errors when uploading file:" + ex.getMessage());
        }

    }

    return tempList;

}

From source file:metabup.annotations.general.Annotation.java

public static List<MetaClass> getCommonSupers(List<MetaClass> mcs) {
    if (mcs == null || mcs.isEmpty())
        return null;
    List<MetaClass> supers = new ArrayList<MetaClass>();
    supers.addAll(mcs.get(0).getSupers());

    for (MetaClass mc : mcs)
        for (MetaClass superMc : mc.getSupers())
            if (!supers.contains(superMc))
                supers.remove(superMc);

    if (supers.isEmpty())
        return null;
    else/*from  ww  w. j a va2  s .  c o m*/
        return supers;
}

From source file:com.espertech.esper.event.bean.PropertyHelper.java

/**
 * Remove Java language specific properties from the given list of property descriptors.
 * @param properties is the list of property descriptors
 *///from w  w  w .ja v a  2 s .com
protected static void removeJavaProperties(List<InternalEventPropDescriptor> properties) {
    List<InternalEventPropDescriptor> toRemove = new LinkedList<InternalEventPropDescriptor>();

    // add removed entries to separate list
    for (InternalEventPropDescriptor desc : properties) {
        if ((desc.getPropertyName().equals("class")) || (desc.getPropertyName().equals("getClass"))
                || (desc.getPropertyName().equals("toString")) || (desc.getPropertyName().equals("hashCode"))) {
            toRemove.add(desc);
        }
    }

    // remove
    for (InternalEventPropDescriptor desc : toRemove) {
        properties.remove(desc);
    }
}

From source file:com.netflix.spinnaker.orca.pipelinetemplate.v1schema.render.tags.ModuleTag.java

/**
 * Look at this ungodly code. It's gross. Thanks to poor foresight, we tokenize on
 * whitespace, which can break concatenation, and definitely breaks usage of filters.
 * Sooo, we take the tokenized module definition and best-guess our way through collapsing
 * whitespace to arrive at the real key/value pairs that we later parse for populating
 * the module's internal context.// w w w.ja v  a  2 s .  com
 */
private static List<String> collapseWhitespaceInTokenPairs(List<String> tokens) {
    List<String> combinedTokens = new ArrayList<>();
    combinedTokens.add(tokens.get(0));

    StringBuilder buffer = new StringBuilder();
    // idx 0 is `moduleName`. Skip that guy.
    for (int i = 1; i < tokens.size(); i++) {
        String token = tokens.get(i);
        if (token.contains("=")) {
            if (buffer.length() > 0) {
                combinedTokens.add(buffer.toString());
            }
            buffer = new StringBuilder();
            combinedTokens.add(token);
        } else {
            String lastToken = combinedTokens.get(combinedTokens.size() - 1);
            if (lastToken.contains("=") && !lastToken.endsWith(",")) {
                buffer.append(combinedTokens.remove(combinedTokens.size() - 1));
            }
            buffer.append(token);
        }
    }

    if (buffer.length() > 0) {
        int i = combinedTokens.size() - 1;
        combinedTokens.set(i, combinedTokens.get(i) + buffer.toString());
    }

    return combinedTokens.stream().map(ModuleTag::removeTrailingCommas).collect(Collectors.toList());
}

From source file:main.StratioENEI.java

private static float calculate(float[][] custos, int cidadeInicial, int cidadeFinal, List<String> ordem) {

    // System.out.printf("%d -> %d\n", cidadeInicial, cidadeFinal);
    ordem.clear();/*  w  w  w.  j  a  v a 2s .  c  o m*/
    ordem.add(0, String.valueOf(cidadeInicial));
    ordem.add(1, String.valueOf(cidadeFinal));
    int i;
    for (i = 0; i < custos.length; i++) {
        if (ordem.contains(String.valueOf(i))) {
            continue;
        }
        float minimo = Float.MAX_VALUE;
        int idxMin = 1;
        //   System.out.println(i);
        for (int j = 1; j < ordem.size(); j++) {
            //     System.out.printf(">%d|%d\n>>B4: %s\n",i, j, ordem);
            ordem.add(j, String.valueOf(i));
            //      System.out.printf(">>After: %s\n", ordem);
            float value = calcCost(ordem, custos);
            //  System.out.println("Value: "+value);
            ordem.remove(j);

            if (value < minimo) {
                minimo = value;
                idxMin = j;
            }
        }
        ordem.add(idxMin, String.valueOf(i));
        //    System.out.println(ordem);
    }
    return calcCost(ordem, custos);
}

From source file:de.tudarmstadt.ukp.dkpro.core.performance.PerformanceTestUtil.java

/**
 * Initializes a CAS with random text, tokens, and sentences.
 * /*w w  w. ja v a  2s . c  om*/
 * @param aJCas the CAS
 * @param aTextSize the length of the text to be generated.
 * @param aAnnotationCount the number of annotations to be generated.
 * @param aSeed the random seed to allow for repeatable randomness.
 */
public static void initRandomCas(JCas aJCas, int aTextSize, int aAnnotationCount, long aSeed) {
    List<Type> types = new ArrayList<Type>();
    types.add(getType(aJCas, Token.class));
    types.add(getType(aJCas, Sentence.class));
    //        Iterator<Type> i = aJCas.getTypeSystem().getTypeIterator();
    //        while (i.hasNext()) {
    //            Type t = i.next();
    //            if (t.isArray() || t.isPrimitive()) {
    //                continue;
    //            }
    //            if (aJCas.getDocumentAnnotationFs().getType().getName().equals(t.getName())) {
    //                continue;
    //            }
    //            types.add(t);
    //        }

    // Initialize randomizer
    Random rnd = new Random(aSeed);

    // Shuffle the types
    for (int n = 0; n < 10; n++) {
        Type t = types.remove(rnd.nextInt(types.size()));
        types.add(t);
    }

    // Generate random text
    aJCas.setDocumentText(RandomStringUtils.random(aTextSize));

    // Generate random annotations
    CAS cas = aJCas.getCas();
    for (int n = 0; n < aAnnotationCount; n++) {
        Type t = types.get(n % types.size());
        int length = rnd.nextInt(30);
        int begin = rnd.nextInt(aTextSize);
        int end = begin + length;
        if (end > aTextSize) {
            n--; // Skip and extend loop by one
            continue;
        }
        cas.addFsToIndexes(cas.createAnnotation(t, begin, end));
    }
}

From source file:com.evolveum.midpoint.util.MiscUtil.java

private static <T> void carthesian(List<T> items, List<Collection<T>> dimensions, int dimensionNum,
        Processor<Collection<T>> processor) {
    Collection<T> myDimension = dimensions.get(dimensionNum);
    for (T item : myDimension) {
        items.add(item);//from  ww  w  .  j av  a 2  s . c o  m
        if (dimensionNum < dimensions.size() - 1) {
            carthesian(items, dimensions, dimensionNum + 1, processor);
        } else {
            processor.process(items);
        }
        items.remove(items.size() - 1);
    }
}

From source file:jmri.InstanceManager.java

/**
 * Set an object of type T as the default for that type.
 * <p>/*from   w  w w . j a  v a  2 s  .  c o m*/
 * Also registers (stores) the object if not already present.
 * <p>
 * Now, we do that moving the item to the back of the list; see the
 * {@link #getDefault} method
 *
 * @param <T>  The type of the class
 * @param type The Class object for val
 * @param item The object to make default for type
 * @return The default for type (normally this is the item passed in)
 */
@Nonnull
static public <T> T setDefault(@Nonnull Class<T> type, @Nonnull T item) {
    log.trace("setDefault for type {}", type.getName());
    if (item == null) {
        NullPointerException npe = new NullPointerException();
        log.error("Should not set default of type {} to null value", type.getName());
        throw npe;
    }
    Object oldDefault = containsDefault(type) ? getNullableDefault(type) : null;
    List<T> l = getList(type);
    l.remove(item);
    l.add(item);
    if (oldDefault == null || !oldDefault.equals(item)) {
        getDefault().pcs.firePropertyChange(getDefaultsPropertyName(type), oldDefault, item);
    }
    return getDefault(type);
}

From source file:com.cloudbees.plugins.credentials.CredentialsDescriptor.java

/**
 * Attempts to resolve the credentials context from the {@link StaplerRequest} (includes special
 * handling of the HTTP Referer to enable resolution from AJAX requests).
 *
 * @param request the {@link StaplerRequest}.
 * @param type the type of context./*w w w  . ja va  2  s  . c o  m*/
 * @param <T>  the type of context.
 * @return the context from the request
 * @since 2.1.5
 */
@CheckForNull
public static <T extends ModelObject> T findContextInPath(@NonNull StaplerRequest request,
        @NonNull Class<T> type) {
    List<Ancestor> ancestors = request.getAncestors();
    for (int i = ancestors.size() - 1; i >= 0; i--) {
        Ancestor a = ancestors.get(i);
        Object o = a.getObject();
        // special case of unwrapping our internal wrapper classes.
        if (o instanceof CredentialsSelectHelper.WrappedCredentialsStore) {
            o = ((CredentialsSelectHelper.WrappedCredentialsStore) o).getStore().getContext();
        } else if (o instanceof CredentialsStoreAction.CredentialsWrapper) {
            o = ((CredentialsStoreAction.CredentialsWrapper) o).getStore().getContext();
        } else if (o instanceof CredentialsStoreAction.DomainWrapper) {
            o = ((CredentialsStoreAction.DomainWrapper) o).getStore().getContext();
        } else if (o instanceof Descriptor && i == 1) { // URL is /descriptorByName/...
            // TODO this is a https://issues.jenkins-ci.org/browse/JENKINS-19413 workaround

            // we need to try an infer from the Referer as this is likely a doCheck or a doFill method
            String referer = request.getReferer();
            String rootPath = request.getRootPath();
            if (referer != null && rootPath != null && referer.startsWith(rootPath)) {
                // strip out any query portion of the referer URL.
                String path = URI.create(referer.substring(rootPath.length())).getPath().substring(1);

                // TODO have Stapler expose a method that can walk a path and produce the ancestors and use that

                // what now follows is an example of a really evil hack, consequently this means...
                //
                //                         7..       ,
                //                      MMM.          MMM.
                //                     MMMMM        .MMMMMM
                //                    MMMM.           MMMMM.
                //                  OMMM                 MMZ
                //                  MMM                    MM
                //                .MMMM    $.     .       .MM,
                //                MMMMM    MMM   MM        MMM
                //               .MMMMM. MMMMD  8MMM.     MMMM
                //               MMMMMMM.MMMM    MMMMM.  MMMMMM
                //               MMMMMMMM.M .     MMM.  MMMMMMM
                //               MMMMMMMMM.            MMMMMMMM
                //               MMMMMMMMM . ..     MMMMMMMMMMM
                //               MMMMMMMM  IMMMM  Z.MMMMMMMMMM ,
                //               .MMMMMMM   .M:M   MMMMMMMMMMM M
                //              I MMMMMMM.         MMMMMMMMMO  M
                //           MMMM  MMMMMMM       .MMMMMMMMM.   .
                //         :MMMMMM.MMMMMMM.      MMMMMMMM   .MMMM
                //         MMMMMMMMMMMMMMMM      MMMMMMM   MMMMMMMM
                //        MMMMMMMMM.MMMMMMM      MMMMMMM MMMMMMMMMM.
                //        MMMMMMMMMMMMMMMM?      MMMMMM MMMMMMMMMMM
                //        MMMMMMMMMM  .  .       MMMMMIMMMMMMMMMMMM.
                //        MMMMMMMMMM               .. :MMMMMMMMMMMM.
                //        DMMMMMMMMMM                 MMMMMMMMMMMMM.
                //         MMMMMMMMMM.M.              MMMMMMMMMMMM.
                //           MMMMMM,                    ....
                //
                //                   I AM A SAD PANDA

                List<String> pathSegments = new ArrayList<String>(Arrays.asList(StringUtils.split(path, "/")));
                // strip out any leading junk
                while (!pathSegments.isEmpty() && StringUtils.isBlank(pathSegments.get(0))) {
                    pathSegments.remove(0);
                }
                if (pathSegments.size() >= 2) {
                    String firstSegment = pathSegments.get(0);
                    if ("user".equals(firstSegment)) {
                        User user = User.get(pathSegments.get(1));
                        if (type.isInstance(user) && CredentialsProvider.hasStores(user)) {
                            // we have a winner
                            return type.cast(user);
                        }
                    } else if ("job".equals(firstSegment) || "item".equals(firstSegment)
                            || "view".equals(firstSegment)) {
                        int index = 0;
                        while (index < pathSegments.size()) {
                            String segment = pathSegments.get(index);
                            if ("view".equals(segment)) {
                                // remove the /view/
                                pathSegments.remove(index);
                                if (index < pathSegments.size()) {
                                    // remove the /view/{name}
                                    pathSegments.remove(index);
                                }
                            } else if ("job".equals(segment) || "item".equals(segment)) {
                                // remove the /job/
                                pathSegments.remove(index);
                                // skip the name
                                index++;
                            } else {
                                // we have gone as far as we can parse the item path structure
                                while (index < pathSegments.size()) {
                                    // remove the remainder
                                    pathSegments.remove(index);
                                }
                            }
                        }
                        Jenkins jenkins = Jenkins.getActiveInstance();
                        while (!pathSegments.isEmpty()) {
                            String fullName = StringUtils.join(pathSegments, "/");
                            Item item = jenkins.getItemByFullName(fullName);
                            if (item != null) {
                                if (type.isInstance(item) && CredentialsProvider.hasStores(item)) {
                                    // we have a winner
                                    return type.cast(item);
                                }
                            }
                            // walk back up and try one level less deep
                            pathSegments.remove(pathSegments.size() - 1);
                        }
                    }
                }
                // ok we give up, we are not thirsty for more, we'll let "normal" ancestor in path logic continue
            }
        }
        if (type.isInstance(o) && o instanceof ModelObject && CredentialsProvider.hasStores((ModelObject) o)) {
            return type.cast(o);
        }
    }
    return null;

}