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:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Add Other to the list in the first spot if it's not already there.
 * Removes it and put's it in the first spot if it is.
 *//*from  ww w  . j  a va  2 s.  c  o  m*/
private static void addOther(List inList) {

    if (!inList.contains(Constants.Dropdowns.OTHER_OPTION)) {
        inList.add(0, Constants.Dropdowns.OTHER_OPTION);
    } else {
        inList.remove(Constants.Dropdowns.OTHER_OPTION);
        inList.add(0, Constants.Dropdowns.OTHER_OPTION);
    }
}

From source file:com.aliyun.openservices.odps.console.pub.ShowInstanceCommand.java

public static ShowInstanceCommand parse(String commandString, ExecutionContext sessionContext)
        throws ODPSConsoleException {

    String upCommandText = commandString.toUpperCase().trim();
    if (upCommandText.toUpperCase().matches("\\s*SHOW\\s+P\\s*")
            || upCommandText.toUpperCase().matches("\\s*SHOW\\s+PROCESSLIST\\s*")
            || upCommandText.toUpperCase().matches("\\s*SHOW\\s+PROC\\s*")
            || upCommandText.toUpperCase().matches("\\s*SHOW\\s+P\\s+[\\s\\S]*")

            // bug #262924
            || upCommandText.toUpperCase().matches("\\s*SHOW\\s+INSTANCES\\s*")
            || upCommandText.toUpperCase().matches("\\s*SHOW\\s+INSTANCES\\s+[\\s\\S]*")
            || upCommandText.toUpperCase().matches("\\s*(LS|LIST)\\s+INSTANCES\\s*")
            || upCommandText.toUpperCase().matches("\\s*(LS|LIST)\\s+INSTANCES\\s+[\\s\\S]*")) {
        List<String> paraList = new ArrayList<String>(Arrays.asList(upCommandText.trim().split("\\s+")));

        // ??//from  ww w  .  j  a v  a2 s.  c  o  m
        String firstCmd = paraList.remove(0);
        paraList.remove(0);

        int length = paraList.size();
        if (length == 0) {

            // ???50?,
            return new ShowInstanceCommand(commandString, sessionContext, null, getTime(new Date(), 0), null,
                    50);
        }

        // ls instances -p project_name
        // ls instances --limit 100
        String project = null;

        // 50
        Integer number = 50;

        if (firstCmd.equals("LS") || firstCmd.equals("LIST")) {
            AntlrObject antlr = new AntlrObject(commandString);
            List<String> commandList = Arrays.asList(antlr.getTokenStringArray());

            CommandLine cl = getCommandLine(commandList.toArray(new String[length]));
            if (2 < cl.getArgs().length) {
                throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[invalid parameters]");
            }

            project = cl.getOptionValue("p");

            if (cl.hasOption("limit")) {
                try {
                    number = Integer.parseInt(cl.getOptionValue("limit"));
                    if (number < 1) {
                        throw new ODPSConsoleException(
                                ODPSConsoleConstants.BAD_COMMAND + "[number should >=1]");
                    }
                } catch (NumberFormatException e) {
                    // ?
                    throw new ODPSConsoleException(
                            ODPSConsoleConstants.BAD_COMMAND + "[number is not integer]");
                }

            } else if (project == null) {
                throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[invalid paras]");
            }

            return new ShowInstanceCommand(commandString, sessionContext, project, getTime(new Date(), 0), null,
                    number);

        }

        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");

        Date fromDate = null;
        Date toDate = null;
        try {
            // fromto???
            int fromIndex = paraList.indexOf("FROM");
            if (fromIndex >= 0 && fromIndex + 1 < paraList.size()) {

                String fromString = paraList.get(fromIndex + 1);
                fromDate = formatDate.parse(fromString);

                paraList.remove(fromIndex + 1);
                paraList.remove(fromIndex);
            }

            int toIndex = paraList.indexOf("TO");
            if (toIndex >= 0 && toIndex + 1 < paraList.size()) {
                String toString = paraList.get(toIndex + 1);
                toDate = formatDate.parse(toString);

                paraList.remove(toIndex + 1);
                paraList.remove(toIndex);
            }
        } catch (ParseException e1) {
            // ?
            throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[invalid date]");
        }

        // ?linenumber
        if (paraList.size() == 1) {

            try {
                number = Integer.valueOf(paraList.get(0));
            } catch (NumberFormatException e) {
                // ?
                throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[number is not integer]");
            }

            paraList.remove(0);
        }

        if (paraList.size() == 0) {

            // 
            if (fromDate == null && toDate == null) {
                fromDate = new Date();
            }

            return new ShowInstanceCommand(commandString, sessionContext, project, getTime(fromDate, 0),
                    getTime(toDate, 24), number);
        } else {
            // ?
            throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[more parameter]");
        }
    }
    return null;
}

From source file:com.webarch.common.lang.StringSeriesTools.java

/**
 * ?n?//from   ww  w . j av a  2  s .  c o  m
 *
 * @param n    in<
 * @param type 1?23?
 * @return String
 */
public static String getRanDomStr(final int n, final int type) {
    String[] charset;
    String[] charsetAll = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
            "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
            "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9"};
    String[] charsetNum = {"0", "1", "2", "3",
            "4", "5", "6", "7", "8", "9"};
    String[] charsetChar = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
            "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
            "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    switch (type) {
        case 1:
            charset = charsetAll;
            break;
        case 2:
            charset = charsetNum;
            break;
        case 3:
            charset = charsetChar;
            break;
        default:
            charset = charsetAll;
    }
    Random random = new Random();
    String[] nonces = new String[n];
    //
    List<String> choose = new ArrayList<String>(charset.length);
    //??
    Collections.addAll(choose, charset);
    int nl = n;
    while (nl-- > 0) {
        int k = random.nextInt(choose.size());
        nonces[nl] = choose.get(k);
        choose.remove(k);
    }
    //?str
    String nonce = "";
    for (String str : nonces) {
        nonce += str;
    }
    return nonce;
}

From source file:com.hp.octane.integrations.uft.UftTestDispatchUtils.java

public static void removeItemsWithStatusNone(List<? extends SupportsOctaneStatus> list) {
    for (int i = list.size(); i > 0; i--) {
        if (list.get(i - 1).getOctaneStatus().equals(OctaneStatus.NONE)) {
            list.remove(i - 1);
        }/*from   www  .ja v a2s  . c  o  m*/
    }
}

From source file:com.netflix.spinnaker.halyard.deploy.deployment.v1.OrcaRunner.java

private static String formatId(String id) {
    if (id.length() == 0) {
        return id;
    }/*from  w  w w.  j ava  2  s  .  c o m*/

    id = capitalize(id);
    List<Integer> breaks = new ArrayList<>();
    char[] arr = id.toCharArray();
    for (int i = 0; i < arr.length; i++) {
        char c = arr[i];
        if (Character.isUpperCase(c)) {
            breaks.add(i);
        }
    }

    breaks.add(id.length());

    if (breaks.size() == 1) {
        return id;
    }

    List<String> words = new ArrayList<>();

    int last = breaks.remove(0);
    while (breaks.size() > 0) {
        int curr = breaks.remove(0);
        String word = id.substring(last, curr);
        if (last != 0) {
            word = unCapitalize(word);
        }
        words.add(word);
        last = curr;
    }

    return words.stream().reduce("", (a, b) -> a + " " + b).trim();
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Add Not Specified to the list in the first spot if it's not already there.
 * Removes it and put's it in the second spot if it is.
 */// w  ww . j a  v a 2 s  .co m
private static void addNotSpecified(List inList) {

    if (!inList.contains(Constants.Dropdowns.NOT_SPECIFIED_OPTION)) {
        inList.add(0, Constants.Dropdowns.NOT_SPECIFIED_OPTION);
    } else {
        inList.remove(Constants.Dropdowns.NOT_SPECIFIED_OPTION);
        inList.add(0, Constants.Dropdowns.NOT_SPECIFIED_OPTION);
    }
}

From source file:de.uniulm.omi.cloudiator.axe.aggregator.utils.Calc.java

public static Double PERCENTILE(List<Double> values) {
    //TODO this semantics has to be defined better
    Double p = values.get(0);/*from  w  ww . j a va  2  s  .  c o m*/
    values.remove(0);
    DescriptiveStatistics ds = transform(values);

    return ds.getPercentile(p);
}

From source file:grails.plugin.searchable.internal.compass.mapping.SearchableGrailsDomainClassCompassMappingUtils.java

/**
 * Merges the given property mappings, overriding parent mappings with child mappings
 * @param mappedProperties/*from   w w  w.ja va  2s.co m*/
 * @param parentClassPropertyMappings
 */
public static void mergePropertyMappings(List mappedProperties, List parentClassPropertyMappings) {
    if (parentClassPropertyMappings == null) {
        return;
    }
    Assert.notNull(mappedProperties, "mappedProperties cannot be null");
    List temp = new ArrayList(parentClassPropertyMappings);
    temp.addAll(mappedProperties);
    for (Iterator citer = mappedProperties.iterator(); citer.hasNext();) {
        CompassClassPropertyMapping cmapping = (CompassClassPropertyMapping) citer.next();
        for (Iterator piter = parentClassPropertyMappings.iterator(); piter.hasNext();) {
            CompassClassPropertyMapping pmapping = (CompassClassPropertyMapping) piter.next();
            if (cmapping.getPropertyName().equals(pmapping.getPropertyName())) {
                temp.remove(pmapping);
            }
        }
    }
    mappedProperties.clear();
    mappedProperties.addAll(temp);
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

/**
 * Add "" to the list in the first spot if it's not already there. Removes
 * it and put's it in the first spot if it is.
 *//*from   w ww.j  a  v  a  2 s  .  c  o  m*/
private static void addBlankOption(List inList) {

    DropdownOption theDropdownOption = new DropdownOption("", "");

    if (!inList.contains(theDropdownOption)) {
        inList.add(0, theDropdownOption);
    } else {
        inList.remove(theDropdownOption);
        inList.add(0, theDropdownOption);
    }
}

From source file:com.screenslicer.core.util.StringUtil.java

public static void trimLargeItems(int[] stringLengths, List<? extends Object> originals) {
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (int i = 0; i < stringLengths.length; i++) {
        stats.addValue(stringLengths[i]);
    }//w w w  .j ava 2 s. co m
    double stdDev = stats.getStandardDeviation();
    double mean = stats.getMean();
    List<Object> toRemove = new ArrayList<Object>();
    for (int i = 0; i < stringLengths.length; i++) {
        double diff = stringLengths[i] - mean;
        if (diff / stdDev > 4d) {
            toRemove.add(originals.get(i));
        }
    }
    for (Object obj : toRemove) {
        originals.remove(obj);
    }
}