本文整理汇总了Java中com.google.common.collect.ImmutableSet.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableSet.forEach方法的具体用法?Java ImmutableSet.forEach怎么用?Java ImmutableSet.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.ImmutableSet
的用法示例。
在下文中一共展示了ImmutableSet.forEach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapDirectoriesToPackages
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
/**
* This method associates directories with the path of their enclosing package. For example, if
* rules for the source files in /a/b/c/ are written in /a/b/BUILD, then the map will contain the
* entry /a/b/c/ -> /a/b/. Similarly if the rules for source files in /a/b/c/ are written in
* /a/b/c/BUILD, the map would contain the entry /a/b/c/ -> /a/b/c/.
*
* <p>We decide what BUILD file a directories source files are written through a two phase
* process. First, we create a disjoint set of directories. Two directories are unioned if any
* rule contains source files from both directories. Then, we map each directory in a disjoint set
* to the longest common prefix of all directories in the disjoint set.
*/
static ImmutableMap<Path, Path> mapDirectoriesToPackages(
Iterable<ImmutableSet<Path>> components) {
StandardUnionFind<Path> uf = new StandardUnionFind<>();
for (ImmutableSet<Path> component : components) {
ImmutableSet<Path> uniqueDirectories =
component.stream().map(file -> file.getParent()).collect(toImmutableSet());
Path firstDir = uniqueDirectories.iterator().next();
uniqueDirectories.forEach(dir -> uf.union(firstDir, dir));
}
ImmutableMap.Builder<Path, Path> directoryToBuildFileMap = ImmutableMap.builder();
for (Set<Path> equivalenceClass : uf.allEquivalenceClasses()) {
Path buildFilePath = longestCommonPrefixPath(equivalenceClass);
equivalenceClass.forEach(dir -> directoryToBuildFileMap.put(dir, buildFilePath));
}
return directoryToBuildFileMap.build();
}
示例2: render
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
private static void render(StringBuilder sb, GroupedPropertyMap map, ImmutableList<String> current) {
String prefix=Strings.repeat(INDENT, current.size());
String[] array = current.toArray(new String[current.size()]);
ImmutableMap<String, Object> properties = map.propertiesOf(array);
properties.forEach((key,val) -> {
sb.append(prefix).append(INDENT).append(key).append("=").append(val).append("\n");
});
ImmutableSet<String> groups = map.groupsOf(array);
groups.forEach(g -> {
sb.append(prefix).append(INDENT).append(g).append("=").append("{\n");
render(sb,map,ImmutableList.<String>builder().addAll(current).add(g).build());
sb.append(prefix).append(INDENT).append("}\n");
});
}
示例3: hasDataSetForLabels
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
/**
* Asserts that the distribution for the given label can be constructed from the given data set.
*
* <p>Note that this only tests that the distribution has the same binned histogram, along with
* the same mean, and sum of squared deviation as it would if it had recorded the specified data
* points. It could have in fact collected different data points that resulted in the same
* distribution, but that information is lost to us and cannot be tested.
*/
public And<DistributionMetricSubject> hasDataSetForLabels(
ImmutableSet<? extends Number> dataSet, String... labels) {
ImmutableList<MetricPoint<Distribution>> metricPoints = actual().getTimestampedValues();
if (metricPoints.isEmpty()) {
failWithBadResults(
"has a distribution for labels", Joiner.on(':').join(labels), "has", "no values");
}
MutableDistribution targetDistribution =
new MutableDistribution(metricPoints.get(0).value().distributionFitter());
dataSet.forEach(data -> targetDistribution.add(data.doubleValue()));
return hasValueForLabels(ImmutableDistribution.copyOf(targetDistribution), labels);
}
示例4: createLoader
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
private Loader createLoader(Class<? extends Listener> listenerType, @Nullable MatchScope scope) {
scope = listenerScope(listenerType, scope);
if(logger.isLoggable(Level.FINE)) {
logger.fine("Registering listener type " + listenerType.getName() + " in scope " + scope);
}
final ImmutableSet.Builder<Loader> builder = ImmutableSet.builder();
for(EventHandlerInfo<? extends Event> handler : bukkitScanner.findEventHandlers(listenerType).values()) {
builder.add(createLoader(handler, listenerScope(handler.method(), scope)));
}
final ImmutableSet<Loader> loaders = builder.build();
return (match, listener) -> loaders.forEach(loader -> loader.load(match, listener));
}
示例5: saveRegionData
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
public void saveRegionData(ImmutableSet<LoadedRegion> loadedRegions) {
loadedRegions.forEach(this::saveRegionData);
}
示例6: saveUserData
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
public void saveUserData(ImmutableSet<UserData> loadedUserDatas) {
loadedUserDatas.forEach(this::saveUserData);
}
示例7: saveUserData
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
public void saveUserData(ImmutableSet<UserData> loadedRegions) {
loadedRegions.forEach(this::saveUserData);
}
示例8: run
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
/**
* Periodically updates the set of known configurations
*/
@Override
public void run() {
if (cluster.isEnabled() && !cluster.isMaster()) {
logger.info("Skipping configuration update on this node (not master)");
updateTasksAfterClusterEvent();
return;
}
// load configurations from disk and filter out disabled ones
try {
Set<Configuration> latestConfigurationSet = loader.load().stream().filter(c -> !c.disabled()).collect(Collectors.toSet());
// delete configurations
ImmutableSet<Configuration> deleted = ImmutableSet.copyOf(Sets.difference(configurations(), latestConfigurationSet));
deleted.forEach(new DeleteTaskConsumer().andThen(new DeleteConfigurationConsumer()));
// insert or update new configurations
latestConfigurationSet.forEach(new UpsertTaskConsumer().andThen(new UpsertConfigurationConsumer()));
logger.info("Updated configuration set; {} configs upserted, {} configs deleted", latestConfigurationSet.size(), deleted.size());
// if running in runOnce mode, stop immediately if there are no configurations to process
if (latestConfigurationSet.isEmpty()) {
taskManager.completeIfRunningOnceWithoutAnyTasks();
}
} catch (RuntimeException e) {
logger.warn("Unexpected exception while processing configurations", e);
// if this is the first run, rethrow the exception to cause the program to stop
if (IS_CONFIGURED_LATCH.getCount() > 0) {
taskManager.notifyCompleted();
shutdownHook.shutdown();
throw e;
}
} finally {
// mark that we have processed configurations
IS_CONFIGURED_LATCH.countDown();
}
}
示例9: process
import com.google.common.collect.ImmutableSet; //导入方法依赖的package包/类
@Override
public Set<Element> process(final SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation) {
// Populate template lookup table with partially-built
// appliers for any valid templates we have not seen before
knownTemplates.putAll(ElementFilter
.typesIn(elementsByAnnotation.get(Template.class))
.stream()
.filter(validator::validateTemplate) // Emits validation errors
.filter(template -> !knownTemplates.containsKey(Util.fqName(template)))
.collect(toMap(Util::fqName, t -> DaggerProcessorComponent.builder()
.setProcessingEnvironment(env)
.setTemplateElement(t))));
// Track types to defer
final ImmutableSet.Builder<Element> deferred = ImmutableSet.builder();
// For each descriptor, lookup the target template and apply it.
final ImmutableSet<TypeElement> descriptors = ImmutableSet.<TypeElement>builder()
.addAll(ElementFilter.typesIn(elementsByAnnotation.get(Descriptor.class)))
.addAll(ElementFilter.typesIn(elementsByAnnotation.get(Descriptors.class))) // for repeated annotations
.build();
descriptors.forEach(descriptor -> {
// Before proceeding, ensure that all template lookups will succeed; otherwise, defer the entire descriptor.
final boolean defer = streamRepeatedAnnotation(descriptor, Descriptor.class)
.map(target -> Util.classAnnotationField(target::templateClass))
.anyMatch(templateType -> !templateType.isPresent()
|| !knownTemplates.containsKey(templateType.get().toString()));
if (defer) {
// Try again in a later round
deferred.add(descriptor);
return;
}
// Apply this descriptor to each target template
streamRepeatedAnnotationMirrors(descriptor, Descriptor.class).forEach(target -> {
// Validate descriptor (emits validation errors)
final Optional<DescriptorInfo> maybeDescriptorInfo = validator.validateDescriptor(descriptor, target);
if (!maybeDescriptorInfo.isPresent()) {
// Don't defer invalid descriptors
return;
}
final DescriptorInfo descriptorInfo = maybeDescriptorInfo.get();
final String templateTypeKey = descriptorInfo.templateTypeName().toString();
final ClassName outputClass = descriptorInfo.outputClassName();
try {
final JavaFile file = knownTemplates.get(templateTypeKey)
.setDescriptorElement(descriptor)
.setOutputClass(outputClass)
.setTypeAnnotationTargets(descriptorInfo.outputAnnotationTargets())
.build()
.applier()
.javaFile();
ProcessorException.wrapOnException(() -> file.writeTo(env.getFiler()));
} catch (final ProcessorException pe) {
pe.emitError(env.getMessager());
deferred.add(descriptor);
}
});
});
return deferred.build();
}