Example usage for org.springframework.util Assert isTrue

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.appleframework.monitor.action.AdminAction.java

@RequestMapping(value = "/admin/views/save")
public @ResponseBody WebResult createView(HttpEntity<View> entity, ModelMap map) {
    WebResult result = new WebResult();
    try {/* w ww.  j a  va  2s.  co m*/
        View view = entity.getBody();
        Assert.isTrue(view.getName().length() > 0, "name should not be null");
        logger.debug("save view ={}", view);
        viewService.saveView(view);
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
    }
    return result;
}

From source file:cz.jirutka.spring.http.client.cache.SynchronizedLruCache.java

public SynchronizedLruCache(String name, int capacity, int initialCapacity, float loadFactory) {
    Assert.hasText(name, "name should not be blank");
    Assert.isTrue(capacity > 0, "capacity must be greater then 0");

    this.name = name;
    this.capacity = capacity;

    this.store = new LinkedHashMap<Object, ValueWrapper>(initialCapacity, loadFactory, true) {
        protected boolean removeEldestEntry(Map.Entry eldest) {
            return this.size() > SynchronizedLruCache.this.capacity;
        }//w w w. j a va2  s  . com
    };
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPATest.java

@Test
public void testReadAllEntitlements() {
    List<Entitlement> entitlements = entitlementDAO.getEntitlements(0, 999);
    Assert.isTrue(30 == entitlements.size(), "Size doesn't match");
}

From source file:com.ewcms.common.query.cache.CacheResult.java

@Override
public CacheResult setPage(int page) {
    Assert.isTrue(page >= 0, "page is not < 0");
    this.page = page;
    return this;
}

From source file:com.oreilly.springdata.mongodb.core.Product.java

/**
 * Creates a new {@link Product} from the given name and description.
 * // w  w w .  j a va2s.  c  o  m
 * @param name must not be {@literal null} or empty.
 * @param price must not be {@literal null} or less than or equal to zero.
 * @param description
 */
@PersistenceConstructor
public Product(String name, BigDecimal price, String description) {

    Assert.hasText(name, "Name must not be null or empty!");
    Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!");

    this.name = name;
    this.price = price;
    this.description = description;
}

From source file:org.cleverbus.core.common.asynch.confirm.DelegateConfirmationCallback.java

@Override
public void confirm(Message msg) {
    Assert.notNull(msg, "Message must not be null");
    Assert.isTrue(ALLOWED_STATES.contains(msg.getState()), "Message must be in a final state to be confirmed");

    ExternalSystemConfirmation impl = getImplementation(msg.getSourceSystem());
    if (impl != null) {
        impl.confirm(msg);/*from  ww  w  . j  a  v  a2  s.c  o  m*/
    } else {
        Log.debug("Confirmation {} - no suitable ExternalSystemConfirmation implementation "
                + "for the following external system: {}", msg.getState(), msg.getSourceSystem());
    }
}

From source file:com.stehno.sanctuary.core.scan.DefaultDirectoryScanner.java

/**
 * Scans the given directory for changes. The directory passed in will be used as the root
 * of the changeset and the stored files.
 * /* w  w  w . j  a  v a  2  s.c o  m*/
 * @param directory
 * @return a populated change set.
 */
@Override
public ChangeSet scanDirectory(final File directory) {
    Assert.isTrue(directory != null && directory.isDirectory(), "A non-null directory must be specified.");

    if (log.isDebugEnabled())
        log.debug("Scanning: " + directory);

    final ChangeSet changeSet = new ChangeSet(directory);

    final Queue<File> directories = new LinkedList<File>();
    directories.add(directory);

    while (!directories.isEmpty()) {
        final File scanningDir = directories.poll();

        for (final File item : scanningDir.listFiles()) {
            if (item.isDirectory()) {
                directories.add(item);
            } else {
                changeSet.addFileStatus(localStore.fileStatus(item), item);
            }
        }
    }

    // figure out the deleted files
    for (final String path : localStore.listFilePaths()) {
        final File file = new File(path);
        if (!file.exists()) {
            changeSet.addFileStatus(FileStatus.DELETED, file);
        }
    }

    return changeSet;
}

From source file:example.app.repo.gemfire.support.CustomerRepositoryImpl.java

@SuppressWarnings("unchecked")
protected List<Customer> toCustomerList(List<?> list) {
    Assert.notNull(list, "List cannot be null");

    if (list.size() != 1) {
        throw new IncorrectResultSizeDataAccessException(1, list.size());
    }//from w ww . j a  v  a 2  s  .c om

    Assert.isTrue(list.get(0) instanceof List, "Expected a List of Lists");

    return (List<Customer>) list.get(0);
}

From source file:com.azaptree.services.domain.entity.dao.JDBCVersionedEntityDAOSupport.java

/**
 * /* w ww.  ja v  a2  s. c  om*/
 * @param entity
 * 
 * @throws ObjectNotFoundException
 *             if the entity does not exist in the database
 */
protected void validateForUpdate(VersionedEntity entity) {
    Assert.notNull(entity, "entity is required");
    Assert.notNull(entity.getEntityId(), "entityId must not be null");
    Assert.notNull(entity.getEntityCreatedOn(), "entityCreatedOn must not be null");
    Assert.isTrue(entity.getEntityVersion() > 0, "entityVersion must be > 0");

    if (!exists(entity.getEntityId())) {
        throw new ObjectNotFoundException();
    }

}

From source file:com.jaxio.celerio.configuration.database.IndexHolder.java

public Index getIndex() {
    Assert.isTrue(isSimple(), "Can be invoked only on simple index");
    return getIndexes().iterator().next();
}