Example usage for java.lang Iterable iterator

List of usage examples for java.lang Iterable iterator

Introduction

In this page you can find the example usage for java.lang Iterable iterator.

Prototype

Iterator<T> iterator();

Source Link

Document

Returns an iterator over elements of type T .

Usage

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void defaultAccessMethodsWithStaticNativeOnly() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withAccess(AccessType.DEFAULT);
    memberCriteria.withModifiers(Modifier.STATIC | Modifier.NATIVE);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        int modifiers = member.getModifiers();
        assertFalse(Modifier.isPublic(modifiers));
        assertFalse(Modifier.isProtected(modifiers));
        assertFalse(Modifier.isPrivate(modifiers));
        assertTrue(Modifier.isStatic(modifiers));
        assertTrue(Modifier.isNative(modifiers));
    }//from ww w  . jav  a 2s.  co  m
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@SuppressWarnings("unchecked")
@Test//  www  .j av a2s .  com
public void publicAbstractMethodStartingWithAdd() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withModifiers(Modifier.ABSTRACT);
    memberCriteria.named(Pattern.compile("add.*"));
    memberCriteria.setMemberIterateOrder(ReflectFacade.getMemberNameComparator());
    Collection<Class<?>> iteratedTypes = new ArrayList<Class<?>>(Arrays.asList(List.class, Collection.class));
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        iteratedTypes.remove(member.getDeclaringClass());
        String name = member.getName();
        assertTrue(name.startsWith("add"));
        int modifiers = member.getModifiers();
        assertTrue(Modifier.isAbstract(modifiers));
    }
    assertTrue("Some types have not been iterated. " + iteratedTypes, iteratedTypes.isEmpty());
}

From source file:argendata.service.impl.AppServiceImpl.java

@Override
public List<App> getAllApprovedApps() {
    List<App> resp = new ArrayList<App>();
    Iterable<Semanticapp> mySemanticApps = semanticAppDao.getAll();
    Iterator<Semanticapp> mySemanticAppIterator = mySemanticApps.iterator();
    while (mySemanticAppIterator.hasNext()) {
        Semanticapp aux1 = mySemanticAppIterator.next();
        RelationalApp aux2 = this.relationalAppDao.getRelationalApp("Semanticapp:" + aux1.getName());
        if (aux1 != null && aux2 != null) {
            resp.add(new App(aux1, aux2));
        }/*from   w  w  w  . ja v a 2 s  . c  o m*/
    }

    return resp;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test
public void hierarchyTraveral() {
    memberCriteria.membersOfType(Method.class);
    memberCriteria.withModifiers(Modifier.ABSTRACT);
    memberCriteria.named(Pattern.compile("add.*"));
    Class<?> currentHierarchyClass = ArrayList.class;
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(ArrayList.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    assertTrue(memberIterable.iterator().hasNext());
    for (Member member : memberIterable) {
        assertTrue("member must be a method", member instanceof Method);
        if (!currentHierarchyClass.equals(member.getDeclaringClass())) {
            if (!member.getDeclaringClass().isInterface()) {
                assertTrue("members must be iterated " + "from subclass to superclass",
                        ((Class<?>) member.getDeclaringClass()).isAssignableFrom(currentHierarchyClass));
                // so the current declaring class is not the members
                // declaring
                // class which means we went up the hierarchy
                currentHierarchyClass = member.getDeclaringClass();
            }/*from w ww .  j a v a2s  . c  o  m*/
        }
    }
}

From source file:info.magnolia.ui.form.field.factory.SelectFieldFactory.java

/**
 * Build options based on a remote Node.
 * Simply get the remote Node, Iterate his child nodes and for every child
 * try to get the Value and Label property.
 * In addition create an ArrayList<SelectFieldOptionDefinition> representing this options.
 *///from   ww  w .ja va2  s. co m
private void buildRemoteOptions(List<SelectFieldOptionDefinition> res) {
    Node parent = SessionUtil.getNode(definition.getRepository(), definition.getPath());
    if (parent != null) {
        try {
            // Get only relevant child nodes
            Iterable<Node> iterable = NodeUtil.getNodes(parent, createRemoteOptionFilterPredicate());
            Iterator<Node> iterator = iterable.iterator();
            // Iterate parent children
            while (iterator.hasNext()) {
                SelectFieldOptionDefinition option = new SelectFieldOptionDefinition();
                Node child = iterator.next();
                // Get Label and Value
                String label = getRemoteOptionsName(child, optionLabelName);
                String value = getRemoteOptionsValue(child, optionValueName);
                option.setLabel(getMessage(label));
                option.setValue(value);

                if (child.hasProperty(SelectFieldDefinition.OPTION_SELECTED_PROPERTY_NAME) && Boolean
                        .parseBoolean(child.getProperty(SelectFieldDefinition.OPTION_SELECTED_PROPERTY_NAME)
                                .getString())) {
                    option.setSelected(true);
                    initialSelectedKey.add(option.getValue());
                }
                if (child.hasProperty(SelectFieldDefinition.OPTION_NAME_PROPERTY_NAME)) {
                    option.setName(
                            child.getProperty(SelectFieldDefinition.OPTION_NAME_PROPERTY_NAME).getString());
                }
                if (child.hasProperty(SelectFieldDefinition.OPTION_ICONSRC_PROPERTY_NAME)) {
                    option.setIconSrc(
                            child.getProperty(SelectFieldDefinition.OPTION_ICONSRC_PROPERTY_NAME).getString());
                    hasOptionIcon = true;
                }
                res.add(option);
            }
            definition.setOptions(res);
        } catch (Exception e) {
            log.warn("Not able to build options based on option node " + parent.toString(), e);
        }
    }
}

From source file:net.longfalcon.newsj.Backfill.java

/**
 * Returns single timestamp from a local article number
 * @param nntpClient/*from  w  w w .  j ava 2s. c o m*/
 * @param articleNumber
 * @param debug
 * @return
 */
public DateTime postDate(NewsClient nntpClient, long articleNumber, boolean debug) throws IOException {
    int attempts = 0;
    boolean success = false;
    String dateString = "";
    do {
        try {
            Iterable<NewsArticle> articleIterable = nntpClient.iterateArticleInfo(articleNumber, articleNumber);
            NewsArticle article = articleIterable.iterator().next();
            if (article.getDate() != null) {
                dateString = article.getDate();
                success = true;
            } else {
                success = false;
            }
        } catch (NoSuchElementException e) {
            if (debug) {
                _log.debug(e.toString());
            }
            success = false;
        } catch (Exception e) {
            _log.error(e.toString(), e);
            success = false;
        }
        if (debug && attempts > 0) {
            _log.info(String.format("retried %d time(s)", attempts));
        }
        attempts++;

    } while (attempts <= 3 && !success);

    if (!success) {
        _log.warn("unable to find message id " + articleNumber);
        return null;
    }
    DateTime postDate = DateUtil.parseNNTPDate(dateString);
    return postDate;
}

From source file:com.chiorichan.scheduler.ChioriScheduler.java

public void cancelTasks(final TaskCreator creator) {
    Validate.notNull(creator, "Cannot cancel tasks of null creator");
    final ChioriTask task = new ChioriTask(new Runnable() {
        public void run() {
            check(ChioriScheduler.this.pending);
            check(ChioriScheduler.this.temp);
        }/*from  w  ww  .  j  a v  a2  s. c  o m*/

        void check(final Iterable<ChioriTask> collection) {
            final Iterator<ChioriTask> tasks = collection.iterator();
            while (tasks.hasNext()) {
                final ChioriTask task = tasks.next();
                if (task.getOwner().equals(creator)) {
                    task.cancel0();
                    tasks.remove();
                    if (task.isSync()) {
                        runners.remove(task.getTaskId());
                    }
                }
            }
        }
    });
    handle(task, 0L);
    for (ChioriTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
        if (taskPending == task) {
            return;
        }
        if (taskPending.getTaskId() != -1 && taskPending.getOwner().equals(creator)) {
            taskPending.cancel0();
        }
    }
    for (ChioriTask runner : runners.values()) {
        if (runner.getOwner().equals(creator)) {
            runner.cancel0();
        }
    }
}

From source file:com.threewks.thundr.search.gae.BaseGaeSearchService.java

@SuppressWarnings("unchecked")
<O, R> List<R> convert(Iterable<O> inputs, Class<R> type) {
    Iterator<O> iterator = inputs.iterator();
    if (!iterator.hasNext()) {
        return Collections.emptyList();
    }/*from   w  ww  . j a va 2 s . c om*/

    List<R> results = new ArrayList<R>();
    ETransformer<O, R> transformer = null;
    for (O t : inputs) {
        if (transformer == null) {
            Class<O> inputType = (Class<O>) t.getClass();
            transformer = transformerManager.getTransformerSafe(inputType, type);
        }
        results.add(transformer.from(t));
    }

    return results;
}

From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java

@Test(expected = IllegalStateException.class)
public void iteratorRemove() {
    memberCriteria.membersOfType(Field.class);
    memberCriteria.withAccess(AccessType.PRIVATE);
    memberCriteria.withModifiers(Modifier.STATIC);
    ClassCriteria classCriteria = new ClassCriteria();
    Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class);
    Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable);
    Iterator<Member> iterator = memberIterable.iterator();
    assertTrue(iterator.hasNext());//from  www .  j  av  a  2s  . c  o m
    iterator.remove();
}

From source file:com.chiorichan.scheduler.ChioriScheduler.java

public void cancelTask(final int taskId) {
    if (taskId <= 0) {
        return;/*from   w  w w  . j ava2 s  .  co  m*/
    }
    ChioriTask task = runners.get(taskId);
    if (task != null) {
        task.cancel0();
    }
    task = new ChioriTask(new Runnable() {
        public void run() {
            if (!check(ChioriScheduler.this.temp)) {
                check(ChioriScheduler.this.pending);
            }
        }

        private boolean check(final Iterable<ChioriTask> collection) {
            final Iterator<ChioriTask> tasks = collection.iterator();
            while (tasks.hasNext()) {
                final ChioriTask task = tasks.next();
                if (task.getTaskId() == taskId) {
                    task.cancel0();
                    tasks.remove();
                    if (task.isSync()) {
                        runners.remove(taskId);
                    }
                    return true;
                }
            }
            return false;
        }
    });
    handle(task, 0L);
    for (ChioriTask taskPending = head.getNext(); taskPending != null; taskPending = taskPending.getNext()) {
        if (taskPending == task) {
            return;
        }
        if (taskPending.getTaskId() == taskId) {
            taskPending.cancel0();
        }
    }
}