Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:org.cloudifysource.azure.AbstractCliAzureDeploymentTest.java

public void after(String azureHostedService, int timeoutInMinutes, int pollingIntervalInMinutes)
        throws IOException, InterruptedException {
    if (cliExecutablePath != null) {
        log("Destroying deployment");

        List<List<String>> commands = new ArrayList<List<String>>();
        List<String> azureTeardownApplication = Arrays.asList("azure:teardown-app", "--verbose", "-azure-svc",
                azureHostedService, "-timeout", String.valueOf(timeoutInMinutes), "-progress",
                String.valueOf(pollingIntervalInMinutes));

        commands.add(azureTeardownApplication);

        runCliCommands(cliExecutablePath, commands, isDebugMode);
        commands.clear();
    }/*from   w ww . jav a2 s . c om*/
}

From source file:com.jdom.word.playdough.model.gamepack.GamePackFileGenerator.java

public List<Properties> generateGamePacks(int numberOfPlayableWordsInEachPack) {
    List<Properties> finishedPacks = new ArrayList<Properties>();

    Properties allProperties = generateProperties();

    List<String> allPlayableWords = PropertiesUtil.getPropertyAsList(allProperties,
            GamePack.PLAYABLE_WORDS_KEY);

    Iterator<String> iter = allPlayableWords.iterator();
    Properties currentPack = new Properties();
    List<String> currentPackPlayableWords = new ArrayList<String>();
    for (int i = 0; iter.hasNext(); i++) {
        String playableWord = iter.next();
        System.out.println("Finding a pack for word #" + i + " [" + playableWord + "]");
        String playableWordPrefix = playableWord + ".";

        if (i % numberOfPlayableWordsInEachPack == 0 && i > 0) {
            currentPack.setProperty(GamePack.PLAYABLE_WORDS_KEY,
                    StringUtils.join(currentPackPlayableWords, PropertiesUtil.SEPARATOR));
            finishedPacks.add(currentPack);
            currentPackPlayableWords.clear();
            currentPack = new Properties();
        }//from   w  w w .  jav  a  2s . co m

        currentPackPlayableWords.add(playableWord);
        Iterator<Entry<Object, Object>> propertiesIter = allProperties.entrySet().iterator();

        while (propertiesIter.hasNext()) {
            Entry<Object, Object> entry = propertiesIter.next();
            String key = (String) entry.getKey();
            if (key.startsWith(playableWordPrefix)) {
                currentPack.setProperty(key, (String) entry.getValue());
                propertiesIter.remove();
            }
        }
    }

    if (!currentPack.isEmpty()) {
        currentPack.setProperty(GamePack.PLAYABLE_WORDS_KEY,
                StringUtils.join(currentPackPlayableWords, PropertiesUtil.SEPARATOR));
        finishedPacks.add(currentPack);
    }

    return finishedPacks;
}

From source file:org.opendatakit.aggregate.externalservice.AbstractExternalService.java

@Override
public void delete(CallingContext cc) throws ODKDatastoreException {
    CommonFieldsBase serviceEntity = retrieveObjectEntity();
    List<? extends CommonFieldsBase> repeats = retrieveRepeatElementEntities();

    Datastore ds = cc.getDatastore();//from  w ww . j  a  va  2s.c  o  m
    User user = cc.getCurrentUser();

    if (repeats != null) {
        List<EntityKey> keys = new ArrayList<EntityKey>();
        for (CommonFieldsBase repeat : repeats) {
            keys.add(repeat.getEntityKey());
        }
        DeleteHelper.deleteEntities(keys, cc);
        repeats.clear();
    }

    ds.deleteEntity(serviceEntity.getEntityKey(), user);
    ds.deleteEntity(fsc.getEntityKey(), user);
}

From source file:com.jaeksoft.searchlib.crawler.mailbox.MailboxCrawlThread.java

private final boolean index(List<IndexDocument> indexDocumentList, int limit)
        throws IOException, SearchLibException {
    int i = indexDocumentList.size();
    if (i == 0 || i < limit)
        return false;
    setStatusInfo(CrawlStatus.INDEXATION);
    client.updateDocuments(indexDocumentList);
    rwl.w.lock();//from  ww  w  . j  a  va2s .c  om
    try {
        pendingIndexDocumentCount -= i;
        updatedIndexDocumentCount += i;
    } finally {
        rwl.w.unlock();
    }
    indexDocumentList.clear();
    setStatusInfo(CrawlStatus.CRAWL);
    return true;
}

From source file:fr.paris.lutece.plugins.genericalert.web.NotifyReminderTaskComponent.java

/**
  * {@inheritDoc}//  w  w w .  j a  v a 2s .c o m
  */
@Override
public String doSaveConfig(HttpServletRequest request, Locale locale, ITask task) {
    String strIdForm = request.getParameter(PARAMETER_ID_FORM);
    String strNbAlerts = request.getParameter(PARAMETER_NB_ALERT);
    String strApplyNbAlerts = request.getParameter(PARAMETER_APPLY_NB_ALERTS);
    String strForm = request.getParameter(PARAMETER_APPLY_ID_FORM);

    List<ReminderAppointment> listAppointment = new ArrayList<ReminderAppointment>();

    Boolean bCreate = false;

    int nIdForm = Integer.parseInt(strIdForm);
    UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_MODIFY_TASK);
    url.addParameter(PARAMETER_ID_TASK, task.getId());
    url.addParameter(PARAMETER_ID_FORM, nIdForm);
    int nbAlerts = 0;

    if (strNbAlerts != null) {
        if (StringUtils.isNotEmpty(strNbAlerts) && StringUtils.isNumeric(strNbAlerts)) {
            nbAlerts = Integer.parseInt(strNbAlerts);
        } else {
            return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_NB_ALERT_NO_VALID,
                    AdminMessage.TYPE_STOP);
        }
    }

    TaskNotifyReminderConfig config = TaskNotifyReminderConfigHome.findByIdForm(task.getId(), nIdForm);

    if (config == null) {
        config = new TaskNotifyReminderConfig();
        config.setIdTask(task.getId());
        config.setIdForm(nIdForm);
        config.setListReminderAppointment(new ArrayList<ReminderAppointment>());
        bCreate = true;
    } else {

        List<ReminderAppointment> listReminder = config.getListReminderAppointment();

        if (nbAlerts == 0 && strForm == null) {
            TaskNotifyReminderConfigHome.removeAppointmentReminder(config.getIdTask(), nIdForm, nbAlerts, true);
            listReminder.clear();
            config.setListReminderAppointment(listReminder);
        }

        if (nbAlerts < listReminder.size() && nbAlerts != 0 && strForm == null) {
            for (int i = nbAlerts + 1; i <= listReminder.size(); i++) {

                TaskNotifyReminderConfigHome.removeAppointmentReminder(config.getIdTask(), nIdForm, i, false);
                listReminder.remove(i - 1);
            }
            config.setListReminderAppointment(listReminder);
        }
        if (nbAlerts != 0 && strApplyNbAlerts == null && strForm == null) {
            for (int i = 1; i <= nbAlerts; i++) {
                ReminderAppointment reminderAppointment = new ReminderAppointment();
                String strTimeToAlert = request.getParameter(MARK_TIME_ALERT + i);
                String strEmailNotify = request.getParameter(MARK_EMAIL_NOTIFY + i) == null ? MARK_FALSE
                        : request.getParameter(MARK_EMAIL_NOTIFY + i);
                String strSmsNotify = request.getParameter(MARK_SMS_NOTIFY + i) == null ? MARK_FALSE
                        : request.getParameter(MARK_SMS_NOTIFY + i);
                String strEmailAlertMessage = request.getParameter(MARK_EMAIL_ALERT_MESSAGE + i) == null
                        ? StringUtils.EMPTY
                        : request.getParameter(MARK_EMAIL_ALERT_MESSAGE + i);
                String strSmsAlertMessage = request.getParameter(MARK_SMS_ALERT_MESSAGE + i) == null
                        ? StringUtils.EMPTY
                        : request.getParameter(MARK_SMS_ALERT_MESSAGE + i);
                String strAlertSubject = request.getParameter(MARK_ALERT_SUBJECT + i) == null
                        ? StringUtils.EMPTY
                        : request.getParameter(MARK_ALERT_SUBJECT + i);
                String strPhoneNumber = request.getParameter(MARK_NUMBER_PHONE + i) == null ? StringUtils.EMPTY
                        : request.getParameter(MARK_NUMBER_PHONE + i);
                String strEmailCc = request.getParameter(MARK_EMAIL_CC + i) == null ? StringUtils.EMPTY
                        : request.getParameter(MARK_EMAIL_CC + i);
                String strIdSateAfter = request.getParameter(MARK_STATUS_WORKFLOW + i) == null
                        ? StringUtils.EMPTY
                        : request.getParameter(MARK_STATUS_WORKFLOW + i);

                if (StringUtils.isEmpty(strTimeToAlert) || !StringUtils.isNumeric(strTimeToAlert)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_ALERT_TIME_NO_VALID,
                                AdminMessage.TYPE_STOP);
                    }
                }
                if (strSmsNotify.equals(MARK_FALSE) && strEmailNotify.equals(MARK_FALSE)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_NOTIFY_TYPE_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }
                if (!strSmsNotify.equals(MARK_FALSE) && StringUtils.isEmpty(strPhoneNumber)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_NUMBER_PHONE_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }
                if (StringUtils.isEmpty(strIdSateAfter)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_STATUS_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }

                if (StringUtils.isEmpty(strAlertSubject)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_SUBJECT_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }

                if (StringUtils.isEmpty(strEmailAlertMessage) && Boolean.parseBoolean(strEmailNotify)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_EMAIL_TEXT_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }
                if (StringUtils.isEmpty(strSmsAlertMessage) && Boolean.parseBoolean(strSmsNotify)) {
                    if (strApplyNbAlerts == null && strForm == null) {
                        return AdminMessageService.getMessageUrl(request, MESSAGE_ERROR_SMS_TEXT_EMPTY,
                                AdminMessage.TYPE_STOP);
                    }
                }

                else {
                    reminderAppointment.setIdTask(config.getIdTask());
                    reminderAppointment.setIdForm(nIdForm);
                    reminderAppointment.setRank(i);
                    reminderAppointment.setTimeToAlert(Integer.parseInt(strTimeToAlert));
                    reminderAppointment.setEmailNotify(Boolean.parseBoolean(strEmailNotify));
                    reminderAppointment.setSmsNotify(Boolean.parseBoolean(strSmsNotify));
                    reminderAppointment.setEmailAlertMessage(strEmailAlertMessage);
                    reminderAppointment.setSmsAlertMessage(strSmsAlertMessage);
                    reminderAppointment.setAlertSubject(strAlertSubject);
                    reminderAppointment.setNumberPhone(strPhoneNumber);
                    reminderAppointment.setEmailCc(strEmailCc);
                    reminderAppointment.setIdStateAfter(Integer.parseInt(strIdSateAfter));
                    listAppointment.add(reminderAppointment);
                }
            }
        }

        config.setIdForm(nIdForm);
    }

    if (strForm == null) {
        if (listAppointment.size() > 0) {
            config.setListReminderAppointment(listAppointment);
        }
        config.setNbAlerts(nbAlerts);

        if (bCreate) {
            _taskNotifyReminderConfigService.create(config);
        } else {
            _taskNotifyReminderConfigService.update(config);
        }
    }

    if (strApplyNbAlerts != null || strForm != null) {
        return AppPathService.getBaseUrl(request) + JSP_MODIFY_TASK + "?" + PARAMETER_ID_TASK + "="
                + task.getId() + "&" + PARAMETER_ID_FORM + "=" + nIdForm;
    }
    return null;
}

From source file:org.openvpms.tools.archetype.loader.DerivedNodeUpdater.java

/**
 * Saves a batch of objects./*from   ww w.j  a v  a2  s .  c om*/
 *
 * @param batch the batch to save
 * @return the no. of saved objects
 * @throws ArchetypeServiceException if an archetype service error occurs
 *                                   and <tt>failOnError</tt> is
 *                                   <tt>true</tt>
 */
private int saveBatch(List<IMObject> batch) {
    int saved = 0;
    try {
        service.save(batch);
        saved = batch.size();
    } catch (OpenVPMSException exception) {
        if (failOnError) {
            throw exception;
        }
        for (IMObject object : batch) {
            try {
                service.save(object);
                ++saved;
            } catch (OpenVPMSException error) {
                log.error("Failed to save object: " + object, error);
            }
        }
    }
    batch.clear();
    return saved;
}

From source file:com.github.sardine.FunctionalSardineTest.java

@Test
@Ignore//from   w  ww  .  j a  va 2 s . co  m
public void testSetAcl() throws IOException {
    final String url = String.format("http://demo.sabredav.org/public/folder-%s/",
            UUID.randomUUID().toString());
    Sardine sardine = SardineFactory.begin("testuser", "test");
    sardine.createDirectory(url);
    List<DavAce> aces = new ArrayList<DavAce>();
    sardine.setAcl(url, aces);
    DavAcl acls = sardine.getAcl(url);
    for (DavAce davace : acls.getAces()) {
        if (davace.getInherited() == null)
            fail("We have cleared all ACEs, should not have anymore non inherited ACEs");
    }
    aces.clear();
    DavAce ace = new DavAce(new DavPrincipal(PrincipalType.HREF, "/users/someone", null));
    ace.getGranted().add("read");
    aces.add(ace);
    ace = new DavAce(new DavPrincipal(PrincipalType.PROPERTY, new QName("DAV:", "owner", "somespace"), null));
    ace.getGranted().add("read");
    aces.add(ace);
    sardine.setAcl(url, aces);
    int count = 0;
    for (DavAce davace : sardine.getAcl(url).getAces()) {
        if (davace.getInherited() == null) {
            count++;
        }
    }
    sardine.delete(url);
    assertEquals("After setting two ACL, should find them back", 2, count);
}

From source file:gov.nih.nci.cabig.caaers.web.security.FabricatedAuthenticationFilter.java

private void filterAuthoritiesByStudy(List<GrantedAuthority> list, int studyId) {
    Study study = studyRepository.getById(studyId);
    if (study != null) {
        CurrentEntityHolder.setEntity(study);
        list.clear();
        for (String role : securityFacade.getRoles(SecurityUtils.getUserLoginName(), study)) {
            GrantedAuthority ga = new GrantedAuthorityImpl(role);
            if (!list.contains(ga)) {
                list.add(ga);/*w  w w. j a  v a2 s.c  o  m*/
            }
        }

    }
}

From source file:com.smartitengineering.cms.spi.impl.content.search.ContentSearcherImpl.java

@Override
public void reIndex(final WorkspaceId workspaceId) {
    if (logger.isInfoEnabled()) {
        logger.info(new StringBuilder("Re-Indexing ").append(workspaceId).toString());
    }/*from  www.  ja  v  a2 s  .  c o m*/
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            try {
                final QueryParameter param;
                if (workspaceId == null) {
                    param = null;
                } else {
                    param = QueryParameterFactory.getStringLikePropertyParam("id",
                            new StringBuilder(workspaceId.toString()).append(':').toString(), MatchMode.START);
                }
                final QueryParameter<Integer> maxResultsParam = QueryParameterFactory.getMaxResultsParam(100);
                boolean hasMore = true;
                ContentId lastId = null;
                List<QueryParameter> params = new ArrayList<QueryParameter>();
                logger.debug("Beginning iteration over contents");
                while (hasMore) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Trying with Last ID " + lastId);
                    }
                    params.clear();
                    if (param != null) {
                        params.add(param);
                    }
                    params.add(maxResultsParam);
                    if (lastId != null) {
                        try {
                            params.add(QueryParameterFactory.getGreaterThanPropertyParam("id",
                                    contentLoader.getByteArrayFromId(lastId)));
                        } catch (Exception ex) {
                            logger.warn("Could not add last id clause " + lastId.toString(), ex);
                        }
                    }
                    List<Content> list = contentLoader.getQueryResult(params);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Has More " + hasMore);
                        logger.debug(
                                "Content numbers in current iteration " + (list != null ? list.size() : -1));
                    }
                    if (list == null || list.isEmpty()) {
                        hasMore = false;
                    } else {
                        final Content[] contents = new Content[list.size()];
                        int index = 0;
                        for (Content content : list) {
                            if (logger.isDebugEnabled()) {
                                logger.debug("Attempting to index " + content.getContentId());
                            }
                            reindexListener.notify(SmartContentAPI.getInstance().getEventRegistrar()
                                    .<Content>createEvent(EventType.UPDATE, Type.CONTENT, content));
                            contents[index++] = content;
                        }
                        lastId = contents[contents.length - 1].getContentId();
                    }
                    if (logger.isDebugEnabled()) {
                        logger.debug("Has More " + hasMore);
                        logger.debug(
                                "Content numbers in current iteration " + (list != null ? list.size() : -1));
                        logger.debug("Last ID " + lastId);
                        logger.debug("Going for next iteration " + hasMore);
                    }
                }
            } catch (Exception ex) {
                logger.error("Error reindexing", ex);
            }
        }
    });
}

From source file:csns.util.MassMailSender.java

public void send(SimpleMailMessage email, List<String> addresses) {
    List<String> bccAddresses = new ArrayList<String>();
    for (int i = 0; i < addresses.size(); ++i) {
        if (!addresses.get(i).endsWith("@localhost"))
            bccAddresses.add(addresses.get(i));
        if (bccAddresses.size() >= maxRecipientsPerMessage
                || bccAddresses.size() > 0 && i == addresses.size() - 1) {
            email.setBcc(bccAddresses.toArray(new String[0]));
            try {
                mailSender.send(email);//  w ww . j av  a  2 s . c o  m
            } catch (MailException e) {
                logger.warn(e.getMessage());
            }
            logger.debug("sent email to " + StringUtils.collectionToCommaDelimitedString(bccAddresses));
            bccAddresses.clear();
        }
    }
}