Java Code Examples for com.google.common.collect.Iterables#concat()
The following examples show how to use
com.google.common.collect.Iterables#concat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoadingCacheTest.java From caffeine with Apache License 2.0 | 6 votes |
@CheckNoWriter @Test(dataProvider = "caches") @CacheSpec(loader = { Loader.NEGATIVE, Loader.BULK_NEGATIVE }, population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }, removalListener = { Listener.DEFAULT, Listener.REJECTING }) public void getAll_duplicates(LoadingCache<Integer, Integer> cache, CacheContext context) { Set<Integer> absentKeys = ImmutableSet.copyOf(Iterables.limit(context.absentKeys(), Ints.saturatedCast(context.maximum().max() - context.initialSize()))); Iterable<Integer> keys = Iterables.concat(absentKeys, absentKeys, context.original().keySet(), context.original().keySet()); Map<Integer, Integer> result = cache.getAll(keys); assertThat(context, hasMissCount(absentKeys.size())); assertThat(context, hasHitCount(context.initialSize())); assertThat(result.keySet(), is(equalTo(ImmutableSet.copyOf(keys)))); int loads = context.loader().isBulk() ? 1 : absentKeys.size(); assertThat(context, both(hasLoadSuccessCount(loads)).and(hasLoadFailureCount(0))); }
Example 2
Source File: CacheTest.java From caffeine with Apache License 2.0 | 6 votes |
@CheckNoWriter @Test(dataProvider = "caches") @CacheSpec(population = { Population.SINGLETON, Population.PARTIAL, Population.FULL }, removalListener = { Listener.DEFAULT, Listener.REJECTING }, implementation = Implementation.Guava) public void getAll_duplicates(Cache<Integer, Integer> cache, CacheContext context) { Set<Integer> absentKeys = ImmutableSet.copyOf(Iterables.limit(context.absentKeys(), Ints.saturatedCast(context.maximum().max() - context.initialSize()))); Iterable<Integer> keys = Iterables.concat(absentKeys, absentKeys, context.original().keySet(), context.original().keySet()); Map<Integer, Integer> result = cache.getAll(keys, bulkMappingFunction()); assertThat(context, hasMissCount(absentKeys.size())); assertThat(context, hasHitCount(context.initialSize())); assertThat(result.keySet(), is(equalTo(ImmutableSet.copyOf(keys)))); assertThat(context, both(hasLoadSuccessCount(1)).and(hasLoadFailureCount(0))); }
Example 3
Source File: PyCommon.java From bazel with Apache License 2.0 | 6 votes |
/** * Returns true if any of this target's {@code deps} or {@code data} deps has a shared library * file (e.g. a {@code .so}) in its transitive dependency closure. * * <p>For targets with the py provider, we consult the {@code uses_shared_libraries} field. For * targets without this provider, we look for {@link CppFileTypes#SHARED_LIBRARY}-type files in * the filesToBuild. */ private static boolean initUsesSharedLibraries(RuleContext ruleContext) { Iterable<? extends TransitiveInfoCollection> targets; // The deps attribute must exist for all rule types that use PyCommon, but not necessarily the // data attribute. if (ruleContext.attributes().has("data")) { targets = Iterables.concat( ruleContext.getPrerequisites("deps", TransitionMode.TARGET), ruleContext.getPrerequisites("data", TransitionMode.DONT_CHECK)); } else { targets = ruleContext.getPrerequisites("deps", TransitionMode.TARGET); } for (TransitiveInfoCollection target : targets) { try { if (PyProviderUtils.getUsesSharedLibraries(target)) { return true; } } catch (EvalException e) { ruleContext.ruleError(String.format("In dep '%s': %s", target.getLabel(), e.getMessage())); } } return false; }
Example 4
Source File: ManagementSystem.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Override public <T extends RelationType> Iterable<T> getRelationTypes(Class<T> clazz) { Preconditions.checkNotNull(clazz); Iterable<? extends TitanVertex> types = null; if (PropertyKey.class.equals(clazz)) { types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.PROPERTYKEY); } else if (EdgeLabel.class.equals(clazz)) { types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.EDGELABEL); } else if (RelationType.class.equals(clazz)) { types = Iterables.concat(getRelationTypes(EdgeLabel.class), getRelationTypes(PropertyKey.class)); } else throw new IllegalArgumentException("Unknown type class: " + clazz); return Iterables.filter(Iterables.filter(types, clazz), new Predicate<T>() { @Override public boolean apply(@Nullable T t) { //Filter out all relation type indexes return ((InternalRelationType) t).getBaseType() == null; } }); }
Example 5
Source File: BagFiltered.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object[][] unpack() { // Most of the filter logic is done in PACK. We could do some checking here, but for now we won't bother List<Object[]> tuples = Lists.newArrayList(); for (ByteString serialized : Iterables.concat(ACTIVE.get(bagId), ARCHIVE.get(bagId))) { try { Bag bag = Bag.parseFrom(serialized); if (bag.hasFilterBag()) { for (SimpleTuple tuple : bag.getFilterBag().getTupleList()) { tuples.add(tuple.getValueList().toArray()); } } } catch (InvalidProtocolBufferException e) { } } return tuples.toArray(new Object[tuples.size()][]); }
Example 6
Source File: DirtyStateManager.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<IEObjectDescription> getExportedObjects() { return Iterables.concat(Iterables.transform(managedResources.values(), new Function<IDirtyResource, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(IDirtyResource from) { if (from != null) return from.getDescription().getExportedObjects(); return Collections.emptyList(); } })); }
Example 7
Source File: PassThroughPagingIterator.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void merge(Iterable<? extends KeyIterable<TKey, TRow>> iterables) { Iterable<TRow> concat = Iterables.concat(iterables); if (repeatable) { this.iterables.addAll(iterables); this.storedForRepeat = null; } if (iterator.hasNext()) { iterator = Iterators.concat(iterator, concat.iterator()); } else { iterator = concat.iterator(); } }
Example 8
Source File: SplitStageExecutor.java From dremio-oss with Apache License 2.0 | 5 votes |
private void transferOut() { // transfer intermediate outputs to the ValueVectorReadExpression // for other splits to read the output for(ExpressionSplit split : Iterables.concat(javaSplits, gandivaSplits)) { split.transferOut(); } // transfer final output for(TransferPair tp : transferPairs) { tp.transfer(); } }
Example 9
Source File: AbstractContainerizingSandboxedSpawn.java From bazel with Apache License 2.0 | 5 votes |
/** * Moves all given outputs from a root to another. * * <p>This is a support function to help with the implementation of {@link #copyOutputs(Path)}. * * @param outputs outputs to move as relative paths to a root * @param sourceRoot source directory from which to resolve outputs * @param targetRoot target directory to which to move the resolved outputs from the source * @throws IOException if any of the moves fails */ static void moveOutputs(SandboxOutputs outputs, Path sourceRoot, Path targetRoot) throws IOException { for (PathFragment output : Iterables.concat(outputs.files(), outputs.dirs())) { Path source = sourceRoot.getRelative(output); Path target = targetRoot.getRelative(output); if (source.isFile() || source.isSymbolicLink()) { // Ensure the target directory exists in the target. The directories for the action outputs // have already been created, but the spawn outputs may be different from the overall action // outputs. This is the case for test actions. target.getParentDirectory().createDirectoryAndParents(); if (FileSystemUtils.moveFile(source, target).equals(MoveResult.FILE_COPIED)) { if (warnedAboutMovesBeingCopies.compareAndSet(false, true)) { logger.atWarning().log( "Moving files out of the sandbox (e.g. from %s to %s" + ") had to be done with a file copy, which is detrimental to performance; are " + " the two trees in different file systems?", source, target); } } } else if (source.isDirectory()) { try { source.renameTo(target); } catch (IOException e) { // Failed to move directory directly, thus move it recursively. target.createDirectory(); FileSystemUtils.moveTreesBelow(source, target); } } } }
Example 10
Source File: XtextValidator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private Iterable<GeneratedMetamodel> getAllGeneratedMetamodels(Grammar grammar, Set<Grammar> visited) { Iterable<GeneratedMetamodel> result = Iterables.filter(grammar.getMetamodelDeclarations(), GeneratedMetamodel.class); for (Grammar gr : grammar.getUsedGrammars()) { if (visited.add(gr)) result = Iterables.concat(result, getAllGeneratedMetamodels(gr, visited)); } return result; }
Example 11
Source File: SyntaxFilteredScope.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<IEObjectDescription> getAllElements() { return Iterables.concat(Iterables.transform(values, new Function<QualifiedName, Iterable<IEObjectDescription>>() { @Override public Iterable<IEObjectDescription> apply(QualifiedName input) { return parent.getElements(input); } })); }
Example 12
Source File: MemberMatrix.java From n4js with Eclipse Public License 1.0 | 5 votes |
private Iterable<TMember> members(int source) { return hasSource(source) ? Iterables.concat(members( source, GETTER), members(source, SETTER), members(source, FIELD), members(source, METHOD)) : MemberList.emptyList(); }
Example 13
Source File: TypeUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Convenience method, returns directly declared super types (class, role, interface) of a classifier. May return an * empty list but never null. Order is always super class, super roles, super interfaces. For all non-classifiers * this method returns an empty list. */ public static Iterable<? extends ParameterizedTypeRef> declaredSuperTypes(final Type type) { if (type instanceof TClass) { final TClass c = (TClass) type; if (c.getSuperClassRef() != null) { return Iterables.concat(singletonList(c.getSuperClassRef()), c.getImplementedInterfaceRefs()); } else { return c.getImplementedInterfaceRefs(); } } if (type instanceof TInterface) { final TInterface r = (TInterface) type; return r.getSuperInterfaceRefs(); } if (type instanceof PrimitiveType) { PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible(); if (assignmentCompatible != null) { ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef(); typeRef.setDeclaredType(assignmentCompatible); return singletonList(typeRef); } } if (type instanceof TObjectPrototype) { // IDE-1221 string based enums: traversing super types for object prototypes as well TObjectPrototype tObjectPrototype = (TObjectPrototype) type; if (tObjectPrototype.getSuperType() != null) { return singletonList(tObjectPrototype.getSuperType()); } } return Collections.emptyList(); }
Example 14
Source File: AndFunction.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public FunctionRender render(FunctionRenderer renderer, RexCall call) { List<Iterable<NullReference>> refs = new ArrayList<>(); List<String> operands = Lists.newArrayListWithCapacity(call.getOperands().size()); for (RexNode childCall : call.getOperands()) { FunctionRender r = childCall.accept(renderer.getVisitor()); operands.add(r.getScript()); refs.add(r.getNulls()); } return new FunctionRender("( " + Joiner.on(" " + elasticName + " ").join(operands) + " )", Iterables.concat(refs)); }
Example 15
Source File: DexBackedClassDef.java From HeyGirl with Apache License 2.0 | 4 votes |
@Nonnull @Override public Iterable<? extends DexBackedMethod> getMethods() { return Iterables.concat(getDirectMethods(), getVirtualMethods()); }
Example 16
Source File: DexWriter.java From AppTroy with Apache License 2.0 | 4 votes |
private void writeDebugAndCodeItems(@Nonnull DexDataWriter offsetWriter, @Nonnull DeferredOutputStream temp) throws IOException { ByteArrayOutputStream ehBuf = new ByteArrayOutputStream(); debugSectionOffset = offsetWriter.getPosition(); DebugWriter<StringKey, TypeKey> debugWriter = new DebugWriter<StringKey, TypeKey>(stringSection, typeSection, offsetWriter); DexDataWriter codeWriter = new DexDataWriter(temp, 0); List<CodeItemOffset<MethodKey>> codeOffsets = Lists.newArrayList(); for (ClassKey classKey: classSection.getSortedClasses()) { Collection<? extends MethodKey> directMethods = classSection.getSortedDirectMethods(classKey); Collection<? extends MethodKey> virtualMethods = classSection.getSortedVirtualMethods(classKey); Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods); for (MethodKey methodKey: methods) { List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = classSection.getTryBlocks(methodKey); Iterable<? extends Instruction> instructions = classSection.getInstructions(methodKey); Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey); if (instructions != null && stringSection.hasJumboIndexes()) { boolean needsFix = false; for (Instruction instruction: instructions) { if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { needsFix = true; break; } } } if (needsFix) { MutableMethodImplementation mutableMethodImplementation = classSection.makeMutableMethodImplementation(methodKey); fixInstructions(mutableMethodImplementation); instructions = mutableMethodImplementation.getInstructions(); tryBlocks = mutableMethodImplementation.getTryBlocks(); debugItems = mutableMethodImplementation.getDebugItems(); } } int debugItemOffset = writeDebugItem(offsetWriter, debugWriter, classSection.getParameterNames(methodKey), debugItems); int codeItemOffset = writeCodeItem(codeWriter, ehBuf, methodKey, tryBlocks, instructions, debugItemOffset); if (codeItemOffset != -1) { codeOffsets.add(new CodeItemOffset<MethodKey>(methodKey, codeItemOffset)); } } } offsetWriter.align(); codeSectionOffset = offsetWriter.getPosition(); codeWriter.close(); temp.writeTo(offsetWriter); temp.close(); for (CodeItemOffset<MethodKey> codeOffset: codeOffsets) { classSection.setCodeItemOffset(codeOffset.method, codeSectionOffset + codeOffset.codeOffset); } }
Example 17
Source File: BranchingScope.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
@Override public Iterable<IEObjectDescription> getAllElements() { return Iterables.concat(contents.getAllElements(), parent.getAllElements()); }
Example 18
Source File: Encodings.java From immutables with Apache License 2.0 | 4 votes |
Encoding(TypeElement type) { this.typeEncoding = type; if (type.getKind() != ElementKind.CLASS || type.getNestingKind() != NestingKind.TOP_LEVEL) { reporter.withElement(type).error("Encoding type '%s' should be top-level class", type.getSimpleName()); } this.$$package = processing().getElementUtils().getPackageOf(type).getQualifiedName().toString(); this.name = type.getSimpleName().toString(); CharSequence source = SourceExtraction.extract(processing(), type); if (source.length() == 0) { reporter.withElement(type) .error("No source code can be extracted for @Encoding class. Unsupported compilation mode"); } this.imports = SourceExtraction.importsFrom(source); this.sourceMapper = new SourceMapper(source); this.typesReader = new TypeExtractor(types, type); this.encodingSelfType = typesReader.get(type.asType()); addTypeParameters(type); for (Element e : type.getEnclosedElements()) { processMember(e); } if (postValidate()) { provideSyntheticElements(); } this.allElements = Iterables.concat( Arrays.asList( Iterables.filter( Arrays.asList( impl, from, toString, hashCode, equals, build, isInit), Predicates.notNull()), fields, expose, copy, helpers, builderFields, builderHelpers, builderInits)); this.linkage = new Linkage(); this.generatedImports = generatedImports(); }
Example 19
Source File: UnionGlob.java From copybara with Apache License 2.0 | 4 votes |
@Override protected Iterable<String> getIncludes() { return Iterables.concat(lval.getIncludes(), rval.getIncludes()); }
Example 20
Source File: ObjcCommon.java From bazel with Apache License 2.0 | 4 votes |
/** * Returns effective compilation options that do not arise from the crosstool. */ static Iterable<String> getNonCrosstoolCopts(RuleContext ruleContext) { return Iterables.concat( ruleContext.getFragment(ObjcConfiguration.class).getCopts(), ruleContext.getExpander().withDataLocations().tokenized("copts")); }