@Override public Collection<DefaultInputModule> children(DefaultInputModule component) { return children.get(component); }
/** * Dispatches {@code jibEvent} to all the handlers that can handle it. * * @param jibEvent the {@link JibEvent} to dispatch */ @Override public void dispatch(JibEvent jibEvent) { handlers.get(JibEvent.class).forEach(handler -> handler.handle(jibEvent)); handlers.get(jibEvent.getClass()).forEach(handler -> handler.handle(jibEvent)); } }
/** * Posts provided event to all registered subscribers. Subscriber calls are invoked immediately and in order * in which subscribers were registered. * * @param event event to post */ public void post(@Nonnull final Object event) { for (final Subscriber subscriber : subscribers.get(event.getClass())) { try { subscriber.invoke(event); } catch (Exception e) { exceptionHandler.accept(e); } } }
public Set<ContentPack> loadAllLatest() { final Set<ContentPack> allContentPacks = loadAll(); final ImmutableMultimap.Builder<ModelId, ContentPack> byIdBuilder = ImmutableMultimap.builder(); for (ContentPack contentPack : allContentPacks) { byIdBuilder.put(contentPack.id(), contentPack); } final ImmutableMultimap<ModelId, ContentPack> contentPacksById = byIdBuilder.build(); final ImmutableSet.Builder<ContentPack> latestContentPacks = ImmutableSet.builderWithExpectedSize(contentPacksById.keySet().size()); for (ModelId id : contentPacksById.keySet()) { final ImmutableCollection<ContentPack> contentPacks = contentPacksById.get(id); final ContentPack latestContentPackRevision = Collections.max(contentPacks, Comparator.comparingInt(Revisioned::revision)); latestContentPacks.add(latestContentPackRevision); } return latestContentPacks.build(); }
public void testBuilder_withImmutableEntry() { ImmutableMultimap<String, Integer> multimap = new Builder<String, Integer>().put(Maps.immutableEntry("one", 1)).build(); assertEquals(Arrays.asList(1), multimap.get("one")); }
/** * Whether the given WakeLock may throw an unexpected RuntimeException when released. * * <p>Returns true if: 1) the given WakeLock was acquired with timeout, and 2) the given WakeLock * is reference counted. */ private boolean wakelockMayThrow(Symbol wakelockSymbol, VisitorState state) { ClassTree enclosingClass = getTopLevelClass(state); ImmutableMultimap<String, MethodInvocationTree> map = methodCallsForSymbol(wakelockSymbol, enclosingClass); // Was acquired with timeout. return map.get("acquire").stream().anyMatch(m -> m.getArguments().size() == 1) // Is reference counted, i.e., referenceCounted not explicitly set to false. && map.get("setReferenceCounted").stream() .noneMatch( m -> Boolean.FALSE.equals(constValue(m.getArguments().get(0), Boolean.class))); }
@Override public Iterable<? extends Character> successors(Character node) { checkArgument( graphMap.containsKey(node) || graphMap.containsValue(node), "Node %s is not an element of this graph", node); return Ordering.natural().immutableSortedCopy(graphMap.get(node)); } };
public Collection<ConfigKeyPath> getImportedBy(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (this.fullImportedByMap != null) { return this.fullImportedByMap.get(configKey); } try { return this.ownImportedByMap.get(configKey, () -> this.fallback.getImportedBy(configKey, runtimeConfig)); } catch (UncheckedExecutionException exc) { if (exc.getCause() instanceof UnsupportedOperationException) { computeImportedByMap(runtimeConfig); return getImportedBy(configKey, runtimeConfig); } else { throw new RuntimeException(exc); } } catch (ExecutionException ee) { throw new RuntimeException(ee); } }
public void testBuilder_withMutableEntry() { ImmutableMultimap.Builder<String, Integer> builder = new Builder<>(); final StringHolder holder = new StringHolder(); holder.string = "one"; Entry<String, Integer> entry = new AbstractMapEntry<String, Integer>() { @Override public String getKey() { return holder.string; } @Override public Integer getValue() { return 1; } }; builder.put(entry); holder.string = "two"; assertEquals(Arrays.asList(1), builder.build().get("one")); }
assertEquals(functions.get("avg").asList().size(), 6); assertEquals(functions.get("avg").asList().get(0).getField(1), "decimal(p,s)"); assertEquals(functions.get("avg").asList().get(0).getField(2), "decimal(p,s)"); assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate"); assertEquals(functions.get("avg").asList().get(1).getField(1), "double"); assertEquals(functions.get("avg").asList().get(1).getField(2), "bigint"); assertEquals(functions.get("avg").asList().get(1).getField(3), "aggregate"); assertEquals(functions.get("avg").asList().get(2).getField(1), "double"); assertEquals(functions.get("avg").asList().get(2).getField(2), "double"); assertEquals(functions.get("avg").asList().get(2).getField(3), "aggregate"); assertEquals(functions.get("avg").asList().get(3).getField(1), "interval day to second"); assertEquals(functions.get("avg").asList().get(3).getField(2), "interval day to second"); assertEquals(functions.get("avg").asList().get(3).getField(3), "aggregate"); assertEquals(functions.get("avg").asList().get(4).getField(1), "interval year to month"); assertEquals(functions.get("avg").asList().get(4).getField(2), "interval year to month"); assertEquals(functions.get("avg").asList().get(4).getField(3), "aggregate"); assertEquals(functions.get("avg").asList().get(5).getField(1), "real"); assertEquals(functions.get("avg").asList().get(5).getField(2), "real"); assertEquals(functions.get("avg").asList().get(5).getField(3), "aggregate"); assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar"); assertEquals(functions.get("abs").asList().get(0).getField(4), true); assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar"); assertEquals(functions.get("rand").asList().get(0).getField(4), false); assertEquals(functions.get("rank").asList().get(0).getField(3), "window"); assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar(x)");
private static void assertState( ServiceManager manager, Service.State state, Service... services) { Collection<Service> managerServices = manager.servicesByState().get(state); for (Service service : services) { assertEquals(service.toString(), state, service.state()); assertEquals(service.toString(), service.isRunning(), state == Service.State.RUNNING); assertTrue(managerServices + " should contain " + service, managerServices.contains(service)); } }
public static MonitoredResource getResource(String projectId, String resourceTypeParam) { String resourceType = resourceTypeParam; if (Strings.isNullOrEmpty(resourceType)) { Resource detectedResourceType = getAutoDetectedResourceType(); resourceType = detectedResourceType.getKey(); } // Currently, "gae_app" is the supported logging Resource type, but we distinguish // between "gae_app_flex", "gae_app_standard" to support zone id, instance name logging on flex // VMs. // Hence, "gae_app_flex", "gae_app_standard" are trimmed to "gae_app" String resourceName = resourceType.startsWith("gae_app") ? "gae_app" : resourceType; MonitoredResource.Builder builder = MonitoredResource.newBuilder(resourceName).addLabel(Label.ProjectId.getKey(), projectId); for (Label label : resourceTypeWithLabels.get(resourceType)) { String value = getValue(label); if (value != null) { builder.addLabel(label.getKey(), value); } } return builder.build(); }
@SuppressWarnings("CheckReturnValue") default void use() { ImmutableExtraCollection.of( ImmutableList.<String>of(), ImmutableMultimap.<Integer, String>of(), ImmutableMultimap.<Integer, String>of(), ImmutableMultimap.<Integer, String>of(), ImmutableBiMap.<Integer, String>of()); ImmutableExtraCollection.of(); ImmutableExtraCollection collection = ImmutableExtraCollection.builder() .addBag("2", "2") .putIndex(1, "2", "3", "4") .putAllIndex(1, Arrays.asList("2", "3", "4")) .putIndex(2, "5") .putIndexList(1, "") .putIndexSet(2, "2") .putAllIndexSet(2, Arrays.asList("3", "4")) .putBiMap(1, "a") .putBiMap(2, "b") .putAllBiMap(Collections.singletonMap(3, "c")) .build(); collection.bag().count("2"); collection.index().get(1); collection.indexList().get(1); collection.indexSet().get(2); } }
private static ImmutableMultimap<ZipPath, ModuleEntry> discardAbiDirsWithTooFewFiles( ImmutableMultimap<ZipPath, ModuleEntry> libFilesByAbiDir) { int maxAbiFiles = libFilesByAbiDir.asMap().values().stream().mapToInt(Collection::size).max().orElse(0); // Create a set-based multimap for fast look-ups. return ImmutableSetMultimap.copyOf( Multimaps.filterKeys( libFilesByAbiDir, abiDir -> libFilesByAbiDir.get(abiDir).size() == maxAbiFiles)); }
synchronized ImmutableList<UiAnalyzedMethod> getAnalyzedMethods(String className) { // update cache before proceeding updateCache(); Set<UiAnalyzedMethod> analyzedMethods = Sets.newHashSet(); Collection<Location> locations = classNameLocations.get(className); for (Location location : locations) { try { analyzedMethods.addAll(getAnalyzedMethods(location, className)); } catch (IOException e) { logger.warn(e.getMessage(), e); } } if (instrumentation != null) { // also check loaded classes, e.g. for groovy classes for (Class<?> clazz : instrumentation.getAllLoadedClasses()) { if (clazz.getName().equals(className)) { analyzedMethods.addAll(getAnalyzedMethods(clazz)); } } } return ImmutableList.copyOf(analyzedMethods); }
@Override public void run( TransactionManager txManager, TableReference tableRef, Set<Cell> cells, TransactionType transactionType) { Collection<OnCleanupTask> nextTasks = cleanupTasksByTable.get(tableRef); while (!nextTasks.isEmpty()) { final Collection<OnCleanupTask> cleanupTasks = nextTasks; nextTasks = txManager.runTaskWithRetry(tx -> { Collection<OnCleanupTask> toRetry = Lists.newArrayList(); Preconditions.checkArgument(transactionType == TransactionType.HARD_DELETE || transactionType == TransactionType.AGGRESSIVE_HARD_DELETE); tx.setTransactionType(transactionType); for (OnCleanupTask task : cleanupTasks) { boolean needsRetry = task.cellsCleanedUp(tx, cells); if (needsRetry) { toRetry.add(task); } } return toRetry; }); } } }
ImmutableList<ModuleEntry> entriesList = targetingMap .get(targeting) .stream() .flatMap(directory -> moduleSplit.findEntriesUnderPath(directory.getPath()))
/** * Returns a collection of all values associated with the provided parameter. * If no values are found and empty collection is returned. */ public Collection<String> getParameterValues(String name) { return parameters.get(name); }
@SuppressWarnings("unchecked") public <T> Iterable<NamedComponent<T>> get(Factory.Query<T> key) { ImmutableCollection namedComponents = checkNotNull(materials.get(key), "key not found: %s. Check your bill of materials. Available keys: %s", key, materials.keySet()); return (Iterable<NamedComponent<T>>) namedComponents; }
public TypeInfo<?> getTypeFromSchema(int jdbcType, TypeQualifiers qualifiers) { if (jdbcTypeIndex.containsKey(jdbcType)) { // If it is an unlimited text type, add unlimited string length to the qualifiers if (UNLIMITED_TEXT_TYPES.contains(jdbcType)) { qualifiers = qualifiers.stringLength(TypeQualifiers.UNLIMITED_LENGTH); } return findTypeWithQualifiers(jdbcTypeIndex.get(jdbcType), qualifiers); } else { return null; } }