Example usage for java.util Collection iterator

List of usage examples for java.util Collection iterator

Introduction

In this page you can find the example usage for java.util Collection iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this collection.

Usage

From source file:com.salesmanager.core.util.LocaleUtil.java

public static void setLocaleToEntityCollection(Collection<I18NEntity> coll, Locale locale, String currency) {
    if (coll != null) {
        Iterator i = coll.iterator();
        while (i.hasNext()) {
            I18NEntity entity = (I18NEntity) i.next();
            entity.setLocale(locale, currency);
        }/*from w  ww  .j  a v  a  2  s . co  m*/
    }
}

From source file:com.wolvereness.overmapped.lib.WellOrdered.java

private static <T> Iterator<T> getIterator(final T token, final Map<T, Collection<T>> map) {
    final Collection<T> c = map.get(token);
    if (c == null)
        return null;
    return c.iterator();
}

From source file:gov.va.chir.tagline.dao.DatasetUtil.java

public static boolean hasLabels(final Collection<Document> documents) {
    boolean labels = true;

    final Iterator<Document> iter = documents.iterator();

    while (labels && iter.hasNext()) {
        labels = iter.next().hasLabels();
    }//w w w.ja va  2  s.  com

    return labels;
}

From source file:com.ikon.module.common.CommonNotificationModule.java

/**
 * Send twitter subscription message//from   w  w  w  .  j a v  a 2s. co m
 */
public static void sendTwitterSubscription(String user, String nodePath, String eventType, String comment,
        Set<String> users)
        throws TemplateException, TwitterException, DatabaseException, HttpException, IOException {
    log.debug("sendTwitterSubscription({}, {}, {}, {}, {})",
            new Object[] { user, nodePath, eventType, comment, users });
    Twitter twitter = new Twitter(Config.SUBSCRIPTION_TWITTER_USER, Config.SUBSCRIPTION_TWITTER_PASSWORD);
    StringWriter swStatus = new StringWriter();
    Configuration cfg = TemplateUtils.getConfig();

    Map<String, String> model = new HashMap<String, String>();
    model.put("documentUrl", MailUtils.getTinyUrl(Config.APPLICATION_URL + "?docPath=" + nodePath));
    model.put("documentPath", nodePath);
    model.put("documentName", PathUtils.getName(nodePath));
    model.put("userId", user);
    model.put("eventType", eventType);
    model.put("subscriptionComment", comment);

    if (TemplateUtils.templateExists(Config.SUBSCRIPTION_TWITTER_STATUS)) {
        Template tpl = cfg.getTemplate(Config.SUBSCRIPTION_TWITTER_STATUS);
        tpl.process(model, swStatus);
    } else {
        StringReader sr = new StringReader(Config.SUBSCRIPTION_TWITTER_STATUS);
        Template tpl = new Template("SubscriptionTwitterStatus", sr, cfg);
        tpl.process(model, swStatus);
        sr.close();
    }

    for (Iterator<String> itUsers = users.iterator(); itUsers.hasNext();) {
        String itUser = itUsers.next();
        Collection<TwitterAccount> twitterAccounts = TwitterAccountDAO.findByUser(itUser, true);

        for (Iterator<TwitterAccount> itTwitter = twitterAccounts.iterator(); itTwitter.hasNext();) {
            TwitterAccount ta = itTwitter.next();
            log.info("Twitter Notify from {} to {} ({}) - {}",
                    new Object[] { twitter.getUserId(), ta.getTwitterUser(), itUser, swStatus.toString() });
            twitter.sendDirectMessage(ta.getTwitterUser(), swStatus.toString());
        }
    }
}

From source file:net.sf.zekr.common.util.CollectionUtils.java

public static Object indexOf(Collection<?> collection, String method, Object value)
        throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException,
        NoSuchMethodException {//from  w  w  w. j  a  v a2s  .  c  o m
    for (Iterator<?> iter = collection.iterator(); iter.hasNext();) {
        Object elem = iter.next();
        Object res = elem.getClass().getMethod(method, new Class[] {}).invoke(elem, new Object[] {});
        if (res.equals(value))
            return elem;
    }
    return null;
}

From source file:Main.java

/**
 * Peaks first element from collection//from ww  w.j  a  va 2  s .  c  o m
 * 
 * @param collection
 * @return T
 */
public static <T> T getFirst(Collection<T> collection) {

    T value;

    if (valid(collection)) {
        if (collection instanceof List) {
            value = getFirstFromList(((List<T>) collection));
        } else {
            Iterator<T> iterator = collection.iterator();
            value = iterator.next();
        }
    } else {
        value = null;
    }

    return value;
}

From source file:net.ontopia.topicmaps.utils.KeyGenerator.java

protected static String makeScopeKey(Collection<TopicIF> scope, TopicMapIF othertm) {
    Iterator<TopicIF> it = scope.iterator();
    String[] ids = new String[scope.size()];
    int ix = 0;// w w w. j a va  2  s . c  o  m
    while (it.hasNext()) {
        TopicIF theme = it.next();
        TopicIF othertheme = MergeUtils.findTopic(othertm, theme);
        if (othertheme == null)
            throw new OntopiaRuntimeException("No topic corresponding to: " + theme);
        ids[ix++] = othertheme.getObjectId();
    }

    Arrays.sort(ids);
    return StringUtils.join(ids, " ");
}

From source file:dk.clanie.money.Money.java

/**
 * Summarize a collection of Money.//  ww  w  .  j av a2s.c o m
 * 
 * All the money must have the same currency.
 * 
 * @param monies
 * @return Money - sum. Null if the collection is empty or null.
 * 
 * @throws IllegalArgumentException
 *             if there are Money with different currencies in the
 *             collection.
 */
public static Money sum(Collection<Money> monies) {
    if (monies == null || monies.size() == 0)
        return null;
    Iterator<Money> iter = monies.iterator();
    Money money = iter.next();
    BigDecimal sum = money.amount;
    Currency currency = money.currency;
    while (iter.hasNext()) {
        money = iter.next();
        if (money.currency != currency) {
            throw new IllegalArgumentException("Amounts must have same currency.");
        }
        sum = sum.add(money.amount);
    }
    return new Money(sum, currency);
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.ReadStudentsAndGroupsWithoutShift.java

@Atomic
public static InfoSiteStudentsAndGroups run(String groupPropertiesId) throws FenixServiceException {
    InfoSiteStudentsAndGroups infoSiteStudentsAndGroups = new InfoSiteStudentsAndGroups();

    Grouping groupProperties = FenixFramework.getDomainObject(groupPropertiesId);

    if (groupProperties == null) {
        throw new ExistingServiceException();
    }//w  w  w  .j  a va2s . c om

    List infoSiteStudentsAndGroupsList = new ArrayList();
    List studentGroups = getStudentGroupsWithoutShiftByGroupProperties(groupProperties);
    Iterator iterStudentGroups = studentGroups.iterator();
    while (iterStudentGroups.hasNext()) {

        Collection studentGroupAttendList;
        StudentGroup studentGroup = (StudentGroup) iterStudentGroups.next();

        studentGroupAttendList = studentGroup.getAttendsSet();

        Iterator iterStudentGroupAttendList = studentGroupAttendList.iterator();
        InfoSiteStudentInformation infoSiteStudentInformation = null;
        InfoSiteStudentAndGroup infoSiteStudentAndGroup = null;
        Attends attend = null;

        while (iterStudentGroupAttendList.hasNext()) {
            infoSiteStudentInformation = new InfoSiteStudentInformation();
            infoSiteStudentAndGroup = new InfoSiteStudentAndGroup();

            attend = (Attends) iterStudentGroupAttendList.next();

            infoSiteStudentAndGroup.setInfoStudentGroup(InfoStudentGroup.newInfoFromDomain(studentGroup));

            infoSiteStudentInformation.setNumber(attend.getRegistration().getNumber());

            infoSiteStudentInformation.setUsername(attend.getRegistration().getPerson().getUsername());

            infoSiteStudentInformation.setName(attend.getRegistration().getPerson().getName());

            infoSiteStudentInformation.setEmail(attend.getRegistration().getPerson().getEmail());

            infoSiteStudentInformation.setPersonID(attend.getRegistration().getPerson().getExternalId());

            infoSiteStudentAndGroup.setInfoSiteStudentInformation(infoSiteStudentInformation);

            infoSiteStudentsAndGroupsList.add(infoSiteStudentAndGroup);
        }
    }
    Collections.sort(infoSiteStudentsAndGroupsList, new BeanComparator("infoSiteStudentInformation.number"));

    infoSiteStudentsAndGroups.setInfoSiteStudentsAndGroupsList(infoSiteStudentsAndGroupsList);

    return infoSiteStudentsAndGroups;
}

From source file:com.redhat.victims.VictimsScanner.java

/**
 * //from  w w  w  . j  av a  2 s.c om
 * Iteratively finds all jar files in a given directory and scans them,
 * producing {@link VictimsRecord}. The string values of the resulting
 * records will be written to the specified output stream.
 * 
 * @param dir
 * @param os
 * @throws IOException
 */
private static void scanDir(File dir, VictimsOutputStream vos) throws IOException {
    Collection<File> files = FileUtils.listFiles(dir, new RegexFileFilter("^(.*?)\\.jar"),
            DirectoryFileFilter.DIRECTORY);
    Iterator<File> fi = files.iterator();
    while (fi.hasNext()) {
        scanFile(fi.next(), vos);
    }
}