List of usage examples for java.lang Iterable getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.antsdb.saltedfish.sql.ExternalTable.java
public static <T> ExternalTable wrap(Orca orca, String namespace, Class<T> klass, Iterable<T> iterable) { ClassBasedTable<T> table = new ClassBasedTable<>(); table.source = iterable;/*from w w w .j a v a 2 s. com*/ table.meta.setNamespace(namespace).setTableName(iterable.getClass().getSimpleName()); List<ColumnMeta> columns = new ArrayList<>(); for (Field i : klass.getFields()) { ColumnMeta column = new ColumnMeta(orca.getTypeFactory(), new SlowRow(0)); column.setColumnName(i.getName()).setId(table.meta.getColumns().size()); if (i.getType() == String.class) { column.setType(DataType.varchar()); } else if (i.getType() == int.class) { column.setType(DataType.integer()); } else if (i.getType() == long.class) { column.setType(DataType.longtype()); } else { throw new NotImplementedException(); } columns.add(column); table.fields.add(i); } table.meta.setColumns(columns); return table; }
From source file:com.bitranger.parknshop.common.recommend.collections.CollectionUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <E> Iterable<E> fast(final Iterable<E> iter) { if (iter instanceof FastIterable) { return new Iterable<E>() { @Override//from w w w. j ava 2 s . com public Iterator<E> iterator() { return ((FastIterable) iter).fastIterator(); } }; } else if (iter instanceof Cursor) { throw new IllegalArgumentException(); } else { Optional<Method> fastMethod = fastIteratorMethods.getUnchecked(iter.getClass()); if (fastMethod.isPresent()) { final Method method = fastMethod.get(); return new Iterable<E>() { @Override public Iterator<E> iterator() { try { return (Iterator<E>) method.invoke(iter); } catch (IllegalAccessException e) { return iter.iterator(); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } } }; } else { return iter; } } }
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 w w. j a v a 2s . co 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.grouplens.lenskit.collections.CollectionUtils.java
/** * Use the fast iterator of an iterable, if available. * * @param <E> The type of object to iterate. * @param iter An iterable to wrap/*from w w w . j a v a 2s. c o m*/ * @return An iterable using the underlying iterable's fast iterator, if present, * to do iteration. Fast iteration is detected by looking for a {@code fastIterator()} * method, like is present in {@link FastEntrySet}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <E> Iterable<E> fast(final Iterable<E> iter) { if (iter instanceof FastIterable) { return new Iterable<E>() { @Override public Iterator<E> iterator() { return ((FastIterable) iter).fastIterator(); } }; } else if (iter instanceof Cursor) { return ((Cursor<E>) iter).fast(); } else { Optional<Method> fastMethod = fastIteratorMethods.getUnchecked(iter.getClass()); if (fastMethod.isPresent()) { final Method method = fastMethod.get(); return new Iterable<E>() { @Override public Iterator<E> iterator() { try { return (Iterator<E>) method.invoke(iter); } catch (IllegalAccessException e) { return iter.iterator(); } catch (InvocationTargetException e) { throw Throwables.propagate(e.getCause()); } } }; } else { return iter; } } }