Example usage for java.util List set

List of usage examples for java.util List set

Introduction

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

Prototype

E set(int index, E element);

Source Link

Document

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

Usage

From source file:Main.java

/**
 * A shell sort//from  ww w.  j a v a 2  s. c o m
 * 
 * @author Jason Harrison
 */
public static <T> void shellSort(List<T> list, Comparator<? super T> c) {
    int h = 1; /* find the largest h value possible */
    while ((h * 3 + 1) < list.size()) {
        h = 3 * h + 1;
    } /* 
       * while h remains larger than 0 
       */
    while (h > 0) { /* 
                     * for each set of elements (there are h sets) 
                     */
        for (int i = h - 1; i < list.size(); i++) { /*
                                                     * pick the last element in the set 
                                                     */
            T A;
            T B = list.get(i);
            int j = i;
            /* 
             * compare the element at B to the one before it in the set 
             * if they are out of order continue this loop, moving
             * elements "back" to make room for B to be inserted. 
             */
            for (j = i; (j >= h) && (c.compare((A = list.get(j - h)), B) > 0); j -= h) {
                list.set(j, A);
            } /* 
               * insert B into the correct place
               */
            list.set(j, B);
        } /*
           * all sets h-sorted, now decrease set size
           */
        h = h / 3;
    }
}

From source file:org.apache.taverna.databundle.DataBundles.java

public static List<Path> getList(Path list) throws IOException {
    if (list == null)
        return null;
    List<Path> paths = new ArrayList<>();
    try (DirectoryStream<Path> ds = newDirectoryStream(list)) {
        for (Path entry : ds)
            try {
                long entryNum = getEntryNumber(entry);
                while (paths.size() <= entryNum)
                    // Fill any gaps
                    paths.add(null);//  ww w . j a v a 2s.c  om
                // NOTE: Don't use add() as these could come in any order!
                paths.set((int) entryNum, entry);
            } catch (NumberFormatException ex) {
            }
    } catch (DirectoryIteratorException ex) {
        throw ex.getCause();
    }
    return paths;
}

From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java

private static void removeNotYetImplemented(final List<String> lines, final int i, final String browserString) {
    final String previous = lines.get(i - 1);
    if (previous.contains("@NotYetImplemented")) {
        if (previous.indexOf('(') != -1) {
            final int p0 = previous.indexOf('(') + 1;
            final int p1 = previous.lastIndexOf(')');
            String browsers = previous.substring(p0, p1);
            if (browsers.indexOf('{') != -1) {
                browsers = browsers.substring(1, browsers.length() - 1).trim();
            }/*from   w  w w  .  j  a  v a2 s  .co m*/
            final Set<String> browserSet = new HashSet<>();
            for (final String browser : browsers.split(",")) {
                browserSet.add(browser.trim());
            }
            browserSet.remove(browserString);
            if (browserSet.size() == 1) {
                lines.set(i - 1, "    @NotYetImplemented(" + browserSet.iterator().next() + ")");
            } else if (browserSet.size() > 1) {
                lines.set(i - 1, "    @NotYetImplemented({ " + StringUtils.join(browserSet, ", ") + " })");
            } else {
                lines.remove(i - 1);
            }
        } else {
            final List<String> allBrowsers = new ArrayList<>(
                    Arrays.asList("CHROME", "IE11", "FF31", "FF38", "EDGE"));
            for (final Iterator<String> it = allBrowsers.iterator(); it.hasNext();) {
                if (it.next().equals(browserString)) {
                    it.remove();
                }
            }
            lines.set(i - 1, "    @NotYetImplemented({ " + StringUtils.join(allBrowsers, ", ") + " })");
        }
    }
}

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./*from ww w.j a va  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:eu.trentorise.opendata.josman.Josmans.java

/**
 * Adds the candidate tag to the provided tags if no other tag has same
 * major and minor or if its patch is greater.
 *//*from w  w w.ja  v a2s .co m*/
@Nullable
private static void updateTags(String repoName, RepositoryTag candidateTag, List<RepositoryTag> tags) {

    SemVersion candidateSemVarsion = version(repoName, candidateTag.getName());

    for (int i = 0; i < tags.size(); i++) {
        RepositoryTag tag = tags.get(i);
        SemVersion semVersion = version(repoName, tag.getName());
        if (candidateSemVarsion.getMajor() == semVersion.getMajor()
                && candidateSemVarsion.getMinor() == semVersion.getMinor()) {
            if (candidateSemVarsion.getPatch() > semVersion.getPatch()) {
                tags.set(i, candidateTag);
            }
            return;
        }
    }
    tags.add(candidateTag);
}

From source file:de.terministic.serein.core.genome.recombination.SingleArithmeticRecombination.java

@Override
public DoubleGenome recombine(DoubleGenome g1, DoubleGenome g2, Random random) {
    int index = random.nextInt(g1.size());
    List<Double> genes = new ArrayList<>(g1.getGenes());
    double value = dominance * g1.getGenes().get(index) + (1 - dominance) * g2.getGenes().get(index);
    genes.set(index, value);
    // TODO Auto-generated method stub
    return g1.createInstance(genes);
}

From source file:info.novatec.testit.livingdoc.repository.FileSystemRepository.java

@Override
public List<Object> listDocumentsInHierarchy() {
    List<Object> hierarchy = toHierarchyNodeVector(root);
    hierarchy.set(0, root.getName());
    hierarchy.set(1, false);/*from  w w  w  . ja  v  a2s.  c  om*/
    hierarchy.set(2, false);
    return hierarchy;
}

From source file:org.meruvian.yama.webapi.interceptor.CurrentUserFilter.java

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    UriInfo uriInfo = requestContext.getUriInfo();
    MultivaluedMap<String, String> parameters = uriInfo.getPathParameters();
    List<String> usernames = parameters.get("username");

    if (usernames == null)
        return;//from  ww w .  j a  va 2 s.  c o  m

    if (usernames.contains("me")) {
        usernames.set(usernames.indexOf("me"), SessionCredentials.getCurrentUsername());
    }
}

From source file:ListOfLists.java

/**
 * Replaces the element at the specified position in underlying list with the
 * specified element.//from   w  w w.  j a  v  a 2 s .  c om
 *
 * @param index index of element to replace.
 * @param element element to be stored at the specified position.
 * @return the element previously at the specified position.
 */
public Object set(int index, Object element) {
    int size = size();
    if (index < 0)
        throw new IndexOutOfBoundsException("index: " + index + "; size: " + size);

    Iterator it = lists.iterator();
    while (it.hasNext()) {
        List list = (List) it.next();
        if (index < list.size()) {
            return list.set(index, element);
        } else
            index -= list.size();
    }

    // if value has not been returned yet - IndexOutOfBoundsException is thrown
    throw new IndexOutOfBoundsException("index: " + index + "; size: " + size);
}

From source file:com.ibm.watson.catalyst.jumpqa.template.PatternTemplate.java

/**
 * TODO: Method description/*from  w w w.j  a  v  a2  s .  c o m*/
 * 
 * @param aCandidate the candidate to create entries for
 * @return the ground truth entries
 */
@Override
public List<IGroundTruthEntry> candidate2entries(Candidate aCandidate) {
    final List<IGroundTruthEntry> result = new ArrayList<IGroundTruthEntry>();
    final String cleanedString = StringCleaner.clean(aCandidate.getMatchText(), _clean);
    final List<String> splits = _patterns.splitCandidateText(cleanedString);
    splits.set(1, _replacer.replace(splits.get(1)));

    String questionText = _questioner.makeQuestion(splits);
    QuestionAnswerPair qaPair = new QuestionAnswerPair(questionText, aCandidate.getAnswer());
    gteb.setQaPair(qaPair);
    result.add(gteb.build());
    return result;
}