Example usage for java.lang Iterable Iterable

List of usage examples for java.lang Iterable Iterable

Introduction

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

Prototype

Iterable

Source Link

Usage

From source file:net.solarnetwork.node.backup.DefaultBackupManager.java

@Override
public Iterable<BackupResource> resourcesForBackup() {
    BackupService service = activeBackupService();
    if (service == null) {
        log.debug("No BackupService available, can't find resources for backup");
        return Collections.emptyList();
    }/*from w  w  w  . ja va2  s. c o m*/
    if (service.getInfo().getStatus() != BackupStatus.Configured) {
        log.info("BackupService {} in {} state, can't find resources for backup", service.getKey(),
                service.getInfo().getStatus());
        return Collections.emptyList();
    }

    final List<Iterator<BackupResource>> resources = new ArrayList<Iterator<BackupResource>>(10);
    for (BackupResourceProvider provider : resourceProviders) {
        // map each resource into a sub directory
        Iterator<BackupResource> itr = provider.getBackupResources().iterator();
        resources.add(new PrefixedBackupResourceIterator(itr, provider.getKey()));

    }
    return new Iterable<BackupResource>() {

        @Override
        public Iterator<BackupResource> iterator() {
            return new UnionIterator<BackupResource>(resources);
        }

    };
}

From source file:pt.webdetails.cpf.Util.java

public static <T> Iterable<T> toIterable(final T[] array) {
    return new Iterable<T>() {

        public Iterator<T> iterator() {
            return new Iterator<T>() {

                private int idx = 0;

                public boolean hasNext() {
                    return idx < array.length;
                }/*from   ww  w .  j  a v  a2s  .c o m*/

                public T next() {
                    return array[idx++];
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:com.emc.ecs.sync.service.DbService.java

public Iterable<SyncRecord> getSyncErrors() {
    initCheck();/*from w  w w . j a  v  a 2  s  .c om*/
    return TimingUtil.time(timingPlugin, OPERATION_LIST_ERRORS, new Function<Iterable<SyncRecord>>() {
        @Override
        public Iterable<SyncRecord> call() {
            return new Iterable<SyncRecord>() {
                @Override
                public Iterator<SyncRecord> iterator() {
                    return new RowIterator<>(getJdbcTemplate().getDataSource(), new Mapper(),
                            SyncRecord.selectErrors(objectsTableName));
                }
            };
        }
    });
}

From source file:name.martingeisse.stackd.server.section.SectionWorkingSet.java

/**
 * Of multiple objects, returns those that are already present in the cache.
 * //w  ww  .  j a va 2s .com
 * @param sectionDataIds the section data IDs
 * @return the cached section-related objects
 */
public ImmutableMap<SectionDataId, SectionDataCacheEntry> getAllPresent(final SectionDataId... sectionDataIds) {
    return cache.getAllPresent(new Iterable<SectionDataId>() {
        @Override
        @SuppressWarnings("unchecked")
        public Iterator<SectionDataId> iterator() {
            return new ArrayIterator(sectionDataIds);
        }
    });
}

From source file:oculus.aperture.common.JSONProperties.java

@Override
public Iterable<String> getStrings(String key) {
    try {//from   ww  w .  ja va 2  s  .  c  o m
        final JSONArray array = obj.getJSONArray(key);

        return new Iterable<String>() {
            @Override
            public Iterator<String> iterator() {
                return new Iterator<String>() {
                    private final int n = array.length();
                    private int i = 0;

                    @Override
                    public boolean hasNext() {
                        return n > i;
                    }

                    @Override
                    public String next() {
                        try {
                            return (n > i) ? array.getString(i++) : null;
                        } catch (JSONException e) {
                            return null;
                        }
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }
        };

    } catch (JSONException e) {
        return EmptyIterable.instance();
    }
}

From source file:org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl.java

/**
 * Return an iterator that reports all the containers under base path
 * /*from  w w w  .  j  a  va2  s.co  m*/
 * @return
 */
@Override
public Iterable<String> getAllContainerNames() {
    Iterable<String> containers = new Iterable<String>() {
        @Override
        public Iterator<String> iterator() {
            return new FileIterator(buildPathStartingFromBaseDir(), DirectoryFileFilter.INSTANCE);
        }
    };

    return containers;
}

From source file:org.omnaest.utils.table.impl.ArrayTable.java

@Override
public Iterable<Cell<E>> cells() {
    return new Iterable<Cell<E>>() {
        @Override//www  .  j a va 2  s  .  c o  m
        public Iterator<Cell<E>> iterator() {
            final Iterator<Row<E>> rowIterator = rows().iterator();
            return IteratorUtils.factoryBasedIterator(new Factory<Iterator<Cell<E>>>() {
                @Override
                public Iterator<Cell<E>> newInstance() {
                    return rowIterator.hasNext() ? rowIterator.next().cells().iterator() : null;
                }
            });
        }
    };
}

From source file:edu.byu.nlp.dataset.BasicSparseFeatureVector.java

@Override
public Iterable<Entry> sparseEntries() {
    return new Iterable<Entry>() {

        @Override/*from   w  ww  .j  a  va2 s  .co m*/
        public Iterator<Entry> iterator() {
            return new SparseEntryIterator();
        }

    };
}

From source file:com.antsdb.saltedfish.util.UberUtil.java

public static <T> Iterable<T> once(final Iterator<T> source) {
    return new Iterable<T>() {
        private AtomicBoolean exhausted = new AtomicBoolean();

        public Iterator<T> iterator() {
            Preconditions.checkState(!exhausted.getAndSet(true));
            return source;
        }// w  ww  .  j  a v  a 2s  .c o  m
    };
}

From source file:org.apache.hadoop.yarn.server.api.records.impl.pb.NodeStatusPBImpl.java

private synchronized void addSqueezedContainersToProto() {
    maybeInitBuilder();//from   w  ww .j av  a2s.  c o  m
    builder.clearSqueezedContainers();
    if (squeezedContainers == null)
        return;
    Iterable<ContainerSqueezeUnitProto> iterable = new Iterable<ContainerSqueezeUnitProto>() {
        @Override
        public Iterator<ContainerSqueezeUnitProto> iterator() {
            return new Iterator<ContainerSqueezeUnitProto>() {

                Iterator<ContainerSqueezeUnit> iter = squeezedContainers.iterator();

                @Override
                public boolean hasNext() {
                    return iter.hasNext();
                }

                @Override
                public ContainerSqueezeUnitProto next() {
                    return convertToProtoFormat(iter.next());
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();

                }
            };

        }
    };
    builder.addAllSqueezedContainers(iterable);
}