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:gemfire.practice.domain.LineItem.java

/**
 * Creates a new {@link LineItem} for the given {@link Product} and amount.
 * //ww w  .j  a va2  s . c om
 * @param product must not be {@literal null}.
 * @param amount
 */
public LineItem(Product product, int amount) {
    Assert.notNull(product, "The given Product must not be null!");
    Assert.isTrue(amount > 0, "The amount of Products to be bought must be greater than 0!");

    productId = product.getId();
    this.amount = amount;
    price = product.getPrice();
}

From source file:cn.designthoughts.sample.axon.sfav.customer.domain.EmailAddress.java

/**
 * Creates a new {@link EmailAddress} from the given {@link String} representation.
 * //from   www . j a v  a2 s.  c  o  m
 * @param emailAddress must not be {@literal null} or empty.
 */
public EmailAddress(String emailAddress) {
    Assert.isTrue(isValid(emailAddress), "Invalid email address!");
    this.value = emailAddress;
}

From source file:fr.mby.portal.coreimpl.app.UserAppStore.java

@Override
public synchronized void storeApp(final IApp app, final HttpServletRequest request) {
    final String appSignature = app.getSignature();

    Assert.isTrue(!this.userAppStore.containsKey(appSignature),
            "UserAppStore cannot store an already stored IApp !");

    this.userAppStore.put(appSignature, app);

}

From source file:org.cleverbus.core.common.asynch.confirm.DefaultConfirmationCallback.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");

    switch (msg.getState()) {
    case OK://from w  w  w . j av  a2s .c o m
        Log.debug("Confirmation - the message " + msg.toHumanString() + " was successfully processed.");
        break;
    case FAILED:
        Log.debug("Confirmation - processing of the message " + msg.toHumanString() + " failed.");
        break;
    }
}

From source file:com.athena.chameleon.common.utils.ZipUtil.java

/**
 * <pre>/*from ww  w. ja v  a2s  .c  om*/
 * ?  ? ? .
 * </pre>
 * @param baseDir
 * @param destFile
 * @param type
 * @return
 * @throws IOException
 * @throws ManifestException 
 */
public static boolean compress(String baseDir, String destFile, ArchiveType type)
        throws IOException, ManifestException {
    Assert.notNull(baseDir, "baseDir cannot be null.");

    Project project = new Project();

    File filesetDir = new File(baseDir);
    File archiveFile = null;

    Assert.isTrue(filesetDir.exists(), baseDir + " does not exist.");
    Assert.isTrue(filesetDir.isDirectory(), baseDir + " is not a directory.");

    if (StringUtils.isEmpty(destFile)) {
        archiveFile = new File(filesetDir.getParent(),
                new StringBuilder(filesetDir.getName()).append(".").append(type.value()).toString());
    } else {
        archiveFile = new File(destFile);
    }

    FileSet fileSet = new FileSet();
    fileSet.setDir(filesetDir);
    fileSet.setProject(project); // project ?  DirectoryScanner  ?  Excption? ?.

    Zip zip = new Zip();
    zip.setProject(project); // project ?  destFile   Exception ?.
    zip.setDestfile(archiveFile);
    zip.add(fileSet);

    zip.execute();

    return true;
}

From source file:com.azaptree.services.commons.validation.ValidationException.java

public ValidationException(final ConstraintViolation<?>... constraintViolations) {
    super();//from  w w w .  j a va  2s .  c  o m
    Assert.notNull(constraintViolations, "constraintViolations is required");
    Assert.isTrue(constraintViolations.length > 0, "constraintViolations cannot be empty");

    for (final ConstraintViolation<?> v : constraintViolations) {
        this.constraintViolations.add(v);
    }
}

From source file:com.consol.citrus.ws.validation.BinarySoapAttachmentValidator.java

@Override
protected void validateAttachmentContent(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
    if (log.isDebugEnabled()) {
        log.debug("Validating binary SOAP attachment content ...");
    }/*from  w  w  w  .  j ava2s . c o m*/

    try {
        Assert.isTrue(
                IOUtils.contentEquals(receivedAttachment.getInputStream(), controlAttachment.getInputStream()),
                "Values not equal for binary attachment content '" + controlAttachment.getContentId() + "'");
    } catch (IOException e) {
        throw new CitrusRuntimeException("Binary SOAP attachment validation failed", e);
    }

    if (log.isDebugEnabled()) {
        log.debug("Validating binary SOAP attachment content: OK");
    }
}

From source file:org.obiba.onyx.core.identifier.impl.randomincrement.RandomIncrementIdentifierSequenceProvider.java

public RandomIncrementIdentifierSequenceProvider(int maxIncrement) {
    Assert.isTrue(maxIncrement >= 1, "maxIncrement must be at least 1");
    this.maxIncrement = maxIncrement;
}

From source file:com.create.mybatis.repository.query.MyBatisQueryLookupStrategy.java

/**
 * Creates a new {@link MyBatisQueryLookupStrategy} from the given domain class.
 *
 * @param mapperProvider must not be {@literal null}.
 * @param key has to be {@literal null} of {@literal Key.USE_DECLARED_QUERY}.
 *//*from w w w  .j  a  va  2  s.com*/
public MyBatisQueryLookupStrategy(final MyBatisMapperProvider mapperProvider, final Key key) {
    Assert.isTrue(key == null || Key.USE_DECLARED_QUERY.equals(key),
            "MyBatis query strategy is supported only for declared statements");
    Assert.notNull(mapperProvider);
    this.provider = mapperProvider;
}

From source file:com.icfcc.cache.ehcache.EhCacheCacheManager.java

@Override
protected Collection<Cache> loadCaches() {
    Assert.notNull(this.cacheManager, "A backing EhCache CacheManager is required");
    Status status = this.cacheManager.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' EhCache CacheManager is required - current cache is " + status.toString());

    String[] names = this.cacheManager.getCacheNames();
    Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
    for (String name : names) {
        caches.add(new EhCacheCache(this.cacheManager.getEhcache(name)));
    }//from w  ww  . j a  v  a 2 s.c o m
    return caches;
}