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:cz.muni.fi.dndtroops.service.TroopServiceImpl.java

@Override
public void removeHeroFromTroop(Troop troop, Hero hero) {
    log.debug("removeHeroToTroop({})", troop, hero);
    if (hero.getTroop() == null) {
        throw new DnDTroopServiceException("hero is not in troop");
    }/*w  w w . j  av  a  2s . c  o  m*/
    if (hero.getTroop() != troop) {
        throw new DnDTroopServiceException("hero is in different troop");
    }
    if (troop.getMembers().contains(hero) == false) {
        throw new DnDTroopServiceException("troop doesn't contain this hero");
    }
    try {
        List<Hero> list = troop.getMembers();
        list.remove(hero);
        troop.setMembers(list);
        hero.setTroop(null);
    } catch (Exception e) {
        throw new DnDTroopServiceException("removeHeroFromTroop problem", e);
    }

}

From source file:com.gisgraphy.webapp.filter.LocaleRequestWrapper.java

/**
 * {@inheritDoc}/*  w  w  w. java2 s  .  com*/
 */
@Override
@SuppressWarnings("unchecked")
public Enumeration<Locale> getLocales() {
    if (null != preferredLocale) {
        List<Locale> l = Collections.list(super.getLocales());
        if (l.contains(preferredLocale)) {
            l.remove(preferredLocale);
        }
        l.add(0, preferredLocale);
        return Collections.enumeration(l);
    } else {
        return super.getLocales();
    }
}

From source file:com.mirth.connect.client.ui.components.rsta.ac.js.PartialHashMap.java

public void removeValue(Object key, Object value) {
    List<V> list = get(key);
    if (list != null) {
        list.remove(value);
        if (list.isEmpty()) {
            remove(key);// w ww  .j a  v a2 s .com
        }
    }
}

From source file:com.twosigma.beaker.table.serializer.TableDisplayDeSerializer.java

public static Pair<String, Object> getDeserializeObject(BeakerObjectConverter parent, JsonNode n,
        ObjectMapper mapper) {//from www .  ja  v a 2 s .  c  o m
    Object o = null;
    String subtype = null;
    try {
        List<List<?>> values = TableDisplayDeSerializer.getValues(parent, n, mapper);
        List<String> columns = TableDisplayDeSerializer.getColumns(n, mapper);
        List<String> classes = TableDisplayDeSerializer.getClasses(n, mapper);

        if (n.has("subtype"))
            subtype = mapper.readValue(n.get("subtype").asText(), String.class);

        if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) {
            o = getValuesAsDictionary(parent, n, mapper);
        } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE) && columns != null
                && values != null) {
            o = getValuesAsRows(parent, n, mapper);
        } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) {
            o = getValuesAsMatrix(parent, n, mapper);
        }
        if (o == null) {
            if (n.has("hasIndex") && mapper.readValue(n.get("hasIndex").asText(), String.class).equals("true")
                    && columns != null && values != null) {
                columns.remove(0);
                classes.remove(0);
                for (List<?> v : values) {
                    v.remove(0);
                }
                o = new TableDisplay(values, columns, classes);
            } else {
                o = new TableDisplay(values, columns, classes);
            }
        }
    } catch (Exception e) {
        logger.error("exception deserializing TableDisplay ", e);
    }
    return new ImmutablePair<String, Object>(subtype, o);
}

From source file:com.google.code.ssm.spring.test.dao.AppUserDAOImpl.java

@Override
@CacheEvict(value = USER_CACHE_NAME, key = "#pk.cacheKey()")
public void remove(final AppUserPK pk) {
    AppUser appUser = MAP.remove(pk);//  w w w.j ava  2  s .  c  o  m
    List<AppUser> list = USER_ID_MAP.get(pk.getUserId());
    if (list != null) {
        list.remove(appUser);
    }
}

From source file:fm.last.citrine.service.TaskManagerImpl.java

@Override
public List<Task> findTasksInSameGroup(Task task) {
    // would be more efficient to add this method to DAO and do an exclude the passed task in select statement
    List<Task> tasks = taskDAO.findByGroup(task.getGroupName());
    tasks.remove(task);
    return tasks;
}

From source file:org.duracloud.account.flow.createaccount.CreateAccountAction.java

@Transactional
public Event doExecute(RequestContext context) throws Exception {

    NewAccountForm newAccountForm = (NewAccountForm) context.getFlowScope().get("newAccountForm");
    FullAccountForm fullAccountForm = (FullAccountForm) context.getFlowScope().get("fullAccountForm");

    StorageProviderType primaryStorageProvider = fullAccountForm.getPrimaryStorageProvider();
    Set<StorageProviderType> secondaryStorageProviders = new HashSet<StorageProviderType>();

    if (fullAccountForm.getStorageProviders() != null) {
        List<StorageProviderType> storageProviders = fullAccountForm.getStorageProviders();
        storageProviders.remove(primaryStorageProvider);
        secondaryStorageProviders.addAll(storageProviders);
    }//  ww w .  ja  va  2 s . c  om

    AccountCreationInfo aci = new AccountCreationInfo(newAccountForm.getSubdomain(),
            newAccountForm.getAcctName(), newAccountForm.getOrgName(), newAccountForm.getDepartment(),
            primaryStorageProvider, secondaryStorageProviders);

    AccountService as = accountManagerService.createAccount(aci);

    String contextPath = context.getExternalContext().getContextPath();
    String accountName = newAccountForm.getAcctName();
    Long accountId = as.getAccountId();

    Message message;

    String pattern = contextPath + AccountsController.BASE_MAPPING + AccountsController.ACCOUNT_SETUP_MAPPING;
    String accountUri = UrlHelper.formatId(accountId, pattern);

    Object[] args = new Object[] { accountName, accountUri };
    message = messageHelper.createMessageSuccess(messageSource, "account.create.full.success", args);

    context.getFlowScope().put(UserFeedbackUtil.FEEDBACK_KEY, message);
    return success();
}

From source file:io.github.tavernaextras.biocatalogue.model.Util.java

/**
 * Joins the set of tokens in the provided list into a single string.
 * /* w  ww .  jav a 2s .  c om*/
 * Any empty strings or <code>null</code> entries in the <code>tokens</code> list 
 * will be removed to achieve a better resulting joined string.
 * 
 * @param tokens List of strings to join.
 * @param prefix String to prepend to each token.
 * @param suffix String to append to each token.
 * @param separator Separator to insert between individual strings.
 * @return String of the form <code>[prefix][token1][suffix][separator][prefix][token2][suffix][separator]...[prefix][tokenN][suffix]</code>
 *         <br/><br/>
 *         Example: call <code>join(["cat","sat","on","the","mat"], "[", "]", ", ")</code> results in the following output:
 *                  <code>"[cat], [sat], [on], [the], [mat]"</code>
 */
public static String join(List<String> tokens, String prefix, String suffix, String separator) {
    if (tokens == null) {
        // nothing to join
        return (null);
    }

    // list of strings is not empty, but some pre-processing is necessary
    // to remove any empty strings that may be there
    for (int i = tokens.size() - 1; i >= 0; i--) {
        if (tokens.get(i) == null || tokens.get(i).length() == 0) {
            tokens.remove(i);
        }
    }

    // now start the actual processing, but it may be the case that all strings
    // were empty and we now have an empty list
    if (tokens.isEmpty()) {
        // nothing to join - just return an empty string
        return ("");
    } else {
        // there are some tokens -- perform the joining
        String effectivePrefix = (prefix == null ? "" : prefix);
        String effectiveSuffix = (suffix == null ? "" : suffix);
        String effectiveSeparator = (separator == null ? "" : separator);

        StringBuilder result = new StringBuilder();
        for (int i = 0; i < tokens.size(); i++) {
            result.append(effectivePrefix + tokens.get(i) + effectiveSuffix);
            result.append(i == tokens.size() - 1 ? "" : effectiveSeparator);
        }

        return (result.toString());
    }
}

From source file:com.netflix.spinnaker.orca.mine.pipeline.CanaryPipelineClusterExtractor.java

@Override
public void updateStageClusters(Map stage, List<Map> replacements) {
    List<Map> clusterPairs = (List<Map>) stage.get("clusterPairs");
    clusterPairs.forEach(pair -> {/*  w w w.  j  a  va  2s  .  c o m*/
        pair.put("baseline", replacements.remove(0));
        pair.put("canary", replacements.remove(0));
    });
}

From source file:com.epam.ta.reportportal.core.externalsystem.handler.impl.DeleteExternalSystemHandler.java

@Override
public synchronized OperationCompletionRS deleteExternalSystem(String projectName, String id, String username) {
    Project project = projectRepository.findByName(projectName);
    expect(project, notNull()).verify(PROJECT_NOT_FOUND, projectName);

    ExternalSystem exist = externalSystemRepository.findOne(id);
    expect(exist, notNull()).verify(EXTERNAL_SYSTEM_NOT_FOUND, exist);

    if (!project.getConfiguration().getExternalSystem().contains(id))
        fail().withError(FORBIDDEN_OPERATION,
                Suppliers.formattedSupplier("BTS with ID='{}' doesn't project '{}' related", id, projectName));

    try {/*from  w w  w. j a  v a  2 s . com*/
        externalSystemRepository.delete(id);
        List<String> externalSystemIds = project.getConfiguration().getExternalSystem();
        externalSystemIds.remove(id);
        project.getConfiguration().setExternalSystem(externalSystemIds);
        projectRepository.save(project);
    } catch (Exception e) {
        throw new ReportPortalException("Error during deleting ExternalSystem", e);
    }
    eventPublisher.publishEvent(new ExternalSystemDeletedEvent(exist, username));
    return new OperationCompletionRS("ExternalSystem with ID = '" + id + "' is successfully deleted.");
}