use of java.util.function.Function in project intellij-community by JetBrains.
the class UnusedPropertyInspection method buildPropertyGroupVisitor.
@NotNull
@Override
public Function<IProperty[], ResourceBundleEditorProblemDescriptor[]> buildPropertyGroupVisitor(@NotNull ResourceBundle resourceBundle) {
final Module module = ModuleUtilCore.findModuleForPsiElement(resourceBundle.getDefaultPropertiesFile().getContainingFile());
if (module == null)
return x -> null;
final UnusedPropertiesSearchHelper helper = new UnusedPropertiesSearchHelper(module);
return properties -> !isPropertyUsed((Property) properties[0], helper, true) ? new ResourceBundleEditorProblemDescriptor[] { new ResourceBundleEditorProblemDescriptor(ProblemHighlightType.LIKE_UNUSED_SYMBOL, PropertiesBundle.message("unused.property.problem.descriptor.name"), new RemovePropertiesFromAllLocalesFix((Property) properties[0])) } : null;
}
use of java.util.function.Function in project AuthMeReloaded by AuthMe.
the class MessageFileHandlerProviderTest method shouldCreateHandler.
@Test
public void shouldCreateHandler() {
// given
String language = "fr";
given(settings.getProperty(PluginSettings.MESSAGES_LANGUAGE)).willReturn(language);
MessageFileHandlerProvider provider = Mockito.spy(handlerProvider);
Function<String, String> fileFunction = lang -> "file_" + lang + ".txt";
File file = new File(dataFolder, "some_file.txt");
doReturn(file).when(provider).initializeFile(language, fileFunction);
// when
MessageFileHandler handler = provider.initializeHandler(fileFunction);
// then
assertThat(handler, not(nullValue()));
verify(settings).getProperty(PluginSettings.MESSAGES_LANGUAGE);
verify(provider).initializeFile(language, fileFunction);
}
use of java.util.function.Function in project pulsar by yahoo.
the class ConcurrentOpenHashMapTest method testComputeIfAbsent.
@Test
public void testComputeIfAbsent() {
ConcurrentOpenHashMap<Integer, Integer> map = new ConcurrentOpenHashMap<>(16, 1);
AtomicInteger counter = new AtomicInteger();
Function<Integer, Integer> provider = key -> counter.getAndIncrement();
assertEquals(map.computeIfAbsent(0, provider).intValue(), 0);
assertEquals(map.get(0).intValue(), 0);
assertEquals(map.computeIfAbsent(1, provider).intValue(), 1);
assertEquals(map.get(1).intValue(), 1);
assertEquals(map.computeIfAbsent(1, provider).intValue(), 1);
assertEquals(map.get(1).intValue(), 1);
assertEquals(map.computeIfAbsent(2, provider).intValue(), 2);
assertEquals(map.get(2).intValue(), 2);
}
use of java.util.function.Function in project wildfly by wildfly.
the class RemoveOnCancelScheduledExecutorServiceBuilder method build.
@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
Supplier<ScheduledExecutorService> supplier = () -> {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
};
Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of java.util.function.Function in project wildfly by wildfly.
the class KeyAffinityServiceFactoryBuilder method build.
@Override
public ServiceBuilder<KeyAffinityServiceFactory> build(ServiceTarget target) {
int bufferSize = this.bufferSize;
Function<ExecutorService, KeyAffinityServiceFactory> mapper = executor -> new KeyAffinityServiceFactory() {
@Override
public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) {
CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode();
return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator);
}
};
Supplier<ExecutorService> supplier = () -> {
ThreadGroup threadGroup = new ThreadGroup("KeyAffinityService ThreadGroup");
String namePattern = "KeyAffinityService Thread Pool -- %t";
PrivilegedAction<ThreadFactory> action = () -> new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
return Executors.newCachedThreadPool(doPrivileged(action));
};
Service<KeyAffinityServiceFactory> service = new SuppliedValueService<>(mapper, supplier, ExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.getServiceName(), service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
Aggregations