List of usage examples for org.springframework.util CollectionUtils isEmpty
public static boolean isEmpty(@Nullable Map<?, ?> map)
From source file:com.google.code.ssm.spring.SSMCacheManager.java
@Override public void afterPropertiesSet() { Assert.notEmpty(caches, "A collection of caches is required and cannot be empty"); this.cacheMap.clear(); // preserve the initial order of the cache names for (SSMCache cache : caches) { addCache(cache.getName(), cache); // use aliases if enabled if (cache.isRegisterAliases() && !CollectionUtils.isEmpty(cache.getCache().getAliases())) { for (String alias : cache.getCache().getAliases()) { addCache(alias, cache);//ww w .ja v a 2 s . com } } } }
From source file:com.developmentsprint.spring.breaker.annotations.AbstractCircuitBreakerConfiguration.java
/** * Determine which {@code CircuitManager} bean to use. Prefer the result of {@link CircuitBreakerConfigurer#circuitManager()} over any by-type matching. If * none, fall back to by-type matching on {@code CircuitManager}. * /*w w w. jav a 2s . c o m*/ * @throws IllegalArgumentException * if no CircuitManager can be found; if more than one CircuitBreakerConfigurer implementation exists; if multiple CircuitManager beans and no * CircuitBreakerConfigurer exists to disambiguate. */ @PostConstruct protected void reconcileCircuitManager() { if (!CollectionUtils.isEmpty(circuitBreakerConfigurers)) { int nConfigurers = circuitBreakerConfigurers.size(); if (nConfigurers > 1) { throw new IllegalStateException(nConfigurers + " implementations of " + "CircuitBreakerConfigurer were found when only 1 was expected. " + "Refactor the configuration such that CircuitBreakerConfigurer is " + "implemented only once or not at all."); } CircuitBreakerConfigurer circuitBreakerConfigurer = circuitBreakerConfigurers.iterator().next(); this.circuitManager = circuitBreakerConfigurer.circuitManager(); } else if (!CollectionUtils.isEmpty(circuitManagerBeans)) { int nManagers = circuitManagerBeans.size(); if (nManagers > 1) { throw new IllegalStateException(nManagers + " beans of type CircuitManager were found when only 1 was expected. Remove all but one of the CircuitManager bean definitions, or implement CircuitBreakerConfigurer to make explicit which CircuitManager should be used for annotation-driven circuit breaker management."); } CircuitManager circuitManager = circuitManagerBeans.iterator().next(); this.circuitManager = circuitManager; } else { throw new IllegalStateException( "No bean of type CircuitManager could be found. Register a CircuitManager bean or remove the @EnableCircuitBreakers annotation from your configuration."); } }
From source file:test.com.azaptree.services.spring.application.SpringApplicationServiceTest.java
@Test public void testSpringApplicationService() throws Exception { final String[] args = { "classpath:spring-application-service.xml" }; try {// w ww . ja v a 2 s . co m new Thread(new Runnable() { @Override public void run() { try { SpringApplicationService.main(args); } catch (Exception e) { e.printStackTrace(); } } }).start(); Thread.yield(); ApplicationContext ctx = SpringApplicationService.getApplicationContext(); while (ctx == null) { log.info("Waiting for ApplicationContext to initialize ..."); Thread.sleep(100l); ctx = SpringApplicationService.getApplicationContext(); } Assert.assertNotNull(ctx); final Properties props = ctx.getBean("systemProps", Properties.class); Assert.assertNotNull(props); Assert.assertFalse(CollectionUtils.isEmpty(props)); Assert.assertEquals(props.getProperty("app.env"), "DEV"); final Map<String, String> env = ctx.getBean("env", Map.class); Assert.assertNotNull(env); Assert.assertFalse(CollectionUtils.isEmpty(env)); final Map<String, String> environment = ctx.getBean("environment", Map.class); Assert.assertNotNull(environment); Assert.assertFalse(CollectionUtils.isEmpty(environment)); log.info("bean count: {}", ctx.getBeanDefinitionCount()); for (String beanName : ctx.getBeanDefinitionNames()) { log.info("beanName: {}", beanName); } } finally { SpringApplicationService.shutdown(); } }
From source file:com.ankang.report.main.ReportCabinet.java
public static Monitor matchMonitor(String modul, String method) { if (StringUtils.isEmpty(modul) || StringUtils.isEmpty(method)) { return null; }/*w w w. j av a 2 s . c om*/ Map moduls = RA.getPool(MonitorRegister.MONITOR_ALIAS_NAME); List<Monitor> monitors = (List<Monitor>) moduls.get(modul); if (!CollectionUtils.isEmpty(monitors)) { for (Monitor monitor : monitors) { if (method.equalsIgnoreCase(monitor.getMethod())) { return monitor; } } } return null; }
From source file:com.appglu.impl.util.StringUtils.java
public static String collectionToDelimitedString(Collection<?> coll, String delim, String prefix, String suffix) {/*from ww w.j a v a 2 s . c o m*/ if (CollectionUtils.isEmpty(coll)) { return ""; } StringBuilder sb = new StringBuilder(); Iterator<?> it = coll.iterator(); while (it.hasNext()) { sb.append(prefix).append(it.next()).append(suffix); if (it.hasNext()) { sb.append(delim); } } return sb.toString(); }
From source file:com.collegesource.interfaces.student.BannerStudentFinder.java
/** * Find a student in Banner by stuno.// w w w.j a v a 2 s . c o m * * @param instidq * @param instid * @param stuno */ @Override public StuMaster findStudentByStuno(String instidq, String instid, String stuno) { //Trim Values instidq = StringUtils.trimToEmpty(instidq); instid = StringUtils.trimToEmpty(instid); stuno = StringUtils.trimToEmpty(stuno); logger.debug(MessageFormat.format("Searching for student by stuno[{0}]", stuno)); StuMaster sm = new StuMaster(); List<Map<String, Object>> results = bannerDao.searchForStudentByStuno(stuno, logger); if (!CollectionUtils.isEmpty(results)) { sm = createStudent(results.get(0)); if (!findStudentInStuMaster(instidq, instid, stuno)) { createStuMasterAndStuDemoRecord(sm); } else if (!validateStuDemo(sm)) { updateStuDemoRecord(sm); } } return sm; }
From source file:nl.surfnet.coin.api.client.domain.Person.java
@JsonIgnore public String getEmailValue() { return CollectionUtils.isEmpty(emails) ? null : emails.iterator().next().getValue(); }
From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.service.anonymisation.AnonymisationService.java
private void traverseAndAnonymise(Node node, Patient patient) { if (node == null) { return;//from ww w . j a v a 2s . co m } if (node instanceof TextNode) { TextNode textNode = (TextNode) node; textNode.text(pseudonymiseAll(patient, textNode.text())); } if (CollectionUtils.isEmpty(node.childNodes())) { return; } for (Node child : node.childNodes()) { traverseAndAnonymise(child, patient); } }
From source file:com.azaptree.services.http.impl.ExecutorThreadPoolWithGracefulShutdown.java
@Override protected void doStop() throws Exception { final Logger log = LoggerFactory.getLogger(getClass()); log.info("STOPPING ..."); executor.shutdown();//from w w w .j av a2 s . c om int totalWaitTime = 0; final int waitTimeInterval = shutdownTimeoutSecs * 1000 / 2; final int shutdownTimeout = (shutdownTimeoutSecs * 1000); log.debug("waitTimeInterval = {} msec", waitTimeInterval); log.debug("shutdownTimeout = {} msec", shutdownTimeout); while (true) { if (executor.awaitTermination(waitTimeInterval, TimeUnit.MILLISECONDS)) { break; } totalWaitTime += waitTimeInterval; log.debug("totalWaitTime = {} msec", totalWaitTime); if (totalWaitTime >= shutdownTimeout) { log.error("Executor tasks failed to shutdown within specified max wait time: {}", shutdownTimeoutSecs); final List<Runnable> tasks = executor.shutdownNow(); if (!CollectionUtils.isEmpty(tasks)) { log.error("Number of tasks left in the executor queue that were not processed = {}", tasks.size()); for (final Runnable task : tasks) { log.error("Unprocessed task: {}", task); } } break; } log.warn("Waiting for executor tasks to complete - Current Wait Time / Max Wait Time = {}/{}", totalWaitTime, shutdownTimeoutSecs); } super.doStop(); log.info("STOPPED"); }
From source file:com.frank.search.solr.core.schema.SolrSchemaWriter.java
private void writeFieldDefinitions(Collection<SchemaDefinition.FieldDefinition> definitions, String collectionName) {//w ww. j ava 2 s . c o m if (!CollectionUtils.isEmpty(definitions)) { try { SolrSchemaRequest.create().fields(definitions).build() .process(factory.getSolrClient(collectionName)); } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to write schema field definitions.", e); } } }