List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:com.gohighedu.platform.framework.utils.common.StringUtils.java
/** * Convenience method to return a String array as a delimited (e.g. CSV) * String. E.g. useful for <code>toString()</code> implementations. * @param arr the array to display// w w w. j av a 2 s. c o m * @param delim the delimiter to use (probably a ",") * @return the delimited String */ public static String arrayToDelimitedString(Object[] arr, String delim) { if (ObjectUtils.isEmpty(arr)) { return ""; } if (arr.length == 1) { return ObjectUtils.nullSafeToString(arr[0]); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { if (i > 0) { sb.append(delim); } sb.append(arr[i]); } return sb.toString(); }
From source file:com.jpoweredcart.common.mock.servlet.MockServletContext.java
public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try {/*from w w w. j ava2 s.c om*/ File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<String>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { logger.warn("Couldn't get resource paths for " + resource, ex); return null; } }
From source file:com.qcadoo.customTranslation.internal.CustomTranslationResolverImpl.java
@Override public String getCustomTranslation(final String key, final Locale locale, final String[] args) { String translation = customTranslationCacheService.getCustomTranslation(key, locale.getLanguage()); if (translation == null) { return null; } else {//from ww w .j ava2s . co m translation = translation.replace("'", "''"); Object[] argsToUse = args; if (!ObjectUtils.isEmpty(argsToUse)) { argsToUse = ArrayUtils.EMPTY_OBJECT_ARRAY; } MessageFormat messageFormat = new MessageFormat(translation); return messageFormat.format(argsToUse); } }
From source file:com.sg.socrates.service.item.excel.AbstractExcelItemReader.java
@Override protected T doRead() throws Exception { if (this.noInput) { return null; }/* w w w . j a v a2 s . c o m*/ final Sheet sheet = this.getSheet(this.currentSheet); final String[] row = this.readRow(sheet); if (ObjectUtils.isEmpty(row)) { this.currentSheet++; if (this.currentSheet >= this.getNumberOfSheets()) { if (logger.isDebugEnabled()) { logger.debug("No more sheets in '" + this.resource.getDescription() + "'."); } return null; } else { this.currentRow = 0; this.openSheet(); return this.doRead(); } } else { try { return this.rowMapper.mapRow(sheet, row, this.currentRow); } catch (final Exception e) { throw new ExcelFileParseException("Exception parsing Excel file.", e, this.resource.getDescription(), sheet.getName(), this.currentRow, row); } } }
From source file:com.thoughtworks.go.http.mocks.MockServletContext.java
@Override public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try {/*w w w . jav a 2 s . co m*/ File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { logger.warn("Couldn't get resource paths for " + resource, ex); return null; } }
From source file:fi.vm.sade.eperusteet.ylops.service.ops.impl.OpetussuunnitelmaServiceImpl.java
@Override @Cacheable("tilastot") @Transactional(readOnly = true)/*from w w w .ja v a 2 s. c o m*/ public OpetussuunnitelmaStatistiikkaDto getStatistiikka() { List<OpetussuunnitelmaInfoDto> opsit = mapper .mapAsList(repository.findAllByTyyppi(Tyyppi.OPS), OpetussuunnitelmaInfoDto.class).stream() .map(ops -> { try { fetchOrganisaatioNimet(ops); } catch (BusinessRuleViolationException ex) { logger.error(ex.getLocalizedMessage()); } return ops; }).collect(Collectors.toList()); OpetussuunnitelmaStatistiikkaDto result = new OpetussuunnitelmaStatistiikkaDto(); result.getTasoittain().put("seutukunnat", opsit.stream().filter(ops -> ops.getKunnat().size() > 1).count()); result.getTasoittain().put("kunnat", opsit.stream().filter(ops -> ops.getKunnat().size() == 1).count()); result.getTasoittain().put("koulujoukko", opsit.stream() .filter(ops -> ops.getOrganisaatiot().stream() .filter(org -> !ObjectUtils.isEmpty(org.getTyypit())) .filter(org -> "Oppilaitos".equals(org.getTyypit().get(0))).count() > 1) .count()); result.getTasoittain().put("koulut", opsit.stream() .filter(ops -> ops.getOrganisaatiot().stream() .filter(org -> !ObjectUtils.isEmpty(org.getTyypit())) .filter(org -> "Oppilaitos".equals(org.getTyypit().get(0))).count() == 1) .count()); result.getKielittain().put("fi", opsit.stream().filter(ops -> ops.getJulkaisukielet().contains(Kieli.FI)).count()); result.getKielittain().put("sv", opsit.stream().filter(ops -> ops.getJulkaisukielet().contains(Kieli.SV)).count()); result.getKielittain().put("se", opsit.stream().filter(ops -> ops.getJulkaisukielet().contains(Kieli.SE)).count()); result.getKielittain().put("en", opsit.stream().filter(ops -> ops.getJulkaisukielet().contains(Kieli.EN)).count()); result.getTiloittain().put("esikatseltavissa", opsit.stream().filter(OpetussuunnitelmaBaseDto::isEsikatseltavissa).count()); for (OpetussuunnitelmaInfoDto ops : opsit) { result.getKoulutustyypeittain().put(ops.getKoulutustyyppi().toString(), result.getKoulutustyypeittain().getOrDefault(ops.getKoulutustyyppi().toString(), 0L) + 1); result.getTiloittain().put(ops.getTila().toString(), result.getTiloittain().getOrDefault(ops.getTila().toString(), 0L) + 1); } return result; }
From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java
public void addInterceptors(HandlerInterceptor... interceptors) { if (!ObjectUtils.isEmpty(interceptors)) { initInterceptorList().addAll(Arrays.asList(interceptors)); }/* ww w . ja v a 2 s . com*/ }
From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java
/** * Apply preHandle methods of registered interceptors. * @return {@code true} if the execution chain should proceed with the * next interceptor or the handler itself. Else, DispatcherServlet assumes * that this interceptor has already dealt with the response itself. *///w w w . j av a 2s . c om boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = 0; i < interceptors.length; i++) { HandlerInterceptor interceptor = interceptors[i]; if (!interceptor.preHandle(request, response, this.handler)) { triggerAfterCompletion(request, response, null); return false; } this.interceptorIndex = i; } } return true; }
From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java
/** * Apply postHandle methods of registered interceptors. *//*from w w w . ja v a 2s . c om*/ void applyPostHandle(HttpServletRequest request, HttpServletResponse response, ModelAndView mv) throws Exception { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = interceptors.length - 1; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i]; interceptor.postHandle(request, response, this.handler, mv); } } }
From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java
/** * Trigger afterCompletion callbacks on the mapped HandlerInterceptors. * Will just invoke afterCompletion for all interceptors whose preHandle invocation * has successfully completed and returned true. *///from www. j av a 2 s .co m void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, Exception ex) throws Exception { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = this.interceptorIndex; i >= 0; i--) { HandlerInterceptor interceptor = interceptors[i]; try { interceptor.afterCompletion(request, response, this.handler, ex); } catch (Throwable ex2) { logger.error("HandlerInterceptor.afterCompletion threw exception", ex2); } } } }