org.springframework.util.CollectionUtils.isEmpty() - java examples

Here are the examples of the java api org.springframework.util.CollectionUtils.isEmpty() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : ExpressionState.java
Copyright MIT License
Author : codeEngraver
public TypedValue getScopeRootContextObject() {
    if (CollectionUtils.isEmpty(this.scopeRootObjects)) {
        return this.rootObject;
    }
    return this.scopeRootObjects.element();
}

19 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : Vip-Augus
/**
 * Return a unique result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 instance found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the unique result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * result object has been found in the given Collection
 * @throws EmptyResultDataAccessException if no result object at all
 * has been found in the given Collection
 * @see org.springframework.util.CollectionUtils#hasUniqueObject
 */
public static <T> T requiredUniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (!CollectionUtils.hasUniqueObject(results)) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : ExpressionState.java
Copyright Apache License 2.0
Author : spring-projects
public TypedValue getScopeRootContextObject() {
    if (CollectionUtils.isEmpty(this.scopeRootObjects)) {
        return this.rootObject;
    }
    return this.scopeRootObjects.element();
}

19 View Complete Implementation : ServerDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void insert(final List<ServerModel> serverList) {
    if (CollectionUtils.isEmpty(serverList)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("insert into server (region_id, server_id, operation, operator_id, token) values (?,?,?,?,?)" + " on duplicate key update operator_id=?, token=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return serverList.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final ServerModel server = serverList.get(index);
            ps.setString(1, server.getRegionId());
            ps.setString(2, server.getServerId());
            ps.setString(3, server.getOperation());
            ps.setString(4, server.getOperatorId());
            ps.setString(5, server.getToken());
            ps.setString(6, server.getOperatorId());
            ps.setString(7, server.getToken());
        }
    });
}

19 View Complete Implementation : DataAccessUtils.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Return a unique result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 instance found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the unique result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * result object has been found in the given Collection
 * @throws EmptyResultDataAccessException if no result object at all
 * has been found in the given Collection
 * @see org.springframework.util.CollectionUtils#hasUniqueObject
 */
public static <T> T requiredUniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (!CollectionUtils.hasUniqueObject(results)) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : ServerDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void destroyServers(final List<ServerKey> serverKeys) {
    if (CollectionUtils.isEmpty(serverKeys)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return serverKeys.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            ServerKey serverKey = serverKeys.get(index);
            ps.setString(1, serverKey.getRegionId());
            ps.setString(2, serverKey.getServerId());
        }
    });
}

19 View Complete Implementation : ServerLogDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void insert(final List<ServerLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("insert into server_log (region_id, server_id, operation, operator_id, token, extensions, complete) values (?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return logs.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final ServerLogModel log = logs.get(index);
            ps.setString(1, log.getRegionId());
            ps.setString(2, log.getServerId());
            ps.setString(3, log.getOperation());
            ps.setString(4, log.getOperatorId());
            ps.setString(5, log.getToken());
            ps.setString(6, log.getExtensions());
            ps.setBoolean(7, log.isComplete());
        }
    });
}

19 View Complete Implementation : ExpressionState.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * The active context object is what unqualified references to properties/etc are resolved against.
 */
public TypedValue getActiveContextObject() {
    if (CollectionUtils.isEmpty(this.contextObjects)) {
        return this.rootObject;
    }
    return this.contextObjects.element();
}

19 View Complete Implementation : ExpressionState.java
Copyright MIT License
Author : codeEngraver
/**
 * The active context object is what unqualified references to properties/etc are resolved against.
 */
public TypedValue getActiveContextObject() {
    if (CollectionUtils.isEmpty(this.contextObjects)) {
        return this.rootObject;
    }
    return this.contextObjects.element();
}

19 View Complete Implementation : ExpressionState.java
Copyright MIT License
Author : Vip-Augus
public TypedValue getScopeRootContextObject() {
    if (CollectionUtils.isEmpty(this.scopeRootObjects)) {
        return this.rootObject;
    }
    return this.scopeRootObjects.element();
}

19 View Complete Implementation : DefaultWebClientBuilder.java
Copyright Apache License 2.0
Author : spring-projects
private ExchangeStrategies initExchangeStrategies() {
    if (CollectionUtils.isEmpty(this.strategiesConfigurers)) {
        return this.strategies != null ? this.strategies : ExchangeStrategies.withDefaults();
    }
    ExchangeStrategies.Builder builder = this.strategies != null ? this.strategies.mutate() : ExchangeStrategies.builder();
    this.strategiesConfigurers.forEach(configurer -> configurer.accept(builder));
    return builder.build();
}

19 View Complete Implementation : InstanceLogDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void insert(final List<InstanceLogModel> logs) {
    if (CollectionUtils.isEmpty(logs)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("insert into instance_log (region_id, service_id, instance_id, operation, operator_id, token, extensions, complete) values (?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return logs.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final InstanceLogModel log = logs.get(index);
            ps.setString(1, log.getRegionId());
            ps.setString(2, log.getServiceId());
            ps.setString(3, log.getInstanceId());
            ps.setString(4, log.getOperation());
            ps.setString(5, log.getOperatorId());
            ps.setString(6, log.getToken());
            ps.setString(7, log.getExtensions());
            ps.setBoolean(8, log.isComplete());
        }
    });
}

19 View Complete Implementation : InstanceDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void destroyServers(final List<ServerKey> serverKeys) {
    if (CollectionUtils.isEmpty(serverKeys)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from instance where region_id=? and instance_id=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return serverKeys.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            ServerKey serverKey = serverKeys.get(index);
            ps.setString(1, serverKey.getRegionId());
            ps.setString(2, serverKey.getServerId());
        }
    });
}

19 View Complete Implementation : DataAccessUtils.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Return a single result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 element found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the single result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 * @throws EmptyResultDataAccessException if no element at all
 * has been found in the given Collection
 */
public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : ValidationUtils.java
Copyright GNU General Public License v3.0
Author : halo-dev
/**
 * 将字段验证错误转换为标准的map型,key:value = field:message
 *
 * @param fieldErrors 字段错误组
 * @return 如果返回null,则表示未出现错误
 */
public static Map<String, String> mapWithFieldError(@Nullable List<FieldError> fieldErrors) {
    if (CollectionUtils.isEmpty(fieldErrors)) {
        return Collections.emptyMap();
    }
    Map<String, String> errMap = new HashMap<>(4);
    fieldErrors.forEach(filedError -> errMap.put(filedError.getField(), filedError.getDefaultMessage()));
    return errMap;
}

19 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : codeEngraver
/**
 * Return a unique result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 instance found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the unique result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * result object has been found in the given Collection
 * @throws EmptyResultDataAccessException if no result object at all
 * has been found in the given Collection
 * @see org.springframework.util.CollectionUtils#hasUniqueObject
 */
public static <T> T requiredUniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (!CollectionUtils.hasUniqueObject(results)) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : codeEngraver
/**
 * Return a single result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 element found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the single result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 * @throws EmptyResultDataAccessException if no element at all
 * has been found in the given Collection
 */
public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : Vip-Augus
/**
 * Return a single result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 element found.
 * @param results the result Collection (can be {@code null}
 * but is not expected to contain {@code null} elements)
 * @return the single result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 * @throws EmptyResultDataAccessException if no element at all
 * has been found in the given Collection
 */
public static <T> T requiredSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

19 View Complete Implementation : InstanceDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void insert(final List<InstanceModel> instances) {
    if (CollectionUtils.isEmpty(instances)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("insert into instance (region_id, service_id, instance_id, operation, operator_id, token) values (?,?,?,?,?,?)" + " on duplicate key update operator_id=?, token=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return instances.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final InstanceModel instance = instances.get(index);
            ps.setString(1, instance.getRegionId());
            ps.setString(2, instance.getServiceId());
            ps.setString(3, instance.getInstanceId());
            ps.setString(4, instance.getOperation());
            ps.setString(5, instance.getOperatorId());
            ps.setString(6, instance.getToken());
            ps.setString(7, instance.getOperatorId());
            ps.setString(8, instance.getToken());
        }
    });
}

19 View Complete Implementation : ServerDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void delete(final List<ServerModel> serverList) {
    if (CollectionUtils.isEmpty(serverList)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from server where region_id=? and server_id=? and operation=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return serverList.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final ServerModel server = serverList.get(index);
            ps.setString(1, server.getRegionId());
            ps.setString(2, server.getServerId());
            ps.setString(3, server.getOperation());
        }
    });
}

19 View Complete Implementation : ExpressionState.java
Copyright MIT License
Author : Vip-Augus
/**
 * The active context object is what unqualified references to properties/etc are resolved against.
 */
public TypedValue getActiveContextObject() {
    if (CollectionUtils.isEmpty(this.contextObjects)) {
        return this.rootObject;
    }
    return this.contextObjects.element();
}

19 View Complete Implementation : InstanceDao.java
Copyright Apache License 2.0
Author : ctripcorp
public void delete(final List<InstanceModel> instances) {
    if (CollectionUtils.isEmpty(instances)) {
        return;
    }
    DataConfig.jdbcTemplate().batchUpdate("delete from instance where region_id=? and service_id=? and instance_id=? and operation=?", new BatchPreparedStatementSetter() {

        @Override
        public int getBatchSize() {
            return instances.size();
        }

        @Override
        public void setValues(final PreparedStatement ps, final int index) throws SQLException {
            final InstanceModel instance = instances.get(index);
            ps.setString(1, instance.getRegionId());
            ps.setString(2, instance.getServiceId());
            ps.setString(3, instance.getInstanceId());
            ps.setString(4, instance.getOperation());
        }
    });
}

18 View Complete Implementation : ResourceHttpRequestHandler.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this clreplaced.
 */
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
                pathResolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
            }
            if (this.urlPathHelper != null) {
                pathResolver.setLocationCharsets(this.locationCharsets);
                pathResolver.setUrlPathHelper(this.urlPathHelper);
            }
            break;
        }
    }
}

18 View Complete Implementation : OptionController.java
Copyright GNU General Public License v3.0
Author : halo-dev
@GetMapping("map_view")
@ApiOperation("Lists all options with map view")
public Map<String, Object> listAllWithMapView(@RequestParam(value = "key[]", required = false) List<String> keys) {
    if (CollectionUtils.isEmpty(keys)) {
        return optionService.listOptions();
    }
    return optionService.listOptions(keys);
}

18 View Complete Implementation : NotificationListenerRegistrar.java
Copyright Apache License 2.0
Author : spring-projects
@Override
public void afterPropertiesSet() {
    if (getNotificationListener() == null) {
        throw new IllegalArgumentException("Property 'notificationListener' is required");
    }
    if (CollectionUtils.isEmpty(this.mappedObjectNames)) {
        throw new IllegalArgumentException("Property 'mappedObjectName' is required");
    }
    prepare();
}

18 View Complete Implementation : AbstractAsyncConfiguration.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Collect any {@link AsyncConfigurer} beans through autowiring.
 */
@Autowired(required = false)
void setConfigurers(Collection<AsyncConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException("Only one AsyncConfigurer may exist");
    }
    AsyncConfigurer configurer = configurers.iterator().next();
    this.executor = configurer::getAsyncExecutor;
    this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler;
}

18 View Complete Implementation : DataAccessUtils.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Return a unique result object from the given Collection.
 * <p>Returns {@code null} if 0 result objects found;
 * throws an exception if more than 1 instance found.
 * @param results the result Collection (can be {@code null})
 * @return the unique result object, or {@code null} if none
 * @throws IncorrectResultSizeDataAccessException if more than one
 * result object has been found in the given Collection
 * @see org.springframework.util.CollectionUtils#hasUniqueObject
 */
@Nullable
public static <T> T uniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        return null;
    }
    if (!CollectionUtils.hasUniqueObject(results)) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : codeEngraver
/**
 * Return a unique result object from the given Collection.
 * <p>Returns {@code null} if 0 result objects found;
 * throws an exception if more than 1 instance found.
 * @param results the result Collection (can be {@code null})
 * @return the unique result object, or {@code null} if none
 * @throws IncorrectResultSizeDataAccessException if more than one
 * result object has been found in the given Collection
 * @see org.springframework.util.CollectionUtils#hasUniqueObject
 */
@Nullable
public static <T> T uniqueResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        return null;
    }
    if (!CollectionUtils.hasUniqueObject(results)) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : AbstractCachingConfiguration.java
Copyright Apache License 2.0
Author : spring-projects
@Autowired(required = false)
void setConfigurers(Collection<CachingConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException(configurers.size() + " implementations of " + "CachingConfigurer were found when only 1 was expected. " + "Refactor the configuration such that CachingConfigurer is " + "implemented only once or not at all.");
    }
    CachingConfigurer configurer = configurers.iterator().next();
    useCachingConfigurer(configurer);
}

18 View Complete Implementation : AbstractCacheInterceptor.java
Copyright MIT License
Author : codeEngraver
/**
 * Convert the collection of caches in a single expected element.
 * <p>Throw an {@link IllegalStateException} if the collection holds more than one element
 * @return the single element or {@code null} if the collection is empty
 */
@Nullable
static Cache extractFrom(Collection<? extends Cache> caches) {
    if (CollectionUtils.isEmpty(caches)) {
        return null;
    } else if (caches.size() == 1) {
        return caches.iterator().next();
    } else {
        throw new IllegalStateException("Unsupported cache resolution result " + caches + ": JSR-107 only supports a single cache.");
    }
}

18 View Complete Implementation : AbstractCachingConfiguration.java
Copyright MIT License
Author : codeEngraver
@Autowired(required = false)
void setConfigurers(Collection<CachingConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException(configurers.size() + " implementations of " + "CachingConfigurer were found when only 1 was expected. " + "Refactor the configuration such that CachingConfigurer is " + "implemented only once or not at all.");
    }
    CachingConfigurer configurer = configurers.iterator().next();
    useCachingConfigurer(configurer);
}

18 View Complete Implementation : OptionServiceImpl.java
Copyright GNU General Public License v3.0
Author : halo-dev
@Override
public Map<String, Object> listOptions(List<String> keys) {
    if (CollectionUtils.isEmpty(keys)) {
        return Collections.emptyMap();
    }
    Map<String, Object> optionMap = listOptions();
    Map<String, Object> result = new HashMap<>(keys.size());
    keys.stream().filter(optionMap::containsKey).forEach(key -> result.put(key, optionMap.get(key)));
    return result;
}

18 View Complete Implementation : BaseCommentServiceImpl.java
Copyright GNU General Public License v3.0
Author : halo-dev
@Override
public <T extends BaseCommentDTO> List<T> filterIpAddress(List<T> comments) {
    if (CollectionUtils.isEmpty(comments)) {
        return Collections.emptyList();
    }
    comments.forEach(this::filterIpAddress);
    return comments;
}

18 View Complete Implementation : AbstractCacheInterceptor.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Convert the collection of caches in a single expected element.
 * <p>Throw an {@link IllegalStateException} if the collection holds more than one element
 * @return the single element, or {@code null} if the collection is empty
 */
@Nullable
static Cache extractFrom(Collection<? extends Cache> caches) {
    if (CollectionUtils.isEmpty(caches)) {
        return null;
    } else if (caches.size() == 1) {
        return caches.iterator().next();
    } else {
        throw new IllegalStateException("Unsupported cache resolution result " + caches + ": JSR-107 only supports a single cache.");
    }
}

18 View Complete Implementation : AbstractAsyncConfiguration.java
Copyright MIT License
Author : codeEngraver
/**
 * Collect any {@link AsyncConfigurer} beans through autowiring.
 */
@Autowired(required = false)
void setConfigurers(Collection<AsyncConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException("Only one AsyncConfigurer may exist");
    }
    AsyncConfigurer configurer = configurers.iterator().next();
    this.executor = configurer::getAsyncExecutor;
    this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler;
}

18 View Complete Implementation : DataAccessUtils.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Return a single result object from the given Collection.
 * <p>Returns {@code null} if 0 result objects found;
 * throws an exception if more than 1 element found.
 * @param results the result Collection (can be {@code null})
 * @return the single result object, or {@code null} if none
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 */
@Nullable
public static <T> T singleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        return null;
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : SimpAnnotationMethodMessageHandler.java
Copyright MIT License
Author : codeEngraver
@Override
protected String getLookupDestination(@Nullable String destination) {
    if (destination == null) {
        return null;
    }
    if (CollectionUtils.isEmpty(getDestinationPrefixes())) {
        return destination;
    }
    for (String prefix : getDestinationPrefixes()) {
        if (destination.startsWith(prefix)) {
            if (this.slashPathSeparator) {
                return destination.substring(prefix.length() - 1);
            } else {
                return destination.substring(prefix.length());
            }
        }
    }
    return null;
}

18 View Complete Implementation : ResourceHttpRequestHandler.java
Copyright MIT License
Author : codeEngraver
/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this clreplaced.
 */
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
                pathResolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
            }
            if (this.urlPathHelper != null) {
                pathResolver.setLocationCharsets(this.locationCharsets);
                pathResolver.setUrlPathHelper(this.urlPathHelper);
            }
            break;
        }
    }
}

18 View Complete Implementation : OptionController.java
Copyright GNU General Public License v3.0
Author : halo-dev
@GetMapping("map_view")
@ApiOperation("Lists options with map view")
public Map<String, Object> listAllWithMapView(@RequestParam(value = "key", required = false) List<String> keys) {
    if (CollectionUtils.isEmpty(keys)) {
        return optionService.listOptions();
    }
    return optionService.listOptions(keys);
}

18 View Complete Implementation : AbstractTransactionManagementConfiguration.java
Copyright Apache License 2.0
Author : spring-projects
@Autowired(required = false)
void setConfigurers(Collection<TransactionManagementConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException("Only one TransactionManagementConfigurer may exist");
    }
    TransactionManagementConfigurer configurer = configurers.iterator().next();
    this.txManager = configurer.annotationDrivenTransactionManager();
}

18 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : codeEngraver
/**
 * Return a single result object from the given Collection.
 * <p>Returns {@code null} if 0 result objects found;
 * throws an exception if more than 1 element found.
 * @param results the result Collection (can be {@code null})
 * @return the single result object, or {@code null} if none
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 */
@Nullable
public static <T> T singleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    if (CollectionUtils.isEmpty(results)) {
        return null;
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : AbstractTransactionManagementConfiguration.java
Copyright MIT License
Author : codeEngraver
@Autowired(required = false)
void setConfigurers(Collection<TransactionManagementConfigurer> configurers) {
    if (CollectionUtils.isEmpty(configurers)) {
        return;
    }
    if (configurers.size() > 1) {
        throw new IllegalStateException("Only one TransactionManagementConfigurer may exist");
    }
    TransactionManagementConfigurer configurer = configurers.iterator().next();
    this.txManager = configurer.annotationDrivenTransactionManager();
}

18 View Complete Implementation : DataAccessUtils.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Return a single result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 element found.
 * @param results the result Collection (can be {@code null}
 * and is also expected to contain {@code null} elements)
 * @return the single result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 * @throws EmptyResultDataAccessException if no element at all
 * has been found in the given Collection
 * @since 5.0.2
 */
@Nullable
public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    // This is identical to the requiredSingleResult implementation but differs in the
    // semantics of the incoming Collection (which we currently can't formally express)
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : DataAccessUtils.java
Copyright MIT License
Author : codeEngraver
/**
 * Return a single result object from the given Collection.
 * <p>Throws an exception if 0 or more than 1 element found.
 * @param results the result Collection (can be {@code null}
 * and is also expected to contain {@code null} elements)
 * @return the single result object
 * @throws IncorrectResultSizeDataAccessException if more than one
 * element has been found in the given Collection
 * @throws EmptyResultDataAccessException if no element at all
 * has been found in the given Collection
 * @since 5.0.2
 */
@Nullable
public static <T> T nullableSingleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException {
    // This is identical to the requiredSingleResult implementation but differs in the
    // semantics of the incoming Collection (which we currently can't formally express)
    if (CollectionUtils.isEmpty(results)) {
        throw new EmptyResultDataAccessException(1);
    }
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }
    return results.iterator().next();
}

18 View Complete Implementation : NotificationListenerRegistrar.java
Copyright MIT License
Author : codeEngraver
@Override
public void afterPropertiesSet() {
    if (getNotificationListener() == null) {
        throw new IllegalArgumentException("Property 'notificationListener' is required");
    }
    if (CollectionUtils.isEmpty(this.mappedObjectNames)) {
        throw new IllegalArgumentException("Property 'mappedObjectName' is required");
    }
    prepare();
}

18 View Complete Implementation : OldVersionMigrateHandler.java
Copyright GNU General Public License v3.0
Author : halo-dev
private void createSheetCommentRecursively(@NonNull final SheetComment parentComment, List<SheetComment> sheetComments) {
    Long oldParentId = parentComment.getId();
    // Create parent
    if (!ServiceUtils.isEmptyId(parentComment.getId())) {
        SheetComment createComment = sheetCommentService.create(parentComment);
        parentComment.setId(createComment.getId());
    }
    if (CollectionUtils.isEmpty(sheetComments)) {
        return;
    }
    // Get all children
    List<SheetComment> children = sheetComments.stream().filter(sheetComment -> Objects.equals(oldParentId, sheetComment.getParentId())).collect(Collectors.toList());
    // Set parent id again
    children.forEach(postComment -> postComment.setParentId(parentComment.getId()));
    // Remove children
    sheetComments.removeAll(children);
    // Create children recursively
    children.forEach(childComment -> createSheetCommentRecursively(childComment, sheetComments));
}

18 View Complete Implementation : OldVersionMigrateHandler.java
Copyright GNU General Public License v3.0
Author : halo-dev
private void createPostCommentRecursively(@NonNull final PostComment parentComment, List<PostComment> postComments) {
    Long oldParentId = parentComment.getId();
    // Create parent
    if (!ServiceUtils.isEmptyId(parentComment.getId())) {
        PostComment createdComment = postCommentService.create(parentComment);
        log.debug("Created post comment: [{}]", createdComment);
        parentComment.setId(createdComment.getId());
    }
    if (CollectionUtils.isEmpty(postComments)) {
        return;
    }
    // Get all children
    List<PostComment> children = postComments.stream().filter(postComment -> Objects.equals(oldParentId, postComment.getParentId())).collect(Collectors.toList());
    // Set parent id again
    children.forEach(postComment -> postComment.setParentId(parentComment.getId()));
    // Remove children
    postComments.removeAll(children);
    // Create children recursively
    children.forEach(childComment -> createPostCommentRecursively(childComment, postComments));
}

18 View Complete Implementation : MenuServiceImpl.java
Copyright GNU General Public License v3.0
Author : halo-dev
private List<MenuDTO> convertTo(List<Menu> menus) {
    if (CollectionUtils.isEmpty(menus)) {
        return Collections.emptyList();
    }
    return menus.stream().map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu)).collect(Collectors.toList());
}

18 View Complete Implementation : SimpAnnotationMethodMessageHandler.java
Copyright Apache License 2.0
Author : spring-projects
@Override
protected String getLookupDestination(@Nullable String destination) {
    if (destination == null) {
        return null;
    }
    if (CollectionUtils.isEmpty(getDestinationPrefixes())) {
        return destination;
    }
    for (String prefix : getDestinationPrefixes()) {
        if (destination.startsWith(prefix)) {
            if (this.slashPathSeparator) {
                return destination.substring(prefix.length() - 1);
            } else {
                return destination.substring(prefix.length());
            }
        }
    }
    return null;
}

18 View Complete Implementation : AbstractCacheInterceptor.java
Copyright MIT License
Author : Vip-Augus
/**
 * Convert the collection of caches in a single expected element.
 * <p>Throw an {@link IllegalStateException} if the collection holds more than one element
 * @return the single element or {@code null} if the collection is empty
 */
@Nullable
static Cache extractFrom(Collection<? extends Cache> caches) {
    if (CollectionUtils.isEmpty(caches)) {
        return null;
    } else if (caches.size() == 1) {
        return caches.iterator().next();
    } else {
        throw new IllegalStateException("Unsupported cache resolution result " + caches + ": JSR-107 only supports a single cache.");
    }
}