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:io.fabric8.core.jmx.BeanUtils.java

public static List<String> getFields(Class clazz) {
    List<String> answer = new ArrayList<String>();

    try {//from   w  w w .ja v a2 s. c o  m
        for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(clazz)) {
            if (desc.getReadMethod() != null) {
                answer.add(desc.getName());
            }
        }
    } catch (Exception e) {
        throw new FabricException("Failed to get property descriptors for " + clazz.toString(), e);
    }

    // few tweaks to maintain compatibility with existing views for now...
    if (clazz.getSimpleName().equals("Container")) {
        answer.add("parentId");
        answer.add("versionId");
        answer.add("profileIds");
        answer.add("childrenIds");
        answer.remove("fabricService");
    } else if (clazz.getSimpleName().equals("Profile")) {
        answer.add("id");
        answer.add("parentIds");
        answer.add("childIds");
        answer.add("containerCount");
        answer.add("containers");
        answer.add("fileConfigurations");
    } else if (clazz.getSimpleName().equals("Version")) {
        answer.add("id");
        answer.add("defaultVersion");
    }

    return answer;
}

From source file:com.amalto.core.storage.hibernate.TypeMapping.java

protected static <T> void resetList(List<T> oldValues, List<T> newValues) {
    if (newValues == null) {
        if (oldValues != null) {
            oldValues.clear();//from   w  ww.ja  va  2 s .  co  m
        }
        return;
    }
    Iterator<T> iterator = newValues.iterator();
    for (int i = 0; iterator.hasNext(); i++) {
        T nextNew = iterator.next();
        if (nextNew != null) {
            if (i < oldValues.size() && !nextNew.equals(oldValues.get(i))) {
                oldValues.set(i, nextNew);
            } else if (i >= oldValues.size()) {
                oldValues.add(i, nextNew);
            }
        }
    }
    while (oldValues.size() > newValues.size()) {
        oldValues.remove(oldValues.size() - 1);
    }
}

From source file:io.dockstore.client.cli.Client.java

private static List<String> optVals(List<String> args, String key) {
    List<String> vals = new ArrayList<>();

    for (int i = 0; i < args.size(); /** do nothing */
            i = i) {//from  w ww  .  java  2s .c o  m
        String s = args.get(i);
        if (key.equals(s)) {
            args.remove(i);
            if (i < args.size()) {
                String val = args.remove(i);
                if (!val.startsWith("--")) {
                    String[] ss = val.split(",");
                    if (ss.length > 0) {
                        vals.addAll(Arrays.asList(ss));
                        continue;
                    }
                }
            }
            kill("dockstore: missing required argument to '%s'.", key);
        } else {
            i++;
        }
    }

    return vals;
}

From source file:discovery.DiscoveryExample.java

private static void deleteInstance(String[] args, String command, List<ExampleServer> servers) {
    // simulate a random instance going down
    // in a real application, this would occur due to normal operation, a crash, maintenance, etc.

    if (args.length != 1) {
        System.err.println("syntax error (expected delete <name>): " + command);
        return;//from   w  w w .jav  a 2 s  . c  o m
    }

    final String serviceName = args[0];
    ExampleServer server = Iterables.find(servers, new Predicate<ExampleServer>() {
        @Override
        public boolean apply(ExampleServer server) {
            return server.getThisInstance().getName().endsWith(serviceName);
        }
    }, null);
    if (server == null) {
        System.err.println("No servers found named: " + serviceName);
        return;
    }

    servers.remove(server);
    IOUtils.closeQuietly(server);
    System.out.println("Removed a random instance of: " + serviceName);
}

From source file:io.fabric8.jube.local.NodeHelper.java

public static Container addOrUpdateDesiredContainer(Pod pod, String containerName, Container container) {
    List<Container> containers = getOrCreatePodDesiredContainers(pod);
    Container oldContainer = findContainer(containers, containerName);
    if (oldContainer != null) {
        // lets update it just in case something changed...
        containers.remove(oldContainer);
    }//from w ww  .  jav a2 s. c o m
    Container newContainer = new Container();

    // TODO we should use bean utils or something to copy properties in case we miss one!
    newContainer.setCommand(container.getCommand());
    newContainer.setEnv(container.getEnv());
    newContainer.setImage(container.getImage());
    newContainer.setPorts(container.getPorts());
    newContainer.setVolumeMounts(container.getVolumeMounts());
    newContainer.setWorkingDir(container.getWorkingDir());
    newContainer.getAdditionalProperties().putAll(container.getAdditionalProperties());
    newContainer.setName(containerName);
    LOG.info("Added new container: {}", containerName);

    containers.add(newContainer);
    return newContainer;
}

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

/**
 * Removed duplicate properties using the property name to find unique properties.
 * @param properties is a list of property descriptors
 *///from   ww  w . j a  v  a  2 s. c  o m
protected static void removeDuplicateProperties(List<InternalEventPropDescriptor> properties) {
    LinkedHashMap<String, InternalEventPropDescriptor> set = new LinkedHashMap<String, InternalEventPropDescriptor>();
    List<InternalEventPropDescriptor> toRemove = new LinkedList<InternalEventPropDescriptor>();

    // add duplicates to separate list
    for (InternalEventPropDescriptor desc : properties) {
        if (set.containsKey(desc.getPropertyName())) {
            toRemove.add(desc);
            continue;
        }
        set.put(desc.getPropertyName(), desc);
    }

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

From source file:com.t3.model.AssetManager.java

public static void removeAssetListener(MD5Key key, AssetAvailableListener... listeners) {

    if (listeners == null || listeners.length == 0) {
        return;/*from  w w  w.j  a  va 2s .  c o m*/
    }

    List<AssetAvailableListener> listenerList = assetListenerListMap.get(key);
    if (listenerList == null) {
        // Nothing to do
        return;
    }

    for (AssetAvailableListener listener : listeners) {
        listenerList.remove(listener);
    }
}

From source file:com.jetbrains.pluginUtils.xml.JDOMXIncluder.java

private static List<Content> resolveXIncludeElement(Element element, Stack<String> bases)
        throws XIncludeException {
    String base = "";
    if (!bases.isEmpty())
        base = bases.peek();//w ww  . j  av a2 s  .c  o m

    // These lines are probably unnecessary
    assert isIncludeElement(element);

    String href = element.getAttributeValue(HREF);
    assert href != null : "Missing href attribute";

    Attribute baseAttribute = element.getAttribute(BASE, Namespace.XML_NAMESPACE);
    if (baseAttribute != null) {
        base = baseAttribute.getValue();
    }

    URL remote;
    if (base != null) {
        try {
            URL context = new URL(base);
            remote = new URL(context, href);
        } catch (MalformedURLException ex) {
            throw new XIncludeException(ex);
        }
    } else { // base == null
        try {
            remote = new URL(href);
        } catch (MalformedURLException ex) {
            throw new XIncludeException(ex);
        }
    }

    boolean parse = true;
    final String parseAttribute = element.getAttributeValue(PARSE);

    if (parseAttribute != null) {
        if (parseAttribute.equals(TEXT)) {
            parse = false;
        }

        assert parseAttribute.equals(XML) : parseAttribute + "is not a legal value for the parse attribute";
    }

    if (parse) {
        assert !bases.contains(remote.toExternalForm()) : "Circular XInclude Reference to "
                + remote.toExternalForm();

        final Element fallbackElement = element.getChild("fallback", element.getNamespace());
        List<Content> remoteParsed = parseRemote(bases, remote, fallbackElement);
        if (!remoteParsed.isEmpty()) {
            remoteParsed = extractNeededChildren(element, remoteParsed);
        }

        for (int i = 0; i < remoteParsed.size(); i++) {
            Object o = remoteParsed.get(i);

            if (o instanceof Element) {
                Element e = (Element) o;
                List<? extends Content> nodes = resolve(e, bases);
                remoteParsed.addAll(i, nodes);
                i += nodes.size();
                remoteParsed.remove(i);
                i--;
                e.detach();
            }
        }

        for (Object o : remoteParsed) {
            if (o instanceof Content) {
                Content content = (Content) o;
                content.detach();
            }
        }
        return remoteParsed;
    } else {
        try {
            String encoding = element.getAttributeValue(ENCODING);
            String s = IOUtils.toString(remote, encoding);
            List<Content> resultList = new ArrayList<Content>(1);
            resultList.add(new Text(s));
            return resultList;
        } catch (IOException e) {
            throw new XIncludeException(e);
        }
    }

}

From source file:com.soomla.data.RewardStorage.java

public static boolean resetRewardsState(JSONObject state) {
    if (state == null) {
        return false;
    }/*from  ww w . j  av  a 2s  .co  m*/

    List<String> rewardIds = getRewardIds();

    try {
        Iterator keysIter = state.keys();
        while (keysIter.hasNext()) {
            String rewardId = (String) keysIter.next();
            JSONObject itemValuesJSON = state.getJSONObject(rewardId);

            if (itemValuesJSON.has("timesGiven")) {
                int timesGiven = itemValuesJSON.getInt("timesGiven");
                resetTimesGiven(rewardId, timesGiven);
            }

            if (itemValuesJSON.has("lastGiven")) {
                long lastGiven = itemValuesJSON.getLong("lastGiven");
                setLastGivenTimeMillis(rewardId, lastGiven);
            }

            rewardIds.remove(rewardId);
        }
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "Unable to set state for rewards. error: " + e.getLocalizedMessage());
        return false;
    }

    // When resetting state we should remove all rewards' state which
    // were not in the sync state (so the state is inline with the provided
    // state)
    for (String rewardId : rewardIds) {
        KeyValueStorage.deleteKeyValue(keyRewardTimesGiven(rewardId));
        KeyValueStorage.deleteKeyValue(keyRewardLastGiven(rewardId));
        KeyValueStorage.deleteKeyValue(keyRewardIdxSeqGiven(rewardId));
    }

    return true;
}

From source file:de.bund.bfr.knime.pmm.common.math.MathUtilities.java

public static void removeNullValues(List<Double> targetValues, List<List<Double>> argumentValues) {
    for (int i = 0; i < targetValues.size(); i++) {
        boolean remove = false;

        if (targetValues.get(i) == null) {
            remove = true;//w w  w.  j a va 2  s . co  m
            continue;
        }

        if (!remove) {
            for (int j = 0; j < argumentValues.size(); j++) {
                if (argumentValues.get(j).get(i) == null) {
                    remove = true;
                    break;
                }
            }
        }

        if (remove) {
            targetValues.remove(i);

            for (int j = 0; j < argumentValues.size(); j++) {
                argumentValues.get(j).remove(i);
            }

            i--;
        }
    }
}