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.nortal.petit.orm.statement.BeansStatement.java

protected void prepareSet() {
    Assert.isTrue(!(setBy == null || setBy.isEmpty()),
            "BeansStatement.prepareSet: setBy columns are mandatory");
    getStatementBuilder().setBy(setBy);/*w  w w. j  a  v  a2  s. c o  m*/
    getStatementBuilder().setWith(prepareSetWith());
}

From source file:gov.nih.nci.cabig.ctms.acegi.acls.dao.impl.BasicAclLookupStrategy.java

public Map readAclsById(ObjectIdentity[] objects, Sid[] sids) {

    Assert.isTrue(batchSize >= 1, "BatchSize must be >= 1");
    Assert.notEmpty(objects, "Objects to lookup required");

    // Map<ObjectIdentity,Acl>
    Map result = new HashMap(); // contains FULLY loaded Acl objects

    Set currentBatchToLoad = new HashSet(); // contains ObjectIdentitys

    for (int i = 0; i < objects.length; i++) {
        // Check we don't already have this ACL in the results
        if (result.containsKey(objects[i])) {
            continue; // already in results, so move to next element
        }//from w ww  .ja v  a2s.  c  o m

        // Check cache for the present ACL entry
        Acl acl = aclCache.getFromCache(objects[i]);

        // Ensure any cached element supports all the requested SIDs
        // (they should always, as our base impl doesn't filter on SID)
        if (acl != null) {
            if (acl.isSidLoaded(sids)) {
                result.put(acl.getObjectIdentity(), acl);

                continue; // now in results, so move to next element
            } else {
                throw new IllegalStateException(
                        "Error: SID-filtered element detected when implementation does not perform SID filtering - have you added something to the cache manually?");
            }
        }

        // To get this far, we have no choice but to retrieve it from DB
        // (although we don't do it until we get a batch of them to load)
        currentBatchToLoad.add(objects[i]);

        // Is it time to load from DB the currentBatchToLoad?
        if ((currentBatchToLoad.size() == this.batchSize) || ((i + 1) == objects.length)) {
            Map loadedBatch = lookupObjectIdentities(
                    (ObjectIdentity[]) currentBatchToLoad.toArray(new ObjectIdentity[] {}), sids);

            // Add loaded batch (all elements 100% initialized) to results
            result.putAll(loadedBatch);

            // Add the loaded batch to the cache
            Iterator loadedAclIterator = loadedBatch.values().iterator();

            while (loadedAclIterator.hasNext()) {
                aclCache.putInCache((AclImpl) loadedAclIterator.next());
            }

            currentBatchToLoad.clear();
        }
    }

    // Now we're done, check every requested object identity was found
    // (throw NotFoundException if needed)
    for (int i = 0; i < objects.length; i++) {
        if (!result.containsKey(objects[i])) {
            throw new NotFoundException(
                    "Unable to find ACL information for object identity '" + objects[i].toString() + "'");
        }
    }

    return result;

}

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

public final void setMemberName(final String memberName) {
    Assert.isTrue(StringUtils.hasText(memberName), "The GemFire Locator member name must be specified!");
    this.memberName = memberName;
}

From source file:com.crossover.trial.weather.domain.Airport.java

public double calculateDistance(Airport toAirport) {
    Assert.isTrue(toAirport != null, "airport is required");
    double deltaLat = Math.toRadians(toAirport.latitude - latitude);
    double deltaLon = Math.toRadians(toAirport.longitude - longitude);
    double a = Math.pow(Math.sin(deltaLat / 2), 2)
            + Math.pow(Math.sin(deltaLon / 2), 2) * Math.cos(latitude) * Math.cos(toAirport.latitude);
    double c = 2 * Math.asin(Math.sqrt(a));
    return EARTH_RADIUS * c;
}

From source file:grails.plugin.cache.gemfire.GrailsGemfireCacheManager.java

protected Collection<Cache> loadCaches() {
    Assert.notNull(gemfireCache, "a backing GemFire cache is required");
    Assert.isTrue(!gemfireCache.isClosed(), "the GemFire cache is closed; an open instance is required");

    Set<Region<?, ?>> regions = gemfireCache.rootRegions();
    Collection<Cache> caches = new LinkedHashSet<Cache>(regions.size());
    for (Region<?, ?> region : regions) {
        caches.add(new GrailsGemfireCache(region));
    }/*from  w ww .j  a va 2 s.  c  om*/

    return caches;
}

From source file:com.silentwu.schedule.component.WebAnalyzeService.java

public List<Schedule> findScheduleFromHtml(String cityId, String cityName, String targetName, String searchDate)
        throws IOException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("cityId", cityId);
    params.put("cityName", cityName);
    params.put("targetNmae", targetName);
    params.put("searchDate", searchDate);
    String html = HttpUtils.doGet(SCHEDULE_URL, params);

    Map<String, Object> map = htmlConvertToMap(html);
    Assert.isTrue((Boolean) map.get("success"), "?");

    List<Schedule> schedules = new ArrayList<Schedule>();
    for (Object schedule : (ArrayList) map.get("data")) {
        schedules.add(fromMap((Map) schedule));
    }//from   w ww  .j  av  a  2 s .  c o m
    Assert.notEmpty(schedules, "?");
    return schedules;
}

From source file:com.trenako.web.images.WebImageServiceImpl.java

@Override
public void saveImageWithThumb(UploadRequest req, int size) {
    Assert.notNull(req, "Upload request must be not null");
    Assert.isTrue(size > 0, "Thumbnail size must be positive");

    try {//  w  ww .  ja v a  2 s.  c  om
        repo.store(converter.createImage(req.getFile(), req.asMetadata(false)));
        repo.store(converter.createThumbnail(req.getFile(), req.asMetadata(true), size));
    } catch (IOException ioEx) {
        throw new UploadSavingException("Error occurred uploading the file.", ioEx);
    }
}

From source file:org.springmodules.validation.bean.conf.loader.annotation.handler.LengthValidationAnnotationHandler.java

protected void validateMinMax(int min, int max, Class clazz, String propertyName) {
    Assert.isTrue(max >= 0, "@Length annotation on property '" + clazz.getName() + "." + propertyName
            + "' is mal-configured - 'max' attribute cannot hold a negative value");
    Assert.isTrue(min >= 0, "@Length annotation on property '" + clazz.getName() + "." + propertyName
            + "' is mal-configured - 'min' attribute cannot hold a negative value");
    Assert.isTrue(max >= min, "@Length annotation on property '" + clazz.getName() + "." + propertyName
            + "' is mal-configured - 'max' attribute is smaller than 'min'");
}