Java Code Examples for com.google.common.collect.ImmutableMap#forEach()
The following examples show how to use
com.google.common.collect.ImmutableMap#forEach() .
These examples are extracted from open source projects.
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 Project: zuihou-admin-boot File: DictionaryItemServiceImpl.java License: Apache License 2.0 | 6 votes |
@Override public Map<Serializable, Object> findDictionaryItem(Set<Serializable> codes) { if (codes.isEmpty()) { return Collections.emptyMap(); } // 1. 根据 字典编码查询可用的字典列表 LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ() .in(DictionaryItem::getCode, codes) .eq(DictionaryItem::getStatus, true) .orderByAsc(DictionaryItem::getSortValue); List<DictionaryItem> list = super.list(query); // 2. 将 list 转换成 Map,Map的key是字典编码,value是字典名称 ImmutableMap<String, String> typeMap = MapHelper.uniqueIndex(list, DictionaryItem::getCode, DictionaryItem::getName); // 3. 将 Map<String, String> 转换成 Map<Serializable, Object> Map<Serializable, Object> typeCodeNameMap = new LinkedHashMap<>(typeMap.size()); typeMap.forEach((key, value) -> typeCodeNameMap.put(key, value)); return typeCodeNameMap; }
Example 2
Source Project: zuihou-admin-cloud File: DictionaryItemServiceImpl.java License: Apache License 2.0 | 6 votes |
@Override public Map<Serializable, Object> findDictionaryItem(Set<Serializable> codes) { if (codes.isEmpty()) { return Collections.emptyMap(); } // 1. 根据 字典编码查询可用的字典列表 LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ() .in(DictionaryItem::getCode, codes) .eq(DictionaryItem::getStatus, true) .orderByAsc(DictionaryItem::getSortValue); List<DictionaryItem> list = super.list(query); // 2. 将 list 转换成 Map,Map的key是字典编码,value是字典名称 ImmutableMap<String, String> typeMap = MapHelper.uniqueIndex(list, DictionaryItem::getCode, DictionaryItem::getName); // 3. 将 Map<String, String> 转换成 Map<Serializable, Object> Map<Serializable, Object> typeCodeNameMap = new LinkedHashMap<>(typeMap.size()); typeMap.forEach((key, value) -> typeCodeNameMap.put(key, value)); return typeCodeNameMap; }
Example 3
Source Project: bundletool File: TargetingGenerator.java License: Apache License 2.0 | 6 votes |
/** * Generates APEX targeting based on the names of the APEX image files. * * @param apexImageFiles names of all files under apex/, including the "apex/" prefix. * @param hasBuildInfo if true then each APEX image file has a corresponding build info file. * @return Targeting for all APEX image files. */ public ApexImages generateTargetingForApexImages( Collection<ZipPath> apexImageFiles, boolean hasBuildInfo) { ImmutableMap<ZipPath, MultiAbi> targetingByPath = Maps.toMap(apexImageFiles, path -> buildMultiAbi(path.getFileName().toString())); ApexImages.Builder apexImages = ApexImages.newBuilder(); ImmutableSet<MultiAbi> allTargeting = ImmutableSet.copyOf(targetingByPath.values()); targetingByPath.forEach( (imagePath, targeting) -> apexImages.addImage( TargetedApexImage.newBuilder() .setPath(imagePath.toString()) .setBuildInfoPath( hasBuildInfo ? imagePath .toString() .replace( BundleModule.APEX_IMAGE_SUFFIX, BundleModule.BUILD_INFO_SUFFIX) : "") .setTargeting(buildApexTargetingWithAlternatives(targeting, allTargeting)))); return apexImages.build(); }
Example 4
Source Project: buck File: AppleBundle.java License: Apache License 2.0 | 6 votes |
/** * @param binariesMap A map from destination to source. Destination is deliberately used as a key * prevent multiple sources overwriting the same destination. */ private void copyBinariesIntoBundle( ImmutableList.Builder<Step> stepsBuilder, BuildContext context, ImmutableMap<Path, Path> binariesMap) { stepsBuilder.add( MkdirStep.of( BuildCellRelativePath.fromCellRelativePath( context.getBuildCellRootPath(), getProjectFilesystem(), bundleRoot.resolve(this.destinations.getExecutablesPath())))); binariesMap.forEach( (binaryBundlePath, binaryOutputPath) -> { stepsBuilder.add( CopyStep.forFile(getProjectFilesystem(), binaryOutputPath, binaryBundlePath)); }); }
Example 5
Source Project: nomulus File: ConsoleOteSetupAction.java License: Apache License 2.0 | 6 votes |
private void sendExternalUpdates(ImmutableMap<String, String> clientIdToTld) { if (!sendEmailUtils.hasRecipients()) { return; } String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); StringBuilder builder = new StringBuilder(); builder.append( String.format( "The following entities were created in %s by %s:\n", environment, registrarAccessor.userIdForLogging())); clientIdToTld.forEach( (clientId, tld) -> builder.append( String.format(" Registrar %s with access to TLD %s\n", clientId, tld))); builder.append(String.format("Gave user %s web access to these Registrars\n", email.get())); sendEmailUtils.sendEmail( String.format("OT&E for registrar %s created in %s", clientId.get(), environment), builder.toString()); }
Example 6
Source Project: nomulus File: SetupOteCommand.java License: Apache License 2.0 | 6 votes |
@Override protected String prompt() { ImmutableMap<String, String> registrarToTldMap = oteAccountBuilder.getClientIdToTldMap(); StringBuilder builder = new StringBuilder(); builder.append("Creating TLDs:"); registrarToTldMap.values().forEach(tld -> builder.append("\n ").append(tld)); builder.append("\nCreating registrars:"); registrarToTldMap.forEach( (clientId, tld) -> builder.append(String.format("\n %s (with access to %s)", clientId, tld))); builder.append("\nGiving contact access to these registrars:").append("\n ").append(email); if (RegistryEnvironment.get() != RegistryEnvironment.SANDBOX && RegistryEnvironment.get() != RegistryEnvironment.UNITTEST) { builder.append( String.format( "\n\nWARNING: Running against %s environment. Are " + "you sure you didn\'t mean to run this against sandbox (e.g. \"-e SANDBOX\")?", RegistryEnvironment.get())); } return builder.toString(); }
Example 7
Source Project: intellij File: ArtifactsDiff.java License: Apache License 2.0 | 6 votes |
public static ArtifactsDiff diffArtifacts( @Nullable ImmutableMap<String, ArtifactState> oldState, ImmutableMap<String, OutputArtifact> newArtifacts) throws InterruptedException, ExecutionException { ImmutableMap<String, ArtifactState> newState = computeState(newArtifacts.values()); // Find new/updated final ImmutableMap<String, ArtifactState> previous = oldState != null ? oldState : ImmutableMap.of(); ImmutableList<OutputArtifact> updated = newState.entrySet().stream() .filter( e -> { ArtifactState old = previous.get(e.getKey()); return old == null || old.isMoreRecent(e.getValue()); }) .map(e -> newArtifacts.get(e.getKey())) .collect(toImmutableList()); // Find removed Set<ArtifactState> removed = new HashSet<>(previous.values()); newState.forEach((k, v) -> removed.remove(v)); return new AutoValue_ArtifactsDiff(newState, updated, ImmutableSet.copyOf(removed)); }
Example 8
Source Project: auto File: SimplifyWithAnnotationsTest.java License: Apache License 2.0 | 6 votes |
void testTypeSpellings(TypeElement testClass) { ExecutableElement witness = ElementFilter.methodsIn(testClass.getEnclosedElements()) .stream() .filter(m -> m.getSimpleName().contentEquals("witness")) .collect(onlyElement()); if (witness.getReturnType().getAnnotationMirrors().isEmpty()) { System.err.println("SKIPPING TEST BECAUSE OF BUGGY COMPILER"); return; } ImmutableMap<String, TypeMirror> typeSpellingToType = typesFromTestClass(testClass); assertThat(typeSpellingToType).isNotEmpty(); StringBuilder text = new StringBuilder(); StringBuilder expected = new StringBuilder(); // Build up a fake source text with the encodings for the types in it, and decode it to // ensure the type spellings are what we expect. typeSpellingToType.forEach( (typeSpelling, type) -> { text.append("{").append(TypeEncoder.encodeWithAnnotations(type)).append("}"); expected.append("{").append(typeSpelling).append("}"); }); String decoded = TypeEncoder.decode(text.toString(), processingEnv, "pkg", null); assertThat(decoded).isEqualTo(expected.toString()); }
Example 9
Source Project: james-project File: EventDeadLettersContract.java License: Apache License 2.0 | 6 votes |
@Test default void storeShouldKeepConsistencyWhenConcurrentStore() throws Exception { EventDeadLetters eventDeadLetters = eventDeadLetters(); ImmutableMap<Integer, Group> groups = concurrentGroups(); Multimap<Integer, EventDeadLetters.InsertionId> storedInsertionIds = Multimaps.synchronizedSetMultimap(HashMultimap.create()); ConcurrentTestRunner.builder() .operation((threadNumber, step) -> { Event.EventId eventId = Event.EventId.random(); EventDeadLetters.InsertionId insertionId = eventDeadLetters.store(groups.get(threadNumber), event(eventId)).block(); storedInsertionIds.put(threadNumber, insertionId); }) .threadCount(THREAD_COUNT) .operationCount(OPERATION_COUNT) .runSuccessfullyWithin(RUN_SUCCESSFULLY_IN); groups.forEach((groupId, group) -> { Group storedGroup = groups.get(groupId); assertThat(eventDeadLetters.failedIds(storedGroup).collectList().block()) .hasSameElementsAs(storedInsertionIds.get(groupId)); }); }
Example 10
Source Project: bazel File: BytecodeTypeInferenceTest.java License: Apache License 2.0 | 6 votes |
@Test public void testInferType() { ImmutableMap<String, InferredType> map = ImmutableMap.<String, InferredType>builder() .put("Z", InferredType.BOOLEAN) .put("B", InferredType.BYTE) .put("I", InferredType.INT) .put("F", InferredType.FLOAT) .put("D", InferredType.DOUBLE) .put("J", InferredType.LONG) .put("TOP", InferredType.TOP) .put("NULL", InferredType.NULL) .put("UNINITIALIZED_THIS", InferredType.UNINITIALIZED_THIS) .build(); map.forEach( (descriptor, expected) -> { InferredType type = InferredType.create(descriptor); assertThat(type.descriptor()).isEqualTo(descriptor); assertThat(type).isSameInstanceAs(expected); }); }
Example 11
Source Project: buck File: ProjectWorkspace.java License: Apache License 2.0 | 5 votes |
/** * Add the correct environment variable to emulate executing buck wrapper from a working directory */ public static ImmutableMap<String, String> setAbsoluteClientWorkingDir( Path workingDir, ImmutableMap<String, String> existingEnv) { ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder(); envBuilder.put("BUCK_CLIENT_PWD", workingDir.toAbsolutePath().toString()); existingEnv.forEach( (k, v) -> { if (!k.equals("BUCK_CLIENT_PWD")) { envBuilder.put(k, v); } }); return envBuilder.build(); }
Example 12
Source Project: exonum-java-binding File: ApiController.java License: Apache License 2.0 | 5 votes |
void mountApi(Router router) { router.route().failureHandler(this::failureHandler); ImmutableMap<String, Handler<RoutingContext>> handlers = ImmutableMap.of( GET_WALLET_PATH, this::getWallet, GET_WALLET_HISTORY_PATH, this::getWalletHistory); handlers.forEach((path, handler) -> router.route(path).handler(handler) ); }
Example 13
Source Project: pravega File: ZkBucketStoreTest.java License: Apache License 2.0 | 5 votes |
@Override public BucketStore getBucketStore(ImmutableMap<BucketStore.ServiceType, Integer> map) { ZookeeperBucketStore store = new ZookeeperBucketStore(map, cli, executorService); map.forEach((service, bucketCount) -> { store.createBucketsRoot(service).join(); for (int bucket = 0; bucket < bucketCount; bucket++) { store.createBucket(service, bucket).join(); } }); return store; }
Example 14
Source Project: buck File: GenruleBuildable.java License: Apache License 2.0 | 5 votes |
private void addLinksForNamedSources( SourcePathResolverAdapter pathResolver, ProjectFilesystem filesystem, ImmutableMap<String, SourcePath> srcs, Map<Path, Path> links) { srcs.forEach( (name, src) -> { Path absolutePath = pathResolver.getAbsolutePath(src); RelPath target = filesystem.relativize(absolutePath); links.put(filesystem.getPath(name), target.getPath()); }); }
Example 15
Source Project: bazel File: BuildEventServiceModule.java License: Apache License 2.0 | 5 votes |
private static ImmutableMap<BuildEventTransport, ListenableFuture<Void>> constructCloseFuturesMapWithTimeouts( ImmutableMap<BuildEventTransport, ListenableFuture<Void>> bepTransportToCloseFuturesMap) { ImmutableMap.Builder<BuildEventTransport, ListenableFuture<Void>> builder = ImmutableMap.builder(); bepTransportToCloseFuturesMap.forEach( (bepTransport, closeFuture) -> { final ListenableFuture<Void> closeFutureWithTimeout; if (bepTransport.getTimeout().isZero() || bepTransport.getTimeout().isNegative()) { closeFutureWithTimeout = closeFuture; } else { final ScheduledExecutorService timeoutExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder() .setNameFormat("bes-close-" + bepTransport.name() + "-%d") .build()); // Make sure to avoid propagating the cancellation to the enclosing future since // we handle cancellation ourselves in this class. // Futures.withTimeout may cancel the enclosing future when the timeout is // reached. final ListenableFuture<Void> enclosingFuture = Futures.nonCancellationPropagating(closeFuture); closeFutureWithTimeout = Futures.withTimeout( enclosingFuture, bepTransport.getTimeout().toMillis(), TimeUnit.MILLISECONDS, timeoutExecutor); closeFutureWithTimeout.addListener( () -> timeoutExecutor.shutdown(), MoreExecutors.directExecutor()); } builder.put(bepTransport, closeFutureWithTimeout); }); return builder.build(); }
Example 16
Source Project: auto File: AutoValueOrOneOfProcessor.java License: Apache License 2.0 | 5 votes |
/** * Returns the ordered set of {@link Property} definitions for the given {@code @AutoValue} or * {@code AutoOneOf} type. * * @param annotatedPropertyMethods a map from property methods to the method annotations that * should go on the implementation of those methods. These annotations are method annotations * specifically. Type annotations do not appear because they are considered part of the return * type and will appear when that is spelled out. Annotations that are excluded by {@code * AutoValue.CopyAnnotations} also do not appear here. */ final ImmutableSet<Property> propertySet( ImmutableMap<ExecutableElement, TypeMirror> propertyMethodsAndTypes, ImmutableListMultimap<ExecutableElement, AnnotationMirror> annotatedPropertyFields, ImmutableListMultimap<ExecutableElement, AnnotationMirror> annotatedPropertyMethods) { ImmutableBiMap<ExecutableElement, String> methodToPropertyName = propertyNameToMethodMap(propertyMethodsAndTypes.keySet()).inverse(); Map<ExecutableElement, String> methodToIdentifier = new LinkedHashMap<>(methodToPropertyName); fixReservedIdentifiers(methodToIdentifier); ImmutableSet.Builder<Property> props = ImmutableSet.builder(); propertyMethodsAndTypes.forEach( (propertyMethod, returnType) -> { String propertyType = TypeEncoder.encodeWithAnnotations( returnType, getExcludedAnnotationTypes(propertyMethod)); String propertyName = methodToPropertyName.get(propertyMethod); String identifier = methodToIdentifier.get(propertyMethod); ImmutableList<String> fieldAnnotations = annotationStrings(annotatedPropertyFields.get(propertyMethod)); ImmutableList<AnnotationMirror> methodAnnotationMirrors = annotatedPropertyMethods.get(propertyMethod); ImmutableList<String> methodAnnotations = annotationStrings(methodAnnotationMirrors); Optional<String> nullableAnnotation = nullableAnnotationForMethod(propertyMethod); Property p = new Property( propertyName, identifier, propertyMethod, propertyType, fieldAnnotations, methodAnnotations, nullableAnnotation); props.add(p); if (p.isNullable() && returnType.getKind().isPrimitive()) { errorReporter().reportError(propertyMethod, "Primitive types cannot be @Nullable"); } }); return props.build(); }
Example 17
Source Project: onos File: GlobalPrefixesListCommand.java License: Apache License 2.0 | 4 votes |
private void printGlobalPrefixes(ImmutableMap<DeviceId, List<InterfaceIpAddress>> globalPrefixes) { globalPrefixes.forEach(((deviceId, interfaceIpAddresses) -> { print("%s", deviceId); interfaceIpAddresses.forEach(interfaceIpAddress -> print(" %s", interfaceIpAddress)); })); }
Example 18
Source Project: james-project File: QuotaMailingListenerConfiguration.java License: Apache License 2.0 | 4 votes |
public Builder addThresholds(ImmutableMap<QuotaThreshold, RenderingInformation> quotaThresholds) { quotaThresholds.forEach(this::addThreshold); return this; }
Example 19
Source Project: GitToolBox File: BehindTracker.java License: Apache License 2.0 | 4 votes |
private synchronized Map<GitRepository, BehindStatus> mapStateAsStatuses( @NotNull ImmutableMap<GitRepository, PendingChange> changes) { Map<GitRepository, BehindStatus> statuses = new HashMap<>(); changes.forEach((repo, change) -> statuses.put(repo, change.status)); return statuses; }
Example 20
Source Project: RDFUnit File: ShaclModel.java License: Apache License 2.0 | 4 votes |
/** * Collects all implicit targets as a set of ShapeGroup for the given list of shapes */ private Set<ShapeGroup> getImplicitShapeTargets(ImmutableMap<Shape, Set<ShapeTarget>> explicitTargets) { Set<ShapeGroup> groups = new HashSet<>(); explicitTargets.forEach( (shape, targets) -> groups.addAll(getImplicitTargetsForSingleShape(shape, targets))); return groups; }