List of usage examples for java.lang Iterable Iterable
Iterable
From source file:sf.net.experimaestro.utils.JSUtils.java
private static Iterable<? extends Map.Entry<Object, Object>> iterable(final NativeObject object) { final Object[] ids = object.getIds(); return new Iterable<Map.Entry<Object, Object>>() { @Override//from w w w . jav a 2 s.c om public Iterator<Map.Entry<Object, Object>> iterator() { return new AbstractIterator<Map.Entry<Object, Object>>() { int i = 0; @Override protected Map.Entry<Object, Object> computeNext() { if (i >= ids.length) return endOfData(); final Object id = ids[i++]; String key = id.toString(); final Object value = object.get(id); return new AbstractMap.SimpleImmutableEntry<>(key, value); } }; } }; }
From source file:org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl.java
private synchronized void addKeepAliveApplicationsToProto() { maybeInitBuilder();/* w w w.j a v a 2 s. com*/ builder.clearKeepAliveApplications(); if (keepAliveApplications == null) return; Iterable<ApplicationIdProto> iterable = new Iterable<ApplicationIdProto>() { @Override public Iterator<ApplicationIdProto> iterator() { return new Iterator<ApplicationIdProto>() { Iterator<ApplicationId> iter = keepAliveApplications.iterator(); @Override public boolean hasNext() { return iter.hasNext(); } @Override public ApplicationIdProto next() { return convertToProtoFormat(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; builder.addAllKeepAliveApplications(iterable); }
From source file:sample.client.Application.java
<T> Iterable<T> toIterable(final Enumeration<T> enumeration) { return new Iterable<T>() { public Iterator<T> iterator() { return (enumeration == null ? Collections.<T>emptyIterator() : new Iterator<T>() { public boolean hasNext() { return enumeration.hasMoreElements(); }/*from www. j a va 2 s . c om*/ public T next() { return enumeration.nextElement(); } public void remove() { throw new UnsupportedOperationException("Auto-generated method stub"); } }); } }; }
From source file:de.uniba.wiai.kinf.pw.projects.lillytab.reasoner.abox.RABox.java
@Override public Iterable<Pair<R, NodeID>> getPredecessorPairs() { return new Iterable<Pair<R, NodeID>>() { @Override//w w w . ja va2 s.c om public Iterator<Pair<R, NodeID>> iterator() { return new SubRoleAwarePairIterator(_predecessors); } }; }
From source file:name.martingeisse.webide.features.java.compiler.memfile.MemoryFileManager.java
@Override public Iterable<JavaFileObject> list(final Location location, final String packageName, final Set<Kind> kinds, final boolean recurse) throws IOException { logger.trace("listing memory files for location [" + location + "], package [" + packageName + "], kinds [" + StringUtils.join(kinds, ", ") + "], recurse [" + recurse + "]"); final Iterable<JavaFileObject> superIterable = super.list(location, packageName, kinds, recurse); final Iterable<JavaFileObject> thisIterable = listThis(location, packageName, kinds, recurse); logger.trace("contributed memory files: " + StringUtils.join(thisIterable.iterator(), ", ")); return new Iterable<JavaFileObject>() { @Override//w ww .j a v a2 s .com public Iterator<JavaFileObject> iterator() { return GenericTypeUtil .unsafeCast(new IteratorChain(superIterable.iterator(), thisIterable.iterator())); } }; }
From source file:org.apache.cayenne.map.DbEntity.java
/** * Returns an Iterable instance over expression path components based on * this entity./*w w w. ja va2 s .c om*/ * * @since 3.0 */ @Override @SuppressWarnings("unchecked") public Iterable<PathComponent<DbAttribute, DbRelationship>> resolvePath(final Expression pathExp, final Map aliasMap) { if (pathExp.getType() == Expression.DB_PATH) { return new Iterable<PathComponent<DbAttribute, DbRelationship>>() { public Iterator iterator() { return new PathComponentIterator(DbEntity.this, (String) pathExp.getOperand(0), aliasMap); } }; } throw new ExpressionException( "Invalid expression type: '" + pathExp.expName() + "', DB_PATH is expected."); }
From source file:org.apache.kylin.engine.spark.SparkCubing.java
private void writeDictionary(DataFrame intermediateTable, String cubeName, String segmentId) throws Exception { final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv(); final CubeManager cubeManager = CubeManager.getInstance(kylinConfig); final CubeInstance cubeInstance = cubeManager.reloadCubeLocal(cubeName); final String[] columns = intermediateTable.columns(); final CubeSegment seg = cubeInstance.getSegmentById(segmentId); final CubeDesc cubeDesc = cubeInstance.getDescriptor(); final HashMap<Integer, TblColRef> tblColRefMap = Maps.newHashMap(); final CubeJoinedFlatTableEnrich flatDesc = new CubeJoinedFlatTableEnrich( EngineFactory.getJoinedFlatTableDesc(seg), cubeDesc); final List<TblColRef> baseCuboidColumn = Cuboid.findById(cubeDesc, Cuboid.getBaseCuboidId(cubeDesc)) .getColumns();//ww w . j ava 2s .c om final long start = System.currentTimeMillis(); final RowKeyDesc rowKey = cubeDesc.getRowkey(); for (int i = 0; i < baseCuboidColumn.size(); i++) { TblColRef col = baseCuboidColumn.get(i); if (!rowKey.isUseDictionary(col)) { continue; } final int rowKeyColumnIndex = flatDesc.getRowKeyColumnIndexes()[i]; tblColRefMap.put(rowKeyColumnIndex, col); } Map<TblColRef, Dictionary<String>> dictionaryMap = Maps.newHashMap(); for (Map.Entry<Integer, TblColRef> entry : tblColRefMap.entrySet()) { final String column = columns[entry.getKey()]; final TblColRef tblColRef = entry.getValue(); final DataFrame frame = intermediateTable.select(column).distinct(); final Row[] rows = frame.collect(); dictionaryMap.put(tblColRef, DictionaryGenerator.buildDictionary(tblColRef.getType(), new IterableDictionaryValueEnumerator(new Iterable<String>() { @Override public Iterator<String> iterator() { return new Iterator<String>() { int i = 0; @Override public boolean hasNext() { return i < rows.length; } @Override public String next() { if (hasNext()) { final Row row = rows[i++]; final Object o = row.get(0); return o != null ? o.toString() : null; } else { throw new NoSuchElementException(); } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }))); } final long end = System.currentTimeMillis(); CubingUtils.writeDictionary(seg, dictionaryMap, start, end); try { CubeUpdate cubeBuilder = new CubeUpdate(cubeInstance); cubeBuilder.setToUpdateSegs(seg); cubeManager.updateCube(cubeBuilder); } catch (IOException e) { throw new RuntimeException("Failed to deal with the request: " + e.getLocalizedMessage()); } }
From source file:oculus.aperture.common.JSONProperties.java
@Override public Iterable<Long> getLongs(String key) { try {/* ww w . ja v a 2 s . c o m*/ final JSONArray array = obj.getJSONArray(key); return new Iterable<Long>() { @Override public Iterator<Long> iterator() { return new Iterator<Long>() { private final int n = array.length(); private int i = 0; @Override public boolean hasNext() { return n > i; } @Override public Long next() { try { return (n > i) ? array.getLong(i++) : null; } catch (JSONException e) { return null; } } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }; } catch (JSONException e) { return EmptyIterable.instance(); } }
From source file:com.healthmarketscience.jackcess.IndexCursor.java
/** * Returns an Iterable whose iterator() method returns the result of a call * to {@link #entryIterator(Collection,Object...)} * @throws IllegalStateException if an IOException is thrown by one of the * operations, the actual exception will be contained within *//*from w w w . j a v a2 s . c o m*/ public Iterable<Map<String, Object>> entryIterable(final Collection<String> columnNames, final Object... entryValues) { return new Iterable<Map<String, Object>>() { public Iterator<Map<String, Object>> iterator() { return new EntryIterator(columnNames, toRowValues(entryValues)); } }; }
From source file:org.omnaest.utils.structure.iterator.IterableUtils.java
/** * Returns a new {@link Iterable} based on a given {@link Factory} for {@link Iterator}s * /*w w w . j a v a 2 s. co m*/ * @param iteratorFactory * @return */ public static <E> Iterable<E> valueOf(final Factory<Iterator<E>> iteratorFactory) { return new Iterable<E>() { @Override public Iterator<E> iterator() { return iteratorFactory != null ? iteratorFactory.newInstance() : null; } }; }