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.icfcc.cache.ehcache.EhCacheCache.java

/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache backing Ehcache instance
 *///w  w w.  j a  v a2s .c o  m
public EhCacheCache(Ehcache ehcache) {
    Assert.notNull(ehcache, "Ehcache must not be null");
    Status status = ehcache.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' Ehcache is required - current cache is " + status.toString());
    this.cache = ehcache;
}

From source file:org.cloudfoundry.client.lib.archive.DirectoryApplicationArchive.java

public DirectoryApplicationArchive(File directory) {
    Assert.notNull(directory, "Directory must not be null");
    Assert.isTrue(directory.isDirectory(), "File must reference a directory");
    this.directory = directory;
    List<Entry> entries = new ArrayList<Entry>();
    collectEntries(entries, directory);/*from w  ww. j  a v  a 2 s .  c  o  m*/
    this.entries = Collections.unmodifiableList(entries);
}

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

@CacheResult(cacheName = "Factorials")
public long factorial(long number) {
    setCacheMiss();/*w w  w  .  j  ava  2s  .c  om*/

    Assert.isTrue(number >= 0L, String.format("Number [%d] must be greater than equal to 0", number));

    if (number <= 2L) {
        return (number < 2L ? 1L : 2L);
    }

    long result = number;

    while (--number > 1L) {
        result *= number;
    }

    return result;
}

From source file:com.athena.peacock.common.core.util.ZipUtil.java

/**
 * <pre>// w ww  .  j  a v a  2 s.  co  m
 * ?  ? ? .
 * </pre>
 * @param baseDir
 * @param destFile
 * @return
 * @throws IOException
 * @throws ManifestException 
 */
public static String compress(String baseDir, String destFile) 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(".zip").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 archiveFile.getAbsolutePath();
}

From source file:br.com.insula.spring.security.janrain.Janrain.java

public String getTokenUrl(HttpServletRequest request, String path) {
    Assert.notNull(request, "'request' cannot be null");
    Assert.notNull(request, "'path' cannot be null");
    Assert.isTrue(path.startsWith("/"), "path must start with '/'");
    String scheme = request.getScheme();
    int serverPort = request.getServerPort();
    if (isRequestInDefaultPort(scheme, serverPort)) {
        return String.format("%s://%s%s", scheme, request.getServerName(), path);
    } else {//from   ww  w .  ja  va2 s .  co m
        return String.format("%s://%s:%d%s", scheme, request.getServerName(), serverPort, path);
    }
}

From source file:com.frank.search.solr.core.query.SimpleFacetQuery.java

@SuppressWarnings("unchecked")
@Override//from   w w w  .  j a v  a 2s.co m
public final <T extends SolrDataQuery> T setFacetOptions(FacetOptions facetOptions) {
    if (facetOptions != null) {
        Assert.isTrue(facetOptions.hasFacets(), "Cannot set facet options having neither fields nor queries.");
    }
    this.facetOptions = facetOptions;
    return (T) this;
}

From source file:com.jaxio.celerio.model.primarykey.CompositePrimaryKey.java

public CompositePrimaryKey(Entity entity, List<Attribute> attributes) {
    super(entity, ClassType.primaryKey);
    Assert.notNull(entity);// w w  w .j a va 2  s .c  o m
    Assert.isTrue(attributes.size() > 1, "Composite PK must have at least 2 attributes");
    for (Attribute attribute : attributes) {
        attribute.setInCpk(true);
    }
    this.attributes = unmodifiableList(attributes);
    this.entity = entity;
}

From source file:grails.plugin.springsecurity.web.access.channel.HeaderCheckInsecureChannelProcessor.java

@Override
public void decide(FilterInvocation invocation, Collection<ConfigAttribute> config)
        throws IOException, ServletException {

    Assert.isTrue(invocation != null && config != null, "Nulls cannot be provided");

    for (ConfigAttribute attribute : config) {
        if (supports(attribute)) {
            if (headerValue.equals(invocation.getHttpRequest().getHeader(headerName))) {
                getEntryPoint().commence(invocation.getRequest(), invocation.getResponse());
            }/*from   w w  w .  ja v a  2  s .c  om*/
        }
    }
}

From source file:com.mike.angry.dm.DataModel.java

public List<Digital> getBySquareNum(int num) {
    List<Digital> result = new ArrayList<Digital>();
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            if (bigSquare[i][j].getSquareNum() == num) {
                result.add(bigSquare[i][j]);
            }//from  www  .  j  a  va  2s. co m
        }
    }

    Assert.isTrue(result.size() == 9,
            "one square num should be 9! num " + num + "result.size()" + result.size());

    return result;
}

From source file:io.lavagna.common.QueryFactory.java

private static QueryTypeAndQuery extractQueryAnnotation(Class<?> clazz, String activeDb, Method method) {
    Query q = method.getAnnotation(Query.class);
    QueriesOverride qs = method.getAnnotation(QueriesOverride.class);

    Assert.isTrue(q != null, String.format("missing @Query annotation for method %s in interface %s",
            method.getName(), clazz.getSimpleName()));
    // only one @Query annotation, thus we return the value without checking the database
    if (qs == null) {
        return new QueryTypeAndQuery(q.type(), q.value());
    }/*from   w  w  w . j  a v a  2s . c  om*/

    for (QueryOverride query : qs.value()) {
        if (query.db().equals(activeDb)) {
            return new QueryTypeAndQuery(q.type(), query.value());
        }
    }

    return new QueryTypeAndQuery(q.type(), q.value());
}