Java 类com.google.common.collect.Iterators 实例源码

项目:andbg    文件:ReflectionClassDef.java   
@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;
        }
    };
}
项目:QDrill    文件:ExternalSortBatch.java   
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());
}
项目:Reer    文件:DefaultTaskOutputs.java   
@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;
}
项目:Reer    文件:HashClassPathSnapshotter.java   
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
    }
}
项目:n4js    文件:ExceptionAnalyser.java   
@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;
}
项目:tableschema-java    文件:CsvDataSource.java   
@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;
}
项目:BaseClient    文件:PlayerProfileCache.java   
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;
}
项目:libtrails    文件:SkinDownloader.java   
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");
    }
}
项目:guava-mock    文件:SubscriberRegistry.java   
/**
 * 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());
}
项目:dremio-oss    文件:BinderImpl.java   
@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();
      }

    }});
}
项目:googles-monorepo-demo    文件:SubscriberRegistryTest.java   
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)));
}
项目:Backmemed    文件:PreYggdrasilConverter.java   
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);
        }
    }
}
项目:QDrill    文件:OptionIterator.java   
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();

}
项目:BaseClient    文件:PlayerProfileCache.java   
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;
}
项目:DecompiledMinecraft    文件:PlayerProfileCache.java   
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;
}
项目:anvil    文件:VeinCapTransformer.java   
@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]);
}
项目:bazel-buildfarm    文件:TreeIterator.java   
@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;
}
项目:andbg    文件:ClassDefRewriter.java   
@Nonnull
@Override
public Iterable<? extends Method> getMethods() {
    return new Iterable<Method>() {
        @Nonnull
        @Override
        public Iterator<Method> iterator() {
            return Iterators.concat(getDirectMethods().iterator(), getVirtualMethods().iterator());
        }
    };
}
项目:googles-monorepo-demo    文件:MutableTypeToInstanceMap.java   
private static <K, V> Iterator<Entry<K, V>> transformEntries(Iterator<Entry<K, V>> entries) {
  return Iterators.transform(
      entries,
      new Function<Entry<K, V>, Entry<K, V>>() {
        @Override
        public Entry<K, V> apply(Entry<K, V> entry) {
          return new UnmodifiableEntry<K, V>(entry);
        }
      });
}
项目:sstable-adaptor    文件:BTreeRow.java   
private CellInLegacyOrderIterator(CFMetaData metadata, boolean reversed)
{
    AbstractType<?> nameComparator = metadata.getColumnDefinitionNameComparator(isStatic() ? ColumnDefinition.Kind.STATIC : ColumnDefinition.Kind.REGULAR);
    this.comparator = reversed ? Collections.reverseOrder(nameComparator) : nameComparator;
    this.reversed = reversed;

    // copy btree into array for simple separate iteration of simple and complex columns
    this.data = new Object[BTree.size(btree)];
    BTree.toArray(btree, data, 0);

    int idx = Iterators.indexOf(Iterators.forArray(data), cd -> cd instanceof ComplexColumnData);
    this.firstComplexIdx = idx < 0 ? data.length : idx;
    this.complexIdx = firstComplexIdx;
}
项目:Reer    文件:NodeBackedModelMap.java   
@Override
public Iterator<T> iterator() {
    viewState.assertCanReadChildren();
    return Iterators.transform(keySet().iterator(), new Function<String, T>() {
        @Override
        public T apply(@Nullable String name) {
            return get(name);
        }
    });
}
项目:googles-monorepo-demo    文件:TestUtil.java   
/**
 * In some cases our graph implementations return custom sets that define their own size() and
 * contains(). Verify that these sets are consistent with the elements of their iterator.
 */
@CanIgnoreReturnValue
static <T> Set<T> sanityCheckSet(Set<T> set) {
  assertThat(set).hasSize(Iterators.size(set.iterator()));
  for (Object element : set) {
    assertThat(set).contains(element);
  }
  assertThat(set).doesNotContain(new Object());
  assertThat(set).isEqualTo(ImmutableSet.copyOf(set));
  return set;
}
项目:Reer    文件:DiscoveredInputsTaskStateChanges.java   
@Override
public Iterator<TaskStateChange> iterator() {
    if (getPrevious() == null) {
        return Iterators.<TaskStateChange>singletonIterator(new DescriptiveChange("Discovered input file history is not available."));
    }
    return getCurrent().iterateContentChangesSince(getPrevious(), "discovered input");
}
项目:Reer    文件:CompositeDomainObjectSet.java   
@SuppressWarnings({"NullableProblems", "unchecked"})
@Override
public Iterator<T> iterator() {
    CompositeCollection store = getStore();
    if (store.isEmpty()) {
        return Iterators.emptyIterator();
    }
    return new SetIterator();
}
项目:andbg    文件:ClassDefRewriter.java   
@Nonnull
@Override
public Iterable<? extends Field> getFields() {
    return new Iterable<Field>() {
        @Nonnull
        @Override
        public Iterator<Field> iterator() {
            return Iterators.concat(getStaticFields().iterator(), getInstanceFields().iterator());
        }
    };
}
项目:HardVox    文件:HardVox.java   
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
    Iterator<CommandModule> modules = Iterators.forArray(
            new RegionCommands(),
            new OperationCommands(),
            new SessionCommands());
    modules.forEachRemaining(m -> m.addCommands(event::registerServerCommand));
}
项目:hadoop    文件:AbstractCounterGroup.java   
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<T> right = (CounterGroupBase<T>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
项目:HardVox    文件:VecArg.java   
@Override
public Iterator<String> getCompletions(ArgumentContext context) {
    String textSoFar = context.text;
    List<String> sections = COMMA_SPLITTER.splitToList(textSoFar);
    String lastSection = Iterables.getLast(sections);
    String prependText = String.join(",", sections.subList(0, sections.size() - 1));
    Iterator<String> integer = Iterators.transform(delegate.getCompletions(context.withText(lastSection)), prependText::concat);
    if (textSoFar.isEmpty() || textSoFar.endsWith(",") || textSoFar.codePoints().filter(cp -> cp == ',').count() >= (dimensions - 1)) {
        return integer;
    }
    return Iterators.concat(integer, Iterators.transform(COMMA.iterator(), textSoFar::concat));
}
项目:sonar-css-plugin    文件:UriContentTreeImpl.java   
@Override
public Iterator<Tree> childrenIterator() {
  if (string != null) {
    return Iterators.singletonIterator(string);
  } else {
    return Iterators.singletonIterator(ident);
  }
}
项目:r8    文件:ReadMainDexList.java   
private void run(String[] args) throws Exception {
  if (args.length < 1 || args.length > 3) {
    System.out.println("Usage: command [-k] <main_dex_list> [<proguard_map>]");
    System.exit(0);
  }

  Iterator<String> arguments = Iterators.forArray(args);
  Function<String, String> outputGenerator;
  String arg = arguments.next();
  if (arg.equals("-k")) {
    outputGenerator = this::toKeepRule;
    arg = arguments.next();
  } else {
    outputGenerator = this::toClassFilePath;
  }
  Path mainDexList = Paths.get(arg);

  final ClassNameMapper mapper =
      arguments.hasNext() ? ProguardMapReader.mapperFromFile(Paths.get(arguments.next())) : null;

  FileUtils.readTextFile(mainDexList)
      .stream()
      .map(this::stripDotClass)
      .map(name -> name.replace('/', '.'))
      .map(name -> deobfuscateClassName(name, mapper))
      .map(outputGenerator)
      .sorted()
      .collect(Collectors.toList())
      .forEach(System.out::println);
}
项目:spydra    文件:HistoryLogUtilsTest.java   
@Test
public void testFindHistoryFilePath() throws Exception {

  final Iterator<LocatedFileStatus> mockListing = Iterators.forArray(
      mockFileStatus("/foobar.jhist"),
      mockFileStatus("/barbaz.jhist"),
      mockFileStatus("/a.log"),
      mockFileStatus("/" + DUMMY_JHIST_NAME));

  Optional<String> jHistFile = HistoryLogUtils.findHistoryFilePath(mockListing,
      ApplicationId.newInstance(DUMMY_ID_TIMESTAMP, DUMMY_ID_SERIAL));

  assertTrue(jHistFile.isPresent());
  assertEquals("/" + DUMMY_JHIST_NAME, jHistFile.get());
}
项目:spydra    文件:HistoryLogUtilsTest.java   
@Test
public void testNoHistoryFound() throws Exception {

  final Iterator<LocatedFileStatus> mockListing = Iterators.forArray(
      mockFileStatus("/a.log"));

  Optional<String> jHistFile = HistoryLogUtils.findHistoryFilePath(mockListing,
      ApplicationId.newInstance(DUMMY_ID_TIMESTAMP, DUMMY_ID_SERIAL));

  assertFalse(jHistFile.isPresent());
}
项目:dremio-oss    文件:SystemOptionManager.java   
/**
 * @return all system options that have been set to a non-default value
 */
public OptionList getNonDefaultOptions() {
  Iterator<OptionValue> persistedOptions = Iterators.transform(this.options.getAll(), EXTRACT_OPTIONS);

  OptionList nonDefaultOptions = new OptionList();
  Iterators.addAll(nonDefaultOptions, persistedOptions);
  return nonDefaultOptions;
}
项目:sonar-css-plugin    文件:ScssAtRootParametersTreeImpl.java   
@Override
public Iterator<Tree> childrenIterator() {
  return Iterators.concat(
    Iterators.forArray(openParenthesis, parameter, colon),
    values.iterator(),
    Iterators.singletonIterator(closeParenthesis));
}
项目:sonar-css-plugin    文件:ScssMapTreeImpl.java   
@Override
public Iterator<Tree> childrenIterator() {
  return Iterators.concat(
    Iterators.singletonIterator(openParenthesis),
    entries.elementsAndSeparators(Function.identity(), Function.identity()),
    Iterators.singletonIterator(closeParenthesis));
}
项目:javaide    文件:JavaInput.java   
private static int updateColumn(int columnI, String originalTokText) {
    Integer last = Iterators.getLast(Newlines.lineOffsetIterator(originalTokText));
    if (last > 0) {
        columnI = originalTokText.length() - last;
    } else {
        columnI += originalTokText.length();
    }
    return columnI;
}
项目:multidexlib2    文件:DexIO.java   
static void writeMultiDexDirectorySingleThread(boolean multiDex, File directory, DexFileNameIterator nameIterator,
        DexFile dexFile, int minMainDexClassCount, boolean minimalMainDex, int maxDexPoolSize, DexIO.Logger logger)
        throws IOException {
    Set<? extends ClassDef> classes = dexFile.getClasses();
    if (!multiDex) {
        minMainDexClassCount = classes.size();
        minimalMainDex = false;
    }
    Object lock = new Object();
    synchronized (lock) {       // avoid multiple synchronizations in single-threaded mode
        writeMultiDexDirectoryCommon(directory, nameIterator, Iterators.peekingIterator(classes.iterator()),
                minMainDexClassCount, minimalMainDex, dexFile.getOpcodes(), maxDexPoolSize, logger, lock);
    }
}
项目:dremio-oss    文件:EasyGroupScanUtils.java   
public Iterable<CompleteFileWork> getWorkIterable() {
  return new Iterable<CompleteFileWork>() {
    @Override
    public Iterator<CompleteFileWork> iterator() {
      return Iterators.unmodifiableIterator(chunks.iterator());
    }
  };
}
项目:Backmemed    文件:ClassInheritanceMultiMap.java   
public boolean contains(Object p_contains_1_)
{
    return Iterators.contains(this.getByClass(p_contains_1_.getClass()).iterator(), p_contains_1_);
}
项目:sstable-adaptor    文件:BTree.java   
public static boolean equals(Object[] a, Object[] b)
{
    return size(a) == size(b) && Iterators.elementsEqual(iterator(a), iterator(b));
}