Example usage for org.springframework.util Assert state

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

Introduction

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

Prototype

public static void state(boolean expression, Supplier<String> messageSupplier) 

Source Link

Document

Assert a boolean expression, throwing an IllegalStateException if the expression evaluates to false .

Usage

From source file:com.excilys.ebi.bank.dao.impl.AccountDaoImpl.java

@Override
public boolean isAccountOfUser(Integer id, String login) {
    long count = from(account).join(account.users, user).where(account.id.eq(id), user.login.eq(login))
            .countDistinct();/*  w  w w  . j a  v a  2  s. co m*/
    Assert.state(count <= 1, "Shouldn't count more than one account");
    return count > 0;
}

From source file:org.cloudfoundry.identity.uaa.openid.UserInfoEndpoint.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.state(userDatabase != null, "A user database must be provided");
}

From source file:example.app.caching.provider.support.AbstractJsr107CachingProviderTests.java

@SuppressWarnings("all")
protected <T> T getNativeCache(String name) {
    Cache cache = getCache(name);/*w  w  w .  j  a  v  a2  s.c om*/
    Assert.state(cache != null, String.format("Cache [%s] not found", name));
    return (T) cache.getNativeCache();
}

From source file:org.kuali.maven.plugins.graph.validate.DependencyNodeValidator.java

@Override
public void validate(Node<MavenContext> node) {
    List<Node<MavenContext>> list = node.getBreadthFirstList();
    List<DependencyNode> nodes = new ArrayList<DependencyNode>();
    for (Node<MavenContext> element : list) {
        DependencyNode dn = element.getObject().getDependencyNode();
        Assert.state(dn.getArtifact() != null, "Artifact for a dependency node can't be null");
        State elementState = State.getState(dn.getState());
        if (state == elementState) {
            nodes.add(dn);/*w  w  w . jav  a  2s . c om*/
        }
    }
    validateState(nodes);
}

From source file:de.langmi.spring.batch.examples.readers.file.multiresourcepartitioner.CustomMultiResourcePartitioner.java

/**
 * Assign the filename of each of the injected resources to an
 * {@link ExecutionContext}.//from  ww w.  ja  va 2 s.co m
 * 
 * @see Partitioner#partition(int)
 */
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
    Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
    int i = 0;
    for (Resource resource : resources) {
        ExecutionContext context = new ExecutionContext();
        Assert.state(resource.exists(), "Resource does not exist: " + resource);
        try {
            context.putString(inputKeyName, resource.getURL().toExternalForm());
            context.put(outputKeyName, createOutputFilename(i, resource));
        } catch (IOException e) {
            throw new IllegalArgumentException("File could not be located for: " + resource, e);
        }
        map.put(PARTITION_KEY + i, context);
        i++;
    }
    return map;
}

From source file:org.spring.data.gemfire.config.ForceGemFireSubRegionCreationBeanPostProcessor.java

protected ApplicationContext getApplicationContext() {
    Assert.state(applicationContext != null,
            "The reference to the ApplicationContext was not initialized properly!");
    return applicationContext;
}

From source file:com.apporiented.spring.override.MapMergeProcessor.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    BeanDefinition bd = beanFactory.getBeanDefinition(ref);
    if (property == null) {
        Assert.state(MapFactoryBean.class.getName().equals(bd.getBeanClassName()),
                "Bean [" + ref + "] must be a MapFactoryBean");

        property = "sourceMap";
    }/*from  www . j a  v  a  2s. c  o  m*/

    if (log.isInfoEnabled()) {
        String keys = StringUtils.collectionToCommaDelimitedString(entries.keySet());
        log.debug("Adding [" + keys + "] to " + ref + "." + property);
    }

    PropertyValue pv = bd.getPropertyValues().getPropertyValue(property);
    if (pv == null) {
        // No map set on the target bean, create a new one ...
        ManagedMap map = new ManagedMap();
        map.putAll(entries);
        bd.getPropertyValues().addPropertyValue(property, map);
    } else {
        Object value = pv.getValue();
        if (value instanceof RuntimeBeanReference) {
            RuntimeBeanReference ref = (RuntimeBeanReference) value;
            value = beanFactory.getBean(ref.getBeanName());
        }
        Assert.isInstanceOf(Map.class, value);
        Map map = (Map) value;
        map.putAll(entries);
    }
}

From source file:example.app.service.ContactsService.java

protected example.app.repo.gemfire.ContactRepository getGemFireContactRepository() {
    Assert.state(gemfireContactRepository != null, "GemFire ContactRepository was not properly initialized");
    return gemfireContactRepository;
}

From source file:com.oreilly.springdata.neo4j.order.Order.java

public Order withShippingAddress(Address shippingAddress) {
    Assert.state(customer.hasAddress(shippingAddress), "valid customer address for " + customer);
    this.shippingAddress = shippingAddress;
    return this;
}