Example usage for org.springframework.util CollectionUtils containsInstance

List of usage examples for org.springframework.util CollectionUtils containsInstance

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils containsInstance.

Prototype

public static boolean containsInstance(@Nullable Collection<?> collection, Object element) 

Source Link

Document

Check whether the given Collection contains the given element instance.

Usage

From source file:org.web4thejob.context.ORMLauncher.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (event.getApplicationContext().getParent() == null) {
        if (ContextUtil.getSystemJoblet().isInstalled()) {
            if (!CollectionUtils.containsInstance(ContextUtil.getActiveProfiles(), "installed")) {
                ContextUtil.addActiveProfile("installed");
                ContextUtil.refresh();/*from  w  w  w  . j  ava2s.c  o m*/
            }
        }
    }
}

From source file:com.gzj.tulip.jade.dataaccess.datasource.MasterSlaveDataSourceFactory.java

/**
 * /*w  w w.j  a  v  a  2  s .  co m*/
 * @param master
 * @param slaves
 * @param queryFromMaster true?master???
 */
public MasterSlaveDataSourceFactory(DataSource master, List<DataSource> slaves, boolean queryFromMaster) {
    if (queryFromMaster && !CollectionUtils.containsInstance(slaves, master)) {
        slaves = new ArrayList<DataSource>(slaves);
        slaves.add(master);
    }
    setSlaves(new RandomDataSourceFactory(slaves));
    setMasters(new SimpleDataSourceFactory(master));
}

From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java

@Test
public void testNewSingleThreadExecutorShutdownNow() throws InterruptedException {
    NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME);
    ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory);

    executor.submit(new SleepRunnable(10L));
    Future<?> notExecutedRunnable = executor.submit(new NullRunnable());
    Future<?> notExecutedCallable = executor.submit(new NullCallable());
    Future<Integer> notEexecutedRunnable2 = executor.submit(new NullRunnable(), 1);

    List<Runnable> notExecuted = executor.shutdownNow();
    Assert.assertTrue(executor.isShutdown());
    Assert.assertEquals(3, notExecuted.size());
    Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notExecutedRunnable));
    Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notExecutedCallable));
    Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notEexecutedRunnable2));

    executor.awaitTermination(10, TimeUnit.MILLISECONDS);
    Assert.assertTrue(executor.isTerminated());
}

From source file:com.brienwheeler.lib.monitor.telemetry.TelemetryInfoTest.java

@Test
public void testGetAttributeNames() {
    TelemetryInfo telemetryInfo = new TelemetryInfo(NAME, log);
    telemetryInfo.set(ATTR, VALUE);/*from w  ww  .ja  v  a2s  . c om*/
    Collection<String> attrNames = telemetryInfo.getAttributeNames();
    Assert.assertEquals(3, attrNames.size());
    Assert.assertTrue(CollectionUtils.containsInstance(attrNames, TelemetryInfo.ATTR_NAME));
    Assert.assertTrue(CollectionUtils.containsInstance(attrNames, TelemetryInfo.ATTR_CREATED_AT));
    Assert.assertTrue(CollectionUtils.containsInstance(attrNames, ATTR));
}

From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java

@Test
public void testNewSingleThreadScheduledExecutor() {
    NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME);
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(threadFactory);

    ScheduledFuture<?> future1 = executor.schedule(new NullRunnable(), 10, TimeUnit.MILLISECONDS);
    ScheduledFuture<Integer> future2 = executor.schedule(new IntCallable(1), 10, TimeUnit.MILLISECONDS);
    ScheduledFuture<?> future3 = executor.scheduleAtFixedRate(new NullRunnable(), 10, 10,
            TimeUnit.MILLISECONDS);
    ScheduledFuture<?> future4 = executor.scheduleWithFixedDelay(new NullRunnable(), 10, 10,
            TimeUnit.MILLISECONDS);

    List<Runnable> notRun = executor.shutdownNow();
    Assert.assertTrue(executor.isShutdown());
    Assert.assertEquals(4, notRun.size());
    Assert.assertTrue(CollectionUtils.containsInstance(notRun, future1));
    Assert.assertTrue(CollectionUtils.containsInstance(notRun, future2));
    Assert.assertTrue(CollectionUtils.containsInstance(notRun, future3));
    Assert.assertTrue(CollectionUtils.containsInstance(notRun, future4));
}

From source file:org.springframework.jmx.export.MBeanExporter.java

/**
 * Performs the actual autodetection process, delegating to an instance
 * <code>AutodetectCallback</code> to vote on the inclusion of a given bean.
 * @param callback the <code>AutodetectCallback</code> to use when deciding
 * whether to include a bean or not//from ww  w .j a  va 2s .  c o  m
 */
private void autodetect(AutodetectCallback callback) {
    String[] beanNames = this.beanFactory.getBeanNamesForType(null);
    for (int i = 0; i < beanNames.length; i++) {
        String beanName = beanNames[i];
        if (!isExcluded(beanName)) {
            Class beanClass = this.beanFactory.getType(beanName);
            if (beanClass != null && callback.include(beanClass, beanName)) {
                boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
                Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
                if (!this.beans.containsValue(beanName) && (beanInstance == null
                        || !CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
                    // Not already registered for JMX exposure.
                    this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
                    if (logger.isInfoEnabled()) {
                        logger.info("Bean with name '" + beanName + "' has been autodetected for JMX exposure");
                    }
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "Bean with name '" + beanName + "' is already registered for JMX exposure");
                    }
                }
            }
        }
    }
}

From source file:org.springframework.ldap.odm.test.TestLdap.java

@Test
public void findAllAsPlainPersons() {
    List<PlainPerson> allPeople = odmManager.findAll(PlainPerson.class, baseName, searchControls);

    assertEquals(9, allPeople.size());/*  w  w w .j  a v a 2s .  co m*/
    assertFalse("No nulls should have been returned", CollectionUtils.containsInstance(allPeople, null));
}