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:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java

public static String convertTOJSON(MultiLevelRequirements levelRequirements) {
    if (levelRequirements == null) {
        return "{nothing}";
    }//from w w w  .  j a va 2s  .  co  m
    JSONObject root = new JSONObject();
    //diff is that in some cases (e.g. condition), name is displayName
    root.put("name", levelRequirements.getName());
    root.put("realName", levelRequirements.getName());
    root.put("type", "" + levelRequirements.getLevel());

    //traverse recursive XML tree
    List<JSONObject> jsonObjects = new ArrayList<>();
    List<MultiLevelRequirements> reqsList = new ArrayList<>();

    reqsList.add(levelRequirements);
    jsonObjects.add(root);

    while (!reqsList.isEmpty()) {
        JSONObject obj = jsonObjects.remove(0);
        MultiLevelRequirements reqs = reqsList.remove(0);

        JSONArray children = new JSONArray();
        for (MultiLevelRequirements childReqs : reqs.getContainedElements()) {
            JSONObject child = new JSONObject();
            child.put("name", childReqs.getName());
            child.put("realName", childReqs.getName());
            child.put("type", "" + childReqs.getLevel());
            children.add(child);

            reqsList.add(childReqs);
            jsonObjects.add(child);
        }

        //add strategies
        for (Strategy strategy : reqs.getOptimizationStrategies()) {
            JSONObject strategyJSON = new JSONObject();
            strategyJSON.put("name", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("realName", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("type", "Strategy");
            children.add(strategyJSON);
        }

        //            JSONArray unitReqs = new JSONArray();
        for (Requirements requirements : reqs.getUnitRequirements()) {
            JSONObject child = new JSONObject();
            child.put("name", requirements.getName());
            child.put("realName", requirements.getName());
            child.put("type", "RequirementsBlock");
            children.add(child);

            JSONArray requirementsJSON = new JSONArray();

            for (Requirement requirement : requirements.getRequirements()) {
                JSONObject requirementJSON = new JSONObject();
                requirementJSON.put("name", requirement.getName());
                requirementJSON.put("realName", requirement.getName());
                requirementJSON.put("type", "Requirement");
                //put individual conditions
                JSONArray conditions = new JSONArray();

                for (Condition condition : requirement.getConditions()) {
                    JSONObject conditionJSON = new JSONObject();
                    conditionJSON.put("name", "MUST BE " + condition.toString());
                    conditionJSON.put("type", "Condition");
                    conditionJSON.put("realName", "" + condition.getType());
                    conditions.add(conditionJSON);
                }

                requirementJSON.put("children", conditions);
                requirementsJSON.add(requirementJSON);
            }

            child.put("children", requirementsJSON);

        }

        obj.put("children", children);

    }

    return root.toJSONString();
}

From source file:com.cdd.bao.template.SchemaUtil.java

public static void gatherAssayStats(Schema schema, List<String> stats) {
    List<Integer> idxAssay = new ArrayList<>();
    for (int n = 0; n < schema.numAssays(); n++)
        if (schema.getAssay(n).annotations.size() > 0)
            idxAssay.add(n);/*from  w ww.j ava 2 s  .  c o m*/
    final int nassay = idxAssay.size();
    stats.add("Assays with partial or complete annotations: " + nassay);

    List<Schema.Group> stack = new ArrayList<>();
    stack.add(schema.getRoot());
    List<Schema.Assignment> assignments = new ArrayList<>();
    while (stack.size() > 0) {
        Schema.Group grp = stack.remove(0);
        assignments.addAll(grp.assignments);
        for (int n = 0; n < grp.subGroups.size(); n++)
            stack.add(n, grp.subGroups.get(n));
    }

    List<Set<String>> assnValues = new ArrayList<>(), assnHits = new ArrayList<>();
    for (Schema.Assignment assn : assignments) {
        Set<String> values = new HashSet<>();
        for (Schema.Value val : assn.values)
            if (val.uri.length() > 0)
                values.add(val.uri);
        assnValues.add(values);
        assnHits.add(new HashSet<>());
    }

    final int nassn = assignments.size();
    if (nassn == 0)
        return;
    int[] assnCount = new int[nassn];

    for (int n : idxAssay) {
        Schema.Assay assay = schema.getAssay(n);
        boolean[] assnHit = new boolean[nassn];
        for (Schema.Annotation annot : assay.annotations) {
            for (int i = 0; i < nassn; i++)
                if (schema.matchAnnotation(annot, assignments.get(i))) {
                    assnHit[i] = true;
                    if (annot.value != null && assnValues.get(i).contains(annot.value.uri))
                        assnHits.get(i).add(annot.value.uri);
                }
        }
        for (int i = 0; i < nassn; i++)
            if (assnHit[i])
                assnCount[i]++;
    }

    for (int n = 0; n < nassn; n++) {
        Schema.Assignment assn = assignments.get(n);
        String assnName = assn.name;
        for (Schema.Group p = assn.parent; p.parent != null; p = p.parent)
            assnName = p.name + " / " + assnName;

        stats.add("[" + assnName + "]");
        stats.add(String.format("        assigned: count=%d/%d (%.1f%%)", assnCount[n], nassay,
                assnCount[n] * 100.0f / nassay));

        int nhits = assnHits.get(n).size(), nvals = assnValues.get(n).size();

        stats.add(String.format("        values used: count=%d/%d (%.1f%%)", nhits, nvals,
                nhits * 100.0f / nvals));
    }
}

From source file:com.sangupta.passcode.HashStream.java

private static List<Integer> splice(List<Integer> list, int index, int howMany) {
    List<Integer> newList = new ArrayList<Integer>();
    final int end = Math.min(index + howMany, list.size());
    if (index > end) {
        return newList;
    }//w ww.j  ava 2  s  .co  m

    for (int i = index; i < end; i++) {
        newList.add(list.remove(index));
    }

    return newList;
}

From source file:net.maritimecloud.identityregistry.model.database.IdentityProviderAttribute.java

public static boolean listsEquals(List<IdentityProviderAttribute> first,
        List<IdentityProviderAttribute> second) {
    if (first == null && second != null || first != null && second == null) {
        return false;
    }//from w  ww  .j  av  a 2s. c o m
    if (first == null && second == null) {
        return true;
    }
    if (first.size() != second.size()) {
        return false;
    }
    List<IdentityProviderAttribute> secondCopy = new ArrayList<>(second);
    for (IdentityProviderAttribute attrInFirst : first) {
        boolean foundMatch = false;
        if (attrInFirst == null) {
            int nullIdx = secondCopy.indexOf(null);
            secondCopy.remove(nullIdx);
            continue;
        }
        for (IdentityProviderAttribute attrInSecond : secondCopy) {
            if (attrInFirst.compareNameAndValueTo(attrInSecond) == 0) {
                foundMatch = true;
                secondCopy.remove(attrInSecond);
                break;
            }
        }
        if (!foundMatch) {
            return false;
        }
    }
    if (secondCopy.size() == 0) {
        return true;
    }
    return false;
}

From source file:edu.cornell.mannlib.semservices.util.SKOSUtils.java

public static List<String> removeConceptURIFromList(List<String> uris, String conceptURI) {
    // remove will return a boolean if the value exists in the list and is
    // removed//from   w w  w  .j a v  a  2 s. c om
    // if/when it returns false, the URI is not in the list
    while (uris.remove(conceptURI)) {
    }
    ;
    return uris;
}

From source file:org.hawkular.alerts.actions.webhook.WebHooks.java

public static synchronized void removeWebHook(String tenantId, String url) throws IOException {
    if (!instance.webhooks.containsKey(tenantId)) {
        return;//from w  ww . ja va 2  s .c  o m
    }
    List<Map<String, String>> tenantWebHooks = instance.webhooks.get(tenantId);
    for (int i = 0; i < tenantWebHooks.size(); i++) {
        Map<String, String> item = tenantWebHooks.get(i);
        if (item.containsKey("url") && item.get("url").equals(url)) {
            tenantWebHooks.remove(i);
            break;
        }
    }
    if (instance.supportsFile) {
        File f = new File(instance.webhooksFile);
        instance.mapper.writeValue(f, instance.webhooks);
    }
}

From source file:com.buaa.cfs.security.ShellBasedUnixGroupsMapping.java

/**
 * Get the current user's group list from Unix by running the command 'groups' NOTE. For non-existing user it will
 * return EMPTY list/*from   w  w  w  . j a v  a2s  .  c  o  m*/
 *
 * @param user user name
 *
 * @return the groups list that the <code>user</code> belongs to. The primary group is returned first.
 *
 * @throws IOException if encounter any error when running the command
 */
private static List<String> getUnixGroups(final String user) throws IOException {
    String result = "";
    try {
        result = Shell.execCommand(Shell.getGroupsForUserCommand(user));
    } catch (Shell.ExitCodeException e) {
        // if we didn't get the group - just return empty list;
        LOG.warn("got exception trying to get groups for user " + user + ": " + e.getMessage());
        return new LinkedList<String>();
    }

    StringTokenizer tokenizer = new StringTokenizer(result, Shell.TOKEN_SEPARATOR_REGEX);
    List<String> groups = new LinkedList<String>();
    while (tokenizer.hasMoreTokens()) {
        groups.add(tokenizer.nextToken());
    }

    // remove duplicated primary group
    if (!Shell.WINDOWS) {
        for (int i = 1; i < groups.size(); i++) {
            if (groups.get(i).equals(groups.get(0))) {
                groups.remove(i);
                break;
            }
        }
    }

    return groups;
}

From source file:Main.java

/**
 * Gets a list of integers(size specified by the given size) between the
 * specified start(inclusion) and end(inclusion) randomly.
 *
 * @param start the specified start/*from www  . j  a v  a 2  s  .c  om*/
 * @param end the specified end
 * @param size the given size
 * @return a list of integers
 */
public static List<Integer> getRandomIntegers(final int start, final int end, final int size) {
    if (size > (end - start + 1)) {
        throw new IllegalArgumentException("The specified size more then (end - start + 1)!");
    }

    final List<Integer> integers = genIntegers(start, end);
    final List<Integer> ret = new ArrayList<Integer>();

    int remainsSize;
    int index;

    while (ret.size() < size) {
        remainsSize = integers.size();
        index = (int) (Math.random() * (remainsSize - 1));
        final Integer i = integers.get(index);

        ret.add(i);
        integers.remove(i);
    }

    return ret;
}

From source file:net.sf.eclipsecs.core.config.ConfigurationWriter.java

/**
 * Writes a module to the transformer handler.
 *
 * @param module//from w w w .ja  va2s .  c  o m
 *            the module to write
 * @param parent
 *            the parent element
 * @param parentSeverity
 *            the severity of the parent module
 * @param remainingModules
 *            the list of remaining (possibly child) modules
 */
private static void writeModule(Module module, Branch parent, Severity parentSeverity,
        List<Module> remainingModules) {

    Severity severity = parentSeverity;

    // remove this module from the list of modules to write
    remainingModules.remove(module);

    List<Module> childs = getChildModules(module, remainingModules);

    // Start the module
    Element moduleEl = parent.addElement(XMLTags.MODULE_TAG);
    moduleEl.addAttribute(XMLTags.NAME_TAG, module.getMetaData().getInternalName());

    // Write comment
    if (StringUtils.trimToNull(module.getComment()) != null) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, XMLTags.COMMENT_ID);
        metaEl.addAttribute(XMLTags.VALUE_TAG, module.getComment());
    }

    // Write severity only if it differs from the parents severity
    if (module.getSeverity() != null && !Severity.inherit.equals(module.getSeverity())) {

        Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
        propertyEl.addAttribute(XMLTags.NAME_TAG, XMLTags.SEVERITY_TAG);
        propertyEl.addAttribute(XMLTags.VALUE_TAG, module.getSeverity().name());

        // set the parent severity for child modules
        severity = module.getSeverity();
    }

    // write module id
    if (StringUtils.trimToNull(module.getId()) != null) {

        Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
        propertyEl.addAttribute(XMLTags.NAME_TAG, XMLTags.ID_TAG);
        propertyEl.addAttribute(XMLTags.VALUE_TAG, module.getId());
    }

    // write properties of the module
    for (ConfigProperty property : module.getProperties()) {

        // write property only if it differs from the default value
        String value = StringUtils.trimToNull(property.getValue());
        if (value != null && !ObjectUtils.equals(value, property.getMetaData().getDefaultValue())) {

            Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
            propertyEl.addAttribute(XMLTags.NAME_TAG, property.getMetaData().getName());
            propertyEl.addAttribute(XMLTags.VALUE_TAG, property.getValue());
        }
    }

    // write custom messages
    for (Map.Entry<String, String> entry : module.getCustomMessages().entrySet()) {

        Element metaEl = moduleEl.addElement(XMLTags.MESSAGE_TAG);
        metaEl.addAttribute(XMLTags.KEY_TAG, entry.getKey());
        metaEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
    }

    // write custom metadata
    for (Map.Entry<String, String> entry : module.getCustomMetaData().entrySet()) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
        metaEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
    }

    // Write last enabled severity level
    if (module.getLastEnabledSeverity() != null) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, XMLTags.LAST_ENABLED_SEVERITY_ID);
        metaEl.addAttribute(XMLTags.VALUE_TAG, module.getLastEnabledSeverity().name());
    }

    // write child modules recursivly
    for (Module child : childs) {
        writeModule(child, moduleEl, severity, remainingModules);
    }
}

From source file:com.aurel.track.admin.customize.lists.importList.ImportListBL.java

/**
 * Remove the lists that won't be deleted
 * @param removableElements// www .  ja  v  a 2s.  co m
 * @param listBean
 */
private static void removeListElement(List<TListBean> removableElements, TListBean listBean) {
    for (int i = 0; i < removableElements.size(); i++)
        if (removableElements.get(i).getObjectID().equals(listBean.getObjectID()))
            removableElements.remove(i);
}