Example usage for org.springframework.util Assert notEmpty

List of usage examples for org.springframework.util Assert notEmpty

Introduction

In this page you can find the example usage for org.springframework.util Assert notEmpty.

Prototype

public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSupplier) 

Source Link

Document

Assert that a Map contains entries; that is, it must not be null and must contain at least one entry.

Usage

From source file:org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.java

/**
 * Perform a scan within the specified base packages. Note that {@link #refresh()}
 * must be called in order for the context to fully process the new class.
 * @param basePackages the packages to check for annotated classes
 * @see #register(Class...)/*from   www  .  j a va2 s .  c  om*/
 * @see #refresh()
 */
@Override
public final void scan(String... basePackages) {
    Assert.notEmpty(basePackages, "At least one base package must be specified");
    this.basePackages = basePackages;
}

From source file:org.springframework.cache.interceptor.CacheAspectSupport.java

/**
 * Set one or more cache operation sources which are used to find the cache
 * attributes. If more than one source is provided, they will be aggregated
 * using a {@link CompositeCacheOperationSource}.
 *//*from www  .  j  av  a  2  s.co  m*/
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
    Assert.notEmpty(cacheOperationSources, "At least 1 CacheOperationSource needs to be specified");
    this.cacheOperationSource = (cacheOperationSources.length > 1
            ? new CompositeCacheOperationSource(cacheOperationSources)
            : cacheOperationSources[0]);
}

From source file:org.springframework.cloud.dataflow.app.launcher.MultiArchiveLauncher.java

/**
 * A list of archives, the first of which is expected to be a Spring boot uberJar
 * //w w w .ja v  a 2 s .c om
 * @param archives
 */
public MultiArchiveLauncher(List<Archive> archives) {
    Assert.notEmpty(archives, "A list of archives must be provided");
    this.archives = archives;
}

From source file:org.springframework.cloud.stream.app.twitter.sentiment.processor.TwitterSentimentTensorflowInputConverter.java

private Map<String, Object> getStringObjectMap(Map jsonMap) {
    Assert.notNull(jsonMap, "Failed to parse the Tweet json!");

    String tweetText = (String) jsonMap.get(TWEET_TEXT_TAG);

    if (isEmpty(tweetText)) {
        logger.warn("Tweet with out text: " + jsonMap.get(TWEET_ID_TAG));
        tweetText = "";
    }//from  www .  j  a v  a2  s . co  m

    int[][] tweetVector = wordVocabulary.vectorizeSentence(tweetText);

    Assert.notEmpty(tweetVector, "Failed to vectorize the tweet text: " + tweetText);

    Map<String, Object> response = new HashMap<>();
    response.put(DATA_IN, tweetVector);
    response.put(DROPOUT_KEEP_PROB, DROPOUT_KEEP_PROB_VALUE);

    return response;
}

From source file:org.springframework.cloud.stream.binding.BindableProxyFactory.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notEmpty(BindableProxyFactory.this.bindingTargetFactories,
            "'bindingTargetFactories' cannot be empty");
    ReflectionUtils.doWithMethods(this.type, new ReflectionUtils.MethodCallback() {
        @Override//ww w.  j a va 2 s.co m
        public void doWith(Method method) throws IllegalArgumentException {
            Input input = AnnotationUtils.findAnnotation(method, Input.class);
            if (input != null) {
                String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(input, method);
                Class<?> returnType = method.getReturnType();
                Object sharedBindingTarget = locateSharedBindingTarget(name, returnType);
                if (sharedBindingTarget != null) {
                    BindableProxyFactory.this.inputHolders.put(name,
                            new BoundTargetHolder(sharedBindingTarget, false));
                } else {
                    BindableProxyFactory.this.inputHolders.put(name,
                            new BoundTargetHolder(getBindingTargetFactory(returnType).createInput(name), true));
                }
            }
        }
    });
    ReflectionUtils.doWithMethods(this.type, new ReflectionUtils.MethodCallback() {
        @Override
        public void doWith(Method method) throws IllegalArgumentException {
            Output output = AnnotationUtils.findAnnotation(method, Output.class);
            if (output != null) {
                String name = BindingBeanDefinitionRegistryUtils.getBindingTargetName(output, method);
                Class<?> returnType = method.getReturnType();
                Object sharedBindingTarget = locateSharedBindingTarget(name, returnType);
                if (sharedBindingTarget != null) {
                    BindableProxyFactory.this.outputHolders.put(name,
                            new BoundTargetHolder(sharedBindingTarget, false));
                } else {
                    BindableProxyFactory.this.outputHolders.put(name, new BoundTargetHolder(
                            getBindingTargetFactory(returnType).createOutput(name), true));
                }
            }
        }
    });
}

From source file:org.springframework.core.annotation.AnnotationUtils.java

/**
 * Find the first {@link Class} in the inheritance hierarchy of the
 * specified {@code clazz} (including the specified {@code clazz} itself)
 * on which at least one of the specified {@code annotationTypes} is
 * <em>directly present</em>.
 * <p>If the supplied {@code clazz} is an interface, only the interface
 * itself will be checked; the inheritance hierarchy for interfaces will
 * not be traversed./*from w  ww  .  j av a 2 s . co m*/
 * <p>Meta-annotations will <em>not</em> be searched.
 * <p>The standard {@link Class} API does not provide a mechanism for
 * determining which class in an inheritance hierarchy actually declares
 * one of several candidate {@linkplain Annotation annotations}, so we
 * need to handle this explicitly.
 * @param annotationTypes the annotation types to look for
 * @param clazz the class to check for the annotations on, or {@code null}
 * @return the first {@link Class} in the inheritance hierarchy that
 * declares an annotation of at least one of the specified
 * {@code annotationTypes}, or {@code null} if not found
 * @since 3.2.2
 * @see Class#isAnnotationPresent(Class)
 * @see Class#getDeclaredAnnotations()
 * @see #findAnnotationDeclaringClass(Class, Class)
 * @see #isAnnotationDeclaredLocally(Class, Class)
 */
@Nullable
public static Class<?> findAnnotationDeclaringClassForTypes(List<Class<? extends Annotation>> annotationTypes,
        @Nullable Class<?> clazz) {
    Assert.notEmpty(annotationTypes, "List of annotation types must not be empty");
    if (clazz == null || Object.class == clazz) {
        return null;
    }
    for (Class<? extends Annotation> annotationType : annotationTypes) {
        if (isAnnotationDeclaredLocally(annotationType, clazz)) {
            return clazz;
        }
    }
    return findAnnotationDeclaringClassForTypes(annotationTypes, clazz.getSuperclass());
}

From source file:org.springframework.core.env.AbstractEnvironment.java

@Override
public boolean acceptsProfiles(String... profiles) {
    Assert.notEmpty(profiles, "Must specify at least one profile");
    for (String profile : profiles) {
        if (StringUtils.hasLength(profile) && profile.charAt(0) == '!') {
            if (!isProfileActive(profile.substring(1))) {
                return true;
            }//from  ww  w . ja v a2 s. c o  m
        } else if (isProfileActive(profile)) {
            return true;
        }
    }
    return false;
}

From source file:org.springframework.data.gemfire.config.annotation.support.GemFireComponentClassTypeScanner.java

/**
 * Constructs an instance of the {@link GemFireComponentClassTypeScanner} initialized with
 * the given {@link Set} of base packages to scan.
 *
 * @param basePackages {@link Set} of base packages to scan for GemFire component clases.
 * @throws IllegalArgumentException if the {@link Set} is {@literal null} or empty.
 * @see java.util.Set/* w  w  w .  ja  v  a  2s . co m*/
 */
protected GemFireComponentClassTypeScanner(Set<String> basePackages) {
    Assert.notEmpty(basePackages, "Base packages is required");
    this.basePackages = basePackages;
}

From source file:org.springframework.data.gemfire.examples.OrderService.java

/**
 * Create an order//ww  w .  j  a va 2  s  .co m
 * @param order
 * @return
 */
public Order createOrder(Order order) {
    Assert.notNull(order, "order cannot be null");
    Assert.notNull(order.getId(), "order ID cannot be null");
    Assert.notNull(order.getCustomerId(), "order customer ID cannot be null");
    Assert.notEmpty(order.getLineItems(), "order must contain at least one line item");
    Assert.notNull(order.getBillingAddress(), "order billing address cannot be null");

    log.debug("creating new order " + order.getId());
    return orderRepository.save(order);
}

From source file:org.springframework.data.hadoop.fs.DistCp.java

/**
 * Initiate a copy operation using a command-line style (arguments are
 * specified as {@link String}s)./*from  w w w  .  j a v a  2  s.  c  o  m*/
 * 
 * @param arguments the copy arguments
 */
public void copy(String... arguments) {
    Assert.notEmpty(arguments, "invalid number of arguments");
    // sanitize the arguments
    final List<String> parsedArguments = new ArrayList<String>();
    for (String arg : arguments) {
        parsedArguments.addAll(Arrays.asList(StringUtils.tokenizeToStringArray(arg, " ")));
    }

    try {
        if (StringUtils.hasText(user)) {
            UserGroupInformation ugi = UserGroupInformation.createProxyUser(user,
                    UserGroupInformation.getLoginUser());
            ugi.doAs(new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    invokeCopy(configuration, parsedArguments.toArray(new String[parsedArguments.size()]));
                    return null;
                }
            });
        } else {
            invokeCopy(configuration, parsedArguments.toArray(new String[parsedArguments.size()]));
        }
    } catch (Exception ex) {
        throw new IllegalStateException("Cannot run distCp impersonated as '" + user + "'", ex);
    }
}