本文整理汇总了Java中com.google.common.collect.Iterators类的典型用法代码示例。如果您正苦于以下问题:Java Iterators类的具体用法?Java Iterators怎么用?Java Iterators使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Iterators类属于com.google.common.collect包,在下文中一共展示了Iterators类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterator
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
public Iterator<String[]> iterator() throws Exception{
Iterator<CSVRecord> iterCSVRecords = this.getCSVParser().iterator();
Iterator<String[]> iterStringArrays = Iterators.transform(iterCSVRecords, (CSVRecord input) -> {
Iterator<String> iterCols = input.iterator();
List<String> cols = new ArrayList();
while(iterCols.hasNext()){
cols.add(iterCols.next());
}
String[] output = cols.toArray(new String[0]);
return output;
});
return iterStringArrays;
}
示例2: getFields
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Nonnull @Override public Set<? extends Field> getFields() {
return new AbstractSet<Field>() {
@Nonnull @Override public Iterator<Field> iterator() {
return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()),
new Function<java.lang.reflect.Field, Field>() {
@Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) {
return new ReflectionField(input);
}
});
}
@Override public int size() {
return cls.getDeclaredFields().length;
}
};
}
示例3: ExternalSortBatch
import com.google.common.collect.Iterators; //导入依赖的package包/类
public ExternalSortBatch(ExternalSort popConfig, FragmentContext context, RecordBatch incoming) throws OutOfMemoryException {
super(popConfig, context, true);
this.incoming = incoming;
DrillConfig config = context.getConfig();
Configuration conf = new Configuration();
conf.set("fs.default.name", config.getString(ExecConstants.EXTERNAL_SORT_SPILL_FILESYSTEM));
try {
this.fs = FileSystem.get(conf);
} catch (IOException e) {
throw new RuntimeException(e);
}
SPILL_BATCH_GROUP_SIZE = config.getInt(ExecConstants.EXTERNAL_SORT_SPILL_GROUP_SIZE);
SPILL_THRESHOLD = config.getInt(ExecConstants.EXTERNAL_SORT_SPILL_THRESHOLD);
dirs = Iterators.cycle(config.getStringList(ExecConstants.EXTERNAL_SORT_SPILL_DIRS));
copierAllocator = oContext.getAllocator().getChildAllocator(
context, PriorityQueueCopier.INITIAL_ALLOCATION, PriorityQueueCopier.MAX_ALLOCATION, true);
FragmentHandle handle = context.getHandle();
fileName = String.format("%s/major_fragment_%s/minor_fragment_%s/operator_%s", QueryIdHelper.getQueryId(handle.getQueryId()),
handle.getMajorFragmentId(), handle.getMinorFragmentId(), popConfig.getOperatorId());
}
示例4: getFileProperties
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
public SortedSet<TaskOutputFilePropertySpec> getFileProperties() {
if (fileProperties == null) {
TaskPropertyUtils.ensurePropertiesHaveNames(filePropertiesInternal);
Iterator<TaskOutputFilePropertySpec> flattenedProperties = Iterators.concat(Iterables.transform(filePropertiesInternal, new Function<TaskPropertySpec, Iterator<? extends TaskOutputFilePropertySpec>>() {
@Override
public Iterator<? extends TaskOutputFilePropertySpec> apply(TaskPropertySpec propertySpec) {
if (propertySpec instanceof CompositeTaskOutputPropertySpec) {
return ((CompositeTaskOutputPropertySpec) propertySpec).resolveToOutputProperties();
} else {
return Iterators.singletonIterator((TaskOutputFilePropertySpec) propertySpec);
}
}
}).iterator());
fileProperties = TaskPropertyUtils.collectFileProperties("output", flattenedProperties);
}
return fileProperties;
}
示例5: hash
import com.google.common.collect.Iterators; //导入依赖的package包/类
private void hash(com.google.common.hash.Hasher combinedHash, List<String> visitedFilePaths, Set<File> visitedDirs, Iterator<File> toHash) {
while (toHash.hasNext()) {
File file = FileUtils.canonicalize(toHash.next());
if (file.isDirectory()) {
if (visitedDirs.add(file)) {
//in theory, awkward symbolic links can lead to recursion problems.
//TODO - figure out a way to test it. I only tested it 'manually' and the feature is needed.
File[] sortedFiles = file.listFiles();
Arrays.sort(sortedFiles);
hash(combinedHash, visitedFilePaths, visitedDirs, Iterators.forArray(sortedFiles));
}
} else if (file.isFile()) {
visitedFilePaths.add(file.getAbsolutePath());
combinedHash.putBytes(hasher.hash(file).asBytes());
}
//else an empty folder - a legit situation
}
}
示例6: getScriptErrors
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
protected List<Diagnostic> getScriptErrors(Script script) {
EcoreUtil.resolveAll(script.eResource());
List<Diagnostic> diagnostics = super.getScriptErrors(script);
Iterator<Expression> expressions = Iterators.filter(EcoreUtil2.eAll(script), Expression.class);
List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics,
ExceptionDiagnostic.class));
while (expressions.hasNext()) {
Expression expression = expressions.next();
RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(expression);
Result<TypeRef> type = typeSystem.type(ruleEnvironment, expression);
if (type.getRuleFailedException() != null) {
Throwable cause = Throwables.getRootCause(type.getRuleFailedException());
if (!(cause instanceof RuleFailedException)) {
if (cause instanceof Exception) {
result.add(new ExceptionDiagnostic((Exception) cause));
} else {
throw new RuntimeException(cause);
}
}
}
}
validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
return result;
}
示例7: getEntriesWithLimit
import com.google.common.collect.Iterators; //导入依赖的package包/类
private List<PlayerProfileCache.ProfileEntry> getEntriesWithLimit(int limitSize)
{
ArrayList<PlayerProfileCache.ProfileEntry> arraylist = Lists.<PlayerProfileCache.ProfileEntry>newArrayList();
for (GameProfile gameprofile : Lists.newArrayList(Iterators.limit(this.gameProfiles.iterator(), limitSize)))
{
PlayerProfileCache.ProfileEntry playerprofilecache$profileentry = this.getByUUID(gameprofile.getId());
if (playerprofilecache$profileentry != null)
{
arraylist.add(playerprofilecache$profileentry);
}
}
return arraylist;
}
示例8: getSkinUrl
import com.google.common.collect.Iterators; //导入依赖的package包/类
public String getSkinUrl(GameProfile prof) throws ParseException {
Collection<Property> ps = prof.getProperties().get("textures");
if (ps == null || ps.isEmpty()) {
return null;
} else {
Property p = Iterators.getLast(ps.iterator());
JSONObject obj = (JSONObject) new JSONParser().parse(
new String(Base64.getDecoder().decode(p.getValue())));
obj = ((JSONObject) obj.get("textures"));
obj = ((JSONObject) obj.get("SKIN"));
return (String) obj.get("url");
}
}
示例9: getSubscribers
import com.google.common.collect.Iterators; //导入依赖的package包/类
/**
* Gets an iterator representing an immutable snapshot of all subscribers to the given event at
* the time this method is called.
*/
Iterator<Subscriber> getSubscribers(Object event) {
ImmutableSet<Class<?>> eventTypes = flattenHierarchy(event.getClass());
List<Iterator<Subscriber>> subscriberIterators =
Lists.newArrayListWithCapacity(eventTypes.size());
for (Class<?> eventType : eventTypes) {
CopyOnWriteArraySet<Subscriber> eventSubscribers = subscribers.get(eventType);
if (eventSubscribers != null) {
// eager no-copy snapshot
subscriberIterators.add(eventSubscribers.iterator());
}
}
return Iterators.concat(subscriberIterators.iterator());
}
示例10: iterator
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Iterator<Binding<?>> iterator() {
return Iterators.transform(lookups.entrySet().iterator(), new Function<Entry<Class<?>, Resolver>, Binding<?>>(){
@Override
public Binding apply(Entry<Class<?>, Resolver> input) {
switch(input.getValue().getType()){
case INSTANCE:
return new InstanceBinding(input.getKey(), ((InjectableReference)input.getValue()).clazz);
case SINGLETON:
return new SingletonBinding(input.getKey(), input.getValue().get(null));
default:
throw new IllegalStateException();
}
}});
}
示例11: testGetSubscribers
import com.google.common.collect.Iterators; //导入依赖的package包/类
public void testGetSubscribers() {
assertEquals(0, Iterators.size(registry.getSubscribers("")));
registry.register(new StringSubscriber());
assertEquals(1, Iterators.size(registry.getSubscribers("")));
registry.register(new StringSubscriber());
assertEquals(2, Iterators.size(registry.getSubscribers("")));
registry.register(new ObjectSubscriber());
assertEquals(3, Iterators.size(registry.getSubscribers("")));
assertEquals(1, Iterators.size(registry.getSubscribers(new Object())));
assertEquals(1, Iterators.size(registry.getSubscribers(1)));
registry.register(new IntegerSubscriber());
assertEquals(3, Iterators.size(registry.getSubscribers("")));
assertEquals(1, Iterators.size(registry.getSubscribers(new Object())));
assertEquals(2, Iterators.size(registry.getSubscribers(1)));
}
示例12: lookupNames
import com.google.common.collect.Iterators; //导入依赖的package包/类
private static void lookupNames(MinecraftServer server, Collection<String> names, ProfileLookupCallback callback)
{
String[] astring = (String[])Iterators.toArray(Iterators.filter(names.iterator(), new Predicate<String>()
{
public boolean apply(@Nullable String p_apply_1_)
{
return !StringUtils.isNullOrEmpty(p_apply_1_);
}
}), String.class);
if (server.isServerInOnlineMode())
{
server.getGameProfileRepository().findProfilesByNames(astring, Agent.MINECRAFT, callback);
}
else
{
for (String s : astring)
{
UUID uuid = EntityPlayer.getUUID(new GameProfile((UUID)null, s));
GameProfile gameprofile = new GameProfile(uuid, s);
callback.onProfileLookupSucceeded(gameprofile);
}
}
}
示例13: OptionIterator
import com.google.common.collect.Iterators; //导入依赖的package包/类
public OptionIterator(FragmentContext context, Mode mode){
final DrillConfigIterator configOptions = new DrillConfigIterator(context.getConfig());
fragmentOptions = context.getOptions();
final Iterator<OptionValue> optionList;
switch(mode){
case BOOT:
optionList = configOptions.iterator();
break;
case SYS_SESS:
optionList = fragmentOptions.iterator();
break;
default:
optionList = Iterators.concat(configOptions.iterator(), fragmentOptions.iterator());
}
List<OptionValue> values = Lists.newArrayList(optionList);
Collections.sort(values);
mergedOptions = values.iterator();
}
示例14: transform
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
AbstractInsnNode[] match = Iterators.getOnlyElement(matcher.match("BIPUSH ISTORE", m -> {
IntInsnNode push = (IntInsnNode) m[0];
if (push.operand != 50) {
return false;
}
VarInsnNode store = (VarInsnNode) m[1];
LocalVariableNode node = AsmUtils.getLocalVariable(method, store.var, store);
return node != null && node.name.equals("resource") && node.desc.equals("I");
}));
method.instructions.remove(match[0]);
method.instructions.remove(match[1]);
}
示例15: next
import com.google.common.collect.Iterators; //导入依赖的package包/类
@Override
public Directory next() throws NoSuchElementException {
Iterator<Digest> iter = pointers.peek();
if (!iter.hasNext()) {
throw new NoSuchElementException();
}
/* we can have null directories in our list
* if members of the tree have been removed from
* the cas. we return this to retain the information
* (and simplify the interface) that they have been
* removed. */
Digest digest = iter.next();
Directory directory = expectDirectory(instance.getBlob(digest));
if (directory != null) {
/* the path to a new iter set is the path to its parent */
parentPath.addLast(digest);
path = parentPath.clone();
pointers.push(Iterators.transform(
directory.getDirectoriesList().iterator(),
directoryNode -> directoryNode.getDigest()));
}
advanceIterator();
return directory;
}