Search in sources :

Example 31 with Function

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;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) Property(com.intellij.lang.properties.psi.Property) PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) FileModificationService(com.intellij.codeInsight.FileModificationService) PropertySearcher(com.intellij.lang.properties.findUsages.PropertySearcher) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) com.intellij.codeInspection(com.intellij.codeInspection) com.intellij.lang.properties(com.intellij.lang.properties) Objects(java.util.Objects) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) com.intellij.psi(com.intellij.psi) ResourceBundleEditorInspection(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorInspection) NotNull(org.jetbrains.annotations.NotNull) FilteringIterator(com.intellij.util.containers.FilteringIterator) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with Function

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);
}
Also used : BeforeClass(org.junit.BeforeClass) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Matchers.not(org.hamcrest.Matchers.not) DataFolder(fr.xephi.authme.initialization.DataFolder) Function(java.util.function.Function) Assert.assertThat(org.junit.Assert.assertThat) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) Files(com.google.common.io.Files) BDDMockito.given(org.mockito.BDDMockito.given) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestHelper(fr.xephi.authme.TestHelper) PluginSettings(fr.xephi.authme.settings.properties.PluginSettings) Mockito.doReturn(org.mockito.Mockito.doReturn) Description(org.hamcrest.Description) Settings(fr.xephi.authme.settings.Settings) InjectDelayed(ch.jalu.injector.testing.InjectDelayed) Test(org.junit.Test) IOException(java.io.IOException) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) Matcher(org.hamcrest.Matcher) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TemporaryFolder(org.junit.rules.TemporaryFolder) DelayedInjectionRunner(ch.jalu.injector.testing.DelayedInjectionRunner) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) File(java.io.File) Test(org.junit.Test)

Example 33 with Function

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.assertNull(org.testng.Assert.assertNull) Assert.fail(org.testng.Assert.fail) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) Random(java.util.Random) Test(org.testng.annotations.Test) Function(java.util.function.Function) Executors(java.util.concurrent.Executors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assert.assertTrue(org.testng.Assert.assertTrue) ConcurrentOpenHashMap(com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashMap) Assert.assertFalse(org.testng.Assert.assertFalse) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentOpenHashMap(com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Example 34 with Function

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);
}
Also used : Service(org.jboss.msc.service.Service) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ServiceController(org.jboss.msc.service.ServiceController) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossExecutors(org.jboss.threads.JBossExecutors) ThreadFactory(java.util.concurrent.ThreadFactory) Builder(org.wildfly.clustering.service.Builder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 35 with Function

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);
}
Also used : Service(org.jboss.msc.service.Service) AccessController.doPrivileged(java.security.AccessController.doPrivileged) Cache(org.infinispan.Cache) Function(java.util.function.Function) Supplier(java.util.function.Supplier) KeyGenerator(org.infinispan.affinity.KeyGenerator) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) KeyAffinityService(org.infinispan.affinity.KeyAffinityService) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) ServiceTarget(org.jboss.msc.service.ServiceTarget) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) PrivilegedAction(java.security.PrivilegedAction) Executors(java.util.concurrent.Executors) KeyAffinityServiceImpl(org.infinispan.affinity.impl.KeyAffinityServiceImpl) ServiceController(org.jboss.msc.service.ServiceController) CacheMode(org.infinispan.configuration.cache.CacheMode) ServiceName(org.jboss.msc.service.ServiceName) Collections(java.util.Collections) Builder(org.wildfly.clustering.service.Builder) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) CacheMode(org.infinispan.configuration.cache.CacheMode) KeyAffinityServiceFactory(org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) KeyGenerator(org.infinispan.affinity.KeyGenerator) Cache(org.infinispan.Cache) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Aggregations

Function (java.util.function.Function)1261 List (java.util.List)606 Map (java.util.Map)447 ArrayList (java.util.ArrayList)416 Test (org.junit.Test)358 Collectors (java.util.stream.Collectors)324 HashMap (java.util.HashMap)287 Collections (java.util.Collections)284 Arrays (java.util.Arrays)271 Set (java.util.Set)255 IOException (java.io.IOException)252 Collection (java.util.Collection)192 HashSet (java.util.HashSet)191 TimeUnit (java.util.concurrent.TimeUnit)174 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)158 Optional (java.util.Optional)157 Assert (org.junit.Assert)137 Consumer (java.util.function.Consumer)134 Supplier (java.util.function.Supplier)126 CompletableFuture (java.util.concurrent.CompletableFuture)121