com.google.common.collect.Iterators#addAll ( )源码实例Demo

下面列出了com.google.common.collect.Iterators#addAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: java-n-IDE-for-Android   文件: Formatter.java
/**
 * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges.
 */
public static RangeSet<Integer> lineRangesToCharRanges(
        String input, RangeSet<Integer> lineRanges) {
    List<Integer> lines = new ArrayList<>();
    Iterators.addAll(lines, Newlines.lineOffsetIterator(input));
    lines.add(input.length() + 1);

    final RangeSet<Integer> characterRanges = TreeRangeSet.create();
    for (Range<Integer> lineRange :
            lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) {
        int lineStart = lines.get(lineRange.lowerEndpoint());
        // Exclude the trailing newline. This isn't strictly necessary, but handling blank lines
        // as empty ranges is convenient.
        int lineEnd = lines.get(lineRange.upperEndpoint()) - 1;
        Range<Integer> range = Range.closedOpen(lineStart, lineEnd);
        characterRanges.add(range);
    }
    return characterRanges;
}
 
源代码2 项目: n4js   文件: N4JSMemberRedefinitionValidator.java
/**
 * Constraints 41 (Abstract Class)
 */
private boolean constraints_41_AbstractClass(TClassifier classifier, MemberCube memberCube) {
	List<TMember> abstractMembers = null;
	if (!classifier.isAbstract() && classifier instanceof TClass) {
		for (Entry<NameStaticPair, MemberMatrix> entry : memberCube.entrySet()) {
			MemberMatrix mm = entry.getValue();
			MemberList<TMember> l = new MemberList<>();
			Iterators.addAll(l, mm.actuallyInheritedAndMixedMembers());
			for (SourceAwareIterator iter = mm.actuallyInheritedAndMixedMembers(); iter.hasNext();) {
				TMember m = iter.next();
				if (m.isAbstract()) {
					if (abstractMembers == null) {
						abstractMembers = new ArrayList<>();
					}
					abstractMembers.add(m);
				}
			}
		}
	}
	if (abstractMembers != null) {
		messageMissingImplementations(abstractMembers);
		return false;
	}
	return true;
}
 
@Test
public void testJSONSerializationWithSnakeCaseMembers() throws Exception {
    CleanupContext context = new CleanupContext(
            Arrays.asList("node1"), Arrays.asList("keyspace1"), Arrays.asList("column_family1"));
    ObjectMapper om = new ObjectMapper();

    JsonSerializer serializer = new JsonSerializer();
    String jsonContext = new String(serializer.serialize(context), StandardCharsets.UTF_8);

    JsonNode rehydratedContext = om.readTree(jsonContext);
    List<String> keys = new ArrayList<>();
    Iterators.addAll(keys, rehydratedContext.getFieldNames());
    keys.sort(String::compareTo);

    Assert.assertEquals(Arrays.asList("column_families", "key_spaces", "nodes"), keys);

    context = serializer.deserialize(jsonContext.getBytes(StandardCharsets.UTF_8), CleanupContext.class);
    Assert.assertEquals(Arrays.asList("column_family1"), context.getColumnFamilies());
    Assert.assertEquals(Arrays.asList("keyspace1"), context.getKeySpaces());
    Assert.assertEquals(Arrays.asList("node1"), context.getNodes());
}
 
源代码4 项目: google-java-format   文件: Formatter.java
/**
 * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges.
 */
public static RangeSet<Integer> lineRangesToCharRanges(
    String input, RangeSet<Integer> lineRanges) {
  List<Integer> lines = new ArrayList<>();
  Iterators.addAll(lines, Newlines.lineOffsetIterator(input));
  lines.add(input.length() + 1);

  final RangeSet<Integer> characterRanges = TreeRangeSet.create();
  for (Range<Integer> lineRange :
      lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) {
    int lineStart = lines.get(lineRange.lowerEndpoint());
    // Exclude the trailing newline. This isn't strictly necessary, but handling blank lines
    // as empty ranges is convenient.
    int lineEnd = lines.get(lineRange.upperEndpoint()) - 1;
    Range<Integer> range = Range.closedOpen(lineStart, lineEnd);
    characterRanges.add(range);
  }
  return characterRanges;
}
 
源代码5 项目: emodb   文件: DefaultDedupEventStore.java
@Override
public Iterator<String> listChannels() {
    // The implementation of this is unfortunate in that, because the underlying methods return channel
    // and queue names in random order, the only way to dedup names between the 3 underlying data structures
    // is to read all the channels into memory.  Hopefully there aren't so many that this causes problems,
    // but this is why the list channels method shouldn't be exposed as a public supported API, just an
    // internal feature that can be re-implemented or reconceived if necessary.
    Set<String> queues = Sets.newHashSet();

    // Enumerate the persistent sorted queues
    Iterators.addAll(queues, _queueDAO.listQueues());

    // Enumerate the read & write channels.
    Iterator<String> channelIter = _delegate.listChannels();
    while (channelIter.hasNext()) {
        String channel = channelIter.next();
        String queue;
        if ((queue = _channels.queueFromReadChannel(channel)) != null) {
            queues.add(queue);
        } else if ((queue = _channels.queueFromWriteChannel(channel)) != null) {
            queues.add(queue);
        }
    }

    return queues.iterator();  // Unordered to be consistent with non-dedup'd event store
}
 
@Test
public void callbackCount() {
    BulkImportStoredProcedureOptions options = null;
    String bulkImportSproc = null;
    DocumentClient client = Mockito.mock(DocumentClient.class);
    List<List<String>> batchesToInsert = new ArrayList<>();
    batchesToInsert.add(new ArrayList<>());
    batchesToInsert.add(new ArrayList<>());
    batchesToInsert.add(new ArrayList<>());

    String partitionIndex = "0";
    BatchInserter bi = new BatchInserter(partitionIndex, batchesToInsert, client, bulkImportSproc, options);

    Iterator<Callable<InsertMetrics>> callbackIterator = bi.miniBatchInsertExecutionCallableIterator();

    List<Callable<InsertMetrics>> list = new ArrayList<>();
    Iterators.addAll(list, callbackIterator);

    assertThat(list.size(), equalTo(3));
}
 
源代码7 项目: sasi   文件: TokenTree.java
@Override
public void merge(CombinedValue<Long> other)
{
    if (!(other instanceof Token))
        return;

    Token o = (Token) other;
    if (token != o.token)
        throw new IllegalArgumentException(String.format("%s != %s", token, o.token));

    if (o instanceof OnDiskToken)
    {
        info.addAll(((OnDiskToken) other).info);
    }
    else
    {
        Iterators.addAll(loadedKeys, o.iterator());
    }
}
 
源代码8 项目: titan1withtp3.1   文件: EntryArrayList.java
public static EntryArrayList of(Iterable<? extends Entry> i) {
    // This is adapted from Guava's Lists.newArrayList implementation
    EntryArrayList result;
    if (i instanceof Collection) {
        // Let ArrayList's sizing logic work, if possible
        result = new EntryArrayList((Collection)i);
    } else {
        // Unknown size
        result = new EntryArrayList();
        Iterators.addAll(result, i.iterator());
    }
    return result;
}
 
源代码9 项目: picard   文件: WidthLimitingDecoratorTest.java
@Test
public void testForVcf() throws Exception {

    final Segment entireThing = new Segment(1, 9942);
    final ImmutableList<Segment> expectedSubThings = ImmutableList.of(
            new Segment(1, 1000),
            new Segment(1001, 2000),
            new Segment(2001, 3000),
            new Segment(3001, 4000),
            new Segment(4001, 5000),
            new Segment(5001, 6000),
            new Segment(6001, 7000),
            new Segment(7001, 8000),
            new Segment(8001, 9000),
            new Segment(9001, 9942)
    );

    final VcfFileSegmentGenerator.WidthLimitingDecorator strategy = VcfFileSegmentGenerator.WidthLimitingDecorator.wrapping(new VcfFileSegmentGenerator() {
        @Override
        public Iterable<VcfFileSegment> forVcf(final File vcf) {
            return Collections.singleton((VcfFileSegment) entireThing);
        }
    }, 1000);

    final List<VcfFileSegment> observed = new ArrayList<VcfFileSegment>();
    Iterators.addAll(observed, strategy.forVcf(new File("B")).iterator());
    final Iterator<VcfFileSegment> observedIterator = observed.iterator();
    for (final VcfFileSegment e : expectedSubThings) {
        Assert.assertTrue(observedIterator.hasNext());
        final VcfFileSegment o = observedIterator.next();
        Assert.assertEquals(ComparisonChain.start()
                .compare(o.contig(), e.contig())
                .compare(o.start(), e.start())
                .compare(o.stop(), e.stop())
                .compare(o.vcf(), e.vcf())
                .result(), 0, String.format(String.format("observed=%[email protected]%s:%s-%s  expected=%s", o.vcf(), o.contig(), o.start(), 
                o.stop(), e.toString())));
    }
}
 
源代码10 项目: xtext-extras   文件: PackratParserGenUtil.java
private static List<String> getConflictingKeywordsImpl(final Grammar grammar, TerminalRule rule) {
	final Iterator<Keyword> conflictingKeywords = getConflictingKeywords(rule,
			Iterators.filter(EcoreUtil.getAllContents(grammar, true), Keyword.class));
	Set<String> res = Sets.newLinkedHashSet();
	Iterators.addAll(res, Iterators.transform(conflictingKeywords, new Function<Keyword, String>() {
		@Override
		public String apply(Keyword param) {
			return param.getValue();
		}
	}));
	return Lists.newArrayList(res);
}
 
源代码11 项目: log-synth   文件: FlattenSamplerTest.java
@Test
public void testEmptyPrefix() throws IOException {
    SchemaSampler s = new SchemaSampler(Resources.asCharSource(Resources.getResource("schema023.json"), Charsets.UTF_8).read());
    JsonNode v = s.sample();
    Set<String> names = Sets.newTreeSet();
    Iterators.addAll(names, v.fieldNames());
    assertEquals("[city, decommisioned, estimatedPopulation, latitude, location, locationType, longitude, state, " +
            "taxReturnsFiled, totalWages, zip, zipType]", names.toString());
}
 
源代码12 项目: stratio-cassandra   文件: TokenMetadataTest.java
private void testRingIterator(ArrayList<Token> ring, String start, boolean includeMin, String... expected)
{
    ArrayList<Token> actual = new ArrayList<Token>();
    Iterators.addAll(actual, TokenMetadata.ringIterator(ring, token(start), includeMin));
    assertEquals(actual.toString(), expected.length, actual.size());
    for (int i = 0; i < expected.length; i++)
        assertEquals("Mismatch at index " + i + ": " + actual, token(expected[i]), actual.get(i));
}
 
源代码13 项目: presto   文件: TestHashJoinOperator.java
@Override
public SingleStreamSpiller create(List<Type> types, SpillContext spillContext, LocalMemoryContext memoryContext)
{
    return new SingleStreamSpiller()
    {
        private boolean writing = true;
        private final List<Page> spills = new ArrayList<>();

        @Override
        public ListenableFuture<?> spill(Iterator<Page> pageIterator)
        {
            checkState(writing, "writing already finished");
            if (failSpill) {
                return immediateFailedFuture(new PrestoException(GENERIC_INTERNAL_ERROR, "Spill failed"));
            }
            Iterators.addAll(spills, pageIterator);
            return immediateFuture(null);
        }

        @Override
        public Iterator<Page> getSpilledPages()
        {
            if (failUnspill) {
                throw new PrestoException(GENERIC_INTERNAL_ERROR, "Unspill failed");
            }
            writing = false;
            return unmodifiableIterator(spills.iterator());
        }

        @Override
        public long getSpilledPagesInMemorySize()
        {
            return spills.stream()
                    .mapToLong(Page::getSizeInBytes)
                    .sum();
        }

        @Override
        public ListenableFuture<List<Page>> getAllSpilledPages()
        {
            if (failUnspill) {
                return immediateFailedFuture(new PrestoException(GENERIC_INTERNAL_ERROR, "Unspill failed"));
            }
            writing = false;
            return immediateFuture(ImmutableList.copyOf(spills));
        }

        @Override
        public void close()
        {
            writing = false;
        }
    };
}
 
源代码14 项目: codebuff   文件: LocalCache.java
private static <E> ArrayList<E> toArrayList(Collection<E> c) {
  // Avoid calling ArrayList(Collection), which may call back into toArray.
  ArrayList<E> result = new ArrayList<E>(c.size());
  Iterators.addAll(result, c.iterator());
  return result;
}
 
源代码15 项目: bazel   文件: OptionsParserImpl.java
/**
 * Parses the args, and returns what it doesn't parse. May be called multiple times, and may be
 * called recursively. Calls may contain intersecting sets of options; in that case, the arg seen
 * last takes precedence.
 *
 * <p>The method treats options that have neither an implicitDependent nor an expandedFrom value
 * as explicitly set.
 */
private ResidueAndPriority parse(
    OptionPriority priority,
    Function<OptionDefinition, String> sourceFunction,
    ParsedOptionDescription implicitDependent,
    ParsedOptionDescription expandedFrom,
    List<String> args)
    throws OptionsParsingException {
  List<String> unparsedArgs = new ArrayList<>();
  List<String> unparsedPostDoubleDashArgs = new ArrayList<>();

  Iterator<String> argsIterator = argsPreProcessor.preProcess(args).iterator();
  while (argsIterator.hasNext()) {
    String arg = argsIterator.next();

    if (!arg.startsWith("-")) {
      unparsedArgs.add(arg);
      continue; // not an option arg
    }

    if (skippedPrefixes.stream().anyMatch(prefix -> arg.startsWith(prefix))) {
      unparsedArgs.add(arg);
      continue;
    }

    if (arg.equals("--")) { // "--" means all remaining args aren't options
      Iterators.addAll(unparsedPostDoubleDashArgs, argsIterator);
      break;
    }

    ParsedOptionDescription parsedOption =
        identifyOptionAndPossibleArgument(
            arg, argsIterator, priority, sourceFunction, implicitDependent, expandedFrom);
    handleNewParsedOption(parsedOption);
    priority = OptionPriority.nextOptionPriority(priority);
  }

  // Go through the final values and make sure they are valid values for their option. Unlike any
  // checks that happened above, this also checks that flags that were not set have a valid
  // default value. getValue() will throw if the value is invalid.
  for (OptionValueDescription valueDescription : asListOfEffectiveOptions()) {
    valueDescription.getValue();
  }

  return new ResidueAndPriority(unparsedArgs, unparsedPostDoubleDashArgs, priority);
}
 
源代码16 项目: stratio-cassandra   文件: Selection.java
public static Selection wildcard(CFMetaData cfm)
{
    List<ColumnDefinition> all = new ArrayList<ColumnDefinition>(cfm.allColumns().size());
    Iterators.addAll(all, cfm.allColumnsInSelectOrder());
    return new SimpleSelection(all, true);
}
 
源代码17 项目: dremio-oss   文件: OptionList.java
public OptionList getNonSystemOptions() {
  final OptionList options = new OptionList();
  Iterators.addAll(options, Iterators.filter(iterator(), Predicates.not(IS_SYSTEM_OPTION)));
  return options;
}
 
源代码18 项目: Hadoop-BAM   文件: TestVCFRoundTrip.java
@Test
public void testRoundTrip() throws Exception {
    Path vcfPath = new Path("file://" + testVCFFileName);

    // run a MR job to write out a VCF file
    Path outputPath = doMapReduce(vcfPath, true);

    // verify the output is the same as the input
    List<VariantContext> expectedVariants = new ArrayList<>();
    VCFFileReader vcfFileReader = parseVcf(new File(testVCFFileName));
    Iterators.addAll(expectedVariants, vcfFileReader.iterator());

    int splits = 0;
    List<VariantContext> actualVariants = new ArrayList<>();
    File[] vcfFiles = new File(outputPath.toUri()).listFiles(
        pathname -> (!pathname.getName().startsWith(".") &&
            !pathname.getName().startsWith("_")));
    Arrays.sort(vcfFiles); // ensure files are sorted by name
    for (File vcf : vcfFiles) {
        splits++;
        Iterators.addAll(actualVariants, parseVcf(vcf).iterator());
        if (BGZFCodec.class.equals(codecClass)) {
            assertTrue(BlockCompressedInputStream.isValidFile(
                new BufferedInputStream(new FileInputStream(vcf))));
        } else if (BGZFEnhancedGzipCodec.class.equals(codecClass)) {
            assertTrue(VCFFormat.isGzip(
                new BufferedInputStream(new FileInputStream(vcf))));
        }
    }

    switch (expectedSplits) {
        case EXACTLY_ONE:
            assertEquals("Should be exactly one split", 1, splits);
            break;
        case MORE_THAN_ONE:
            assertTrue("Should be more than one split", splits > 1);
            break;
        case ANY:
        default:
            break;
    }

    // use a VariantContextComparator to check variants are equal
    VCFHeader vcfHeader = VCFHeaderReader.readHeaderFrom(new SeekableFileStream(new
        File(testVCFFileName)));
    VariantContextComparator vcfRecordComparator = vcfHeader.getVCFRecordComparator();
    assertEquals(expectedVariants.size(), actualVariants.size());
    for (int i = 0; i < expectedVariants.size(); i++) {
        assertEquals(0, vcfRecordComparator.compare(expectedVariants.get(i),
            actualVariants.get(i)));
    }
}
 
源代码19 项目: codebuff   文件: LocalCache.java
private static <E> ArrayList<E> toArrayList(Collection<E> c) {
  // Avoid calling ArrayList(Collection), which may call back into toArray.
  ArrayList<E> result = new ArrayList<E>(c.size());
  Iterators.addAll(result, c.iterator());
  return result;
}
 
源代码20 项目: Bats   文件: ImmutableNullableList.java
/**
 * Adds each element of {@code elements} to the
 * {@code ImmutableNullableList}.
 *
 * @param elements the elements to add to the {@code ImmutableNullableList}
 * @return this {@code Builder} object
 * @throws NullPointerException if {@code elements} is null
 */
public Builder<E> addAll(Iterator<? extends E> elements) {
  Iterators.addAll(contents, elements);
  return this;
}