List of usage examples for java.lang Iterable Iterable
Iterable
From source file:org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener.java
private void authorizeDropMultiPartition(HiveMultiPartitionAuthorizationProviderBase authorizer, final PreDropPartitionEvent context) throws AuthorizationException, HiveException { Iterator<Partition> partitionIterator = context.getPartitionIterator(); final TableWrapper table = new TableWrapper(context.getTable()); final Iterator<org.apache.hadoop.hive.ql.metadata.Partition> qlPartitionIterator = Iterators.transform( partitionIterator, new Function<Partition, org.apache.hadoop.hive.ql.metadata.Partition>() { @Override/* w w w .j a v a 2 s .c o m*/ public org.apache.hadoop.hive.ql.metadata.Partition apply(Partition partition) { try { return new PartitionWrapper(table, partition); } catch (Exception exception) { LOG.error("Could not construct partition-object for: " + partition, exception); throw new RuntimeException(exception); } } }); authorizer.authorize(new TableWrapper(context.getTable()), new Iterable<org.apache.hadoop.hive.ql.metadata.Partition>() { @Override public Iterator<org.apache.hadoop.hive.ql.metadata.Partition> iterator() { return qlPartitionIterator; } }, HiveOperation.ALTERTABLE_DROPPARTS.getInputRequiredPrivileges(), HiveOperation.ALTERTABLE_DROPPARTS.getOutputRequiredPrivileges()); }
From source file:net.orfjackal.retrolambda.test.DefaultMethodsTest.java
/** * We're unable to backport default methods if we cannot modify the interface, * e.g. if it's part of the standard library or a third-party library. *///w ww .j a va2 s. c o m @Test public void default_methods_of_library_interfaces_are_ignored_silently() throws Exception { @SuppressWarnings("unchecked") Iterator<String> dummy = mock(Iterator.class); // the Iterable interface has default methods in Java 8, but that // should not prevent us from using it in previous Java versions Iterable<String> it = new Iterable<String>() { @Override public Iterator<String> iterator() { return dummy; } }; assertThat("interface should work as usual", it.iterator(), is(dummy)); assertThat("should not copy default methods from library interfaces", it.getClass().getDeclaredMethods(), arrayWithSize(1)); }
From source file:org.apache.jackrabbit.core.state.XAItemStateManager.java
/** * Takes an iterator over {@link ItemState}s and returns a new iterator that * filters out all but REFERENCE {@link PropertyState}s. * * @param itemStates item state source iterator. * @return iterator over reference property states. *//*from w w w .j a v a 2 s.c o m*/ private Iterable<PropertyState> filterReferenceProperties(final Iterable<ItemState> itemStates) { return new Iterable<PropertyState>() { @SuppressWarnings("unchecked") public Iterator<PropertyState> iterator() { return (Iterator<PropertyState>) new FilterIterator(itemStates.iterator(), new Predicate() { public boolean evaluate(Object object) { ItemState state = (ItemState) object; if (!state.isNode()) { PropertyState prop = (PropertyState) state; return prop.getType() == PropertyType.REFERENCE; } return false; } }); } }; }
From source file:org.omnaest.utils.structure.iterator.IterableUtils.java
/** * Returns an {@link Factory} of {@link Iterator} instances which is based on an internal {@link List} buffer which will contain * the elements of the given {@link Iterator}. This allows to replicate the content of an {@link Iterator} multiple times. * //from w ww . j a v a 2 s . c o m * @see #valueOf(Iterator) * @param iterator * {@link Iterator} * @param replicate * if true, the {@link Iterable} will return always a new {@link Iterator} instance with the same elements based on an * internal immutable {@link List} buffer, otherwise only the same given instance without using a buffer. * @return new {@link Factory} instance for {@link Iterator}s */ public static <E> Iterable<E> valueOf(final Iterator<E> iterator, boolean replicate) { return replicate ? new Iterable<E>() { private List<E> list = ImmutableList.<E>copyOf(iterator); @Override public Iterator<E> iterator() { return this.list.iterator(); } } : valueOf(iterator); }
From source file:edu.brown.utils.CollectionUtil.java
/** * Wrap an Iterable around an Enumeration that is automatically * cast to the specified type//w w w .ja va2s. com * @param <T> * @param e * @return */ public static <T> Iterable<T> iterable(final Enumeration<?> e, Class<T> castType) { return (new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { @Override public boolean hasNext() { return (e.hasMoreElements()); } @SuppressWarnings("unchecked") @Override public T next() { return ((T) e.nextElement()); } @Override public void remove() { throw new NotImplementedException(); } }; } }); }
From source file:org.python.pydev.core.docutils.StringUtils.java
/** * Splits the given string in a list where each element is a line. * /* w w w. j a v a 2 s . c om*/ * @param string string to be split. * @return list of strings where each string is a line. * * @note the new line characters are also added to the returned string. * * IMPORTANT: The line returned will be a substring of the initial line, so, it's recommended that a copy * is created if it should be kept in memory (otherwise the full initial string will also be kept in memory). */ public static Iterable<String> iterLines(final String string) { return new Iterable<String>() { public Iterator<String> iterator() { return new IterLines(string); } }; }
From source file:com.github.jsonj.JsonArray.java
/** * Convenience method to prevent casting JsonElement to JsonObject when iterating in the common case that you have * an array of JsonObjects.//from w w w. ja va 2 s .c om * * @return iterable that iterates over JsonObjects instead of JsonElements. */ public Iterable<JsonObject> objects() { final JsonArray parent = this; return new Iterable<JsonObject>() { @Override public Iterator<JsonObject> iterator() { final Iterator<JsonElement> iterator = parent.iterator(); return new Iterator<JsonObject>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public JsonObject next() { return iterator.next().asObject(); } @Override public void remove() { iterator.remove(); } }; } }; }
From source file:com.healthmarketscience.jackcess.Cursor.java
/** * Returns an Iterable whose iterator() method calls <code>afterLast</code> * on this table and returns a modifiable Iterator which will iterate * through all the rows of this table in reverse order, returning only the * given columns. Use of the Iterator follows the same restrictions as a * call to <code>getPreviousRow</code>. * @throws IllegalStateException if an IOException is thrown by one of the * operations, the actual exception will be contained within *//*from w w w . ja va 2 s . c o m*/ public Iterable<Map<String, Object>> reverseIterable(final Collection<String> columnNames) { return new Iterable<Map<String, Object>>() { public Iterator<Map<String, Object>> iterator() { return new RowIterator(columnNames, MOVE_REVERSE); } }; }
From source file:org.omnaest.utils.structure.iterator.IterableUtils.java
/** * Similar to {@link IteratorUtils#roundRobin(Iterator...)} * /* www.ja va 2 s . c o m*/ * @param iterables * @return */ public static <E> Iterable<E> roundRobin(final Iterable<E>... iterables) { return new Iterable<E>() { @Override public Iterator<E> iterator() { return IteratorUtils.roundRobin(IteratorUtils.valueOfMultiple(iterables)); } }; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlForm.java
/** * Same as {@link #getHtmlElementDescendants} but * ignoring elements that are contained in a nested form. *//* w ww .jav a 2s .c o m*/ private Iterable<HtmlElement> getFormHtmlElementDescendants() { final Iterator<HtmlElement> iter = new DescendantElementsIterator<HtmlElement>(HtmlElement.class) { private boolean filterChildrenOfNestedForms_; @Override protected boolean isAccepted(final DomNode node) { if (node instanceof HtmlForm) { filterChildrenOfNestedForms_ = true; return false; } final boolean accepted = super.isAccepted(node); if (accepted && filterChildrenOfNestedForms_) { return ((HtmlElement) node).getEnclosingForm() == HtmlForm.this; } return accepted; } }; return new Iterable<HtmlElement>() { @Override public Iterator<HtmlElement> iterator() { return iter; } }; }