Example usage for org.springframework.util Assert noNullElements

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

Introduction

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

Prototype

public static void noNullElements(@Nullable Collection<?> collection, Supplier<String> messageSupplier) 

Source Link

Document

Assert that a collection contains no null elements.

Usage

From source file:com.frank.search.solr.SolrRealtimeGetRequest.java

public SolrRealtimeGetRequest(Collection<? extends Serializable> ids) {
    super(METHOD.GET, "/get");

    Assert.notEmpty(ids, "At least one 'id' is required for real time get request.");
    Assert.noNullElements(ids.toArray(), "Real time get request can't be made for 'null' id.");

    toStringIds(ids);/*from  w ww .  j ava  2 s.  co  m*/
}

From source file:com.oembedler.moon.graphql.engine.StereotypeUtils.java

private static <T extends Annotation> String getAnnotationValue(AnnotatedElement accessibleObject,
        Class<T> annotationClass, String defaultValue) {
    Assert.noNullElements(new Object[] { accessibleObject, annotationClass, defaultValue },
            "input parameters must not be null");

    String result = defaultValue;
    T annotation = accessibleObject.getAnnotation(annotationClass);
    if (annotation != null && StringUtils.hasText((String) AnnotationUtils.getValue(annotation)))
        result = (String) AnnotationUtils.getValue(annotation);

    return result;
}

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

/**
 * Creates new instance faceting on fields with given name
 * /* www  . j av a2  s. co  m*/
 * @param fieldnames
 */
public FacetOptions(String... fieldnames) {
    Assert.notNull(fieldnames, "Fields must not be null.");
    Assert.noNullElements(fieldnames, "Cannot facet on null fieldname.");

    for (String fieldname : fieldnames) {
        addFacetOnField(fieldname);
    }
}

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

/**
 * Creates new instance faceting on given fields
 * //from www  .ja v  a 2s  .com
 * @param fieldnames
 */
public FacetOptions(Field... fields) {
    Assert.notNull(fields, "Fields must not be null.");
    Assert.noNullElements(fields, "Cannot facet on null field.");

    for (Field field : fields) {
        addFacetOnField(field);
    }
}

From source file:rasmantuta.testutil.PopulatedTemporaryFolder.java

public PopulatedTemporaryFolder(String[] resources) {
    Assert.notNull(resources, "resources can not be null.");
    Assert.noNullElements(resources, "resources can not contain null elements.");
    this.resources = resources;
}

From source file:net.projectmonkey.spring.acl.service.SimpleACLService.java

@Override
public Map<ObjectIdentity, Acl> readAclsById(final List<ObjectIdentity> identities, final List<Sid> sids)
        throws NotFoundException {
    Assert.notNull(identities, "At least one Object Identity required");
    Assert.isTrue(identities.size() > 0, "At least one Object Identity required");
    Assert.noNullElements(identities.toArray(new ObjectIdentity[0]),
            "Null object identities are not permitted");

    Map<ObjectIdentity, Acl> result = aclRepository.getAclsById(identities, sids);

    /*//  w  ww .jav  a 2s . co  m
     * Check we found an ACL for every requested object. Where ACL's do not
     * exist for some objects throw a suitable exception.
     */
    Set<ObjectIdentity> remainingIdentities = new HashSet<ObjectIdentity>(identities);
    if (result.size() != remainingIdentities.size()) {
        remainingIdentities.removeAll(result.keySet());
        throw new NotFoundException(
                "Unable to find ACL information for object identities '" + remainingIdentities + "'");
    }
    return result;
}

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

/**
 * Creates new instance faceting on given queries
 * /*w  w  w  .ja  v a2 s. c o  m*/
 * @param facetQueries
 */
public FacetOptions(SolrDataQuery... facetQueries) {
    Assert.notNull(facetQueries, "Facet Queries must not be null.");
    Assert.noNullElements(facetQueries, "Cannot facet on null query.");

    this.facetQueries.addAll(Arrays.asList(facetQueries));
}

From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java

/**
 * Reads config locations from initParameter.
 * @param context the web application context.
 * @param initParameter the init parameter.
 * @return the array of config locations.
 *//*w w  w .  j  a va 2 s.c  o  m*/
private String[] getConfigLocations(WebApplicationContext context, String initParameter) {
    String[] configLocations = null;
    if (initParameter != null) {
        final String[] locations = StringUtils.tokenizeToStringArray(initParameter, CONFIG_LOCATION_DELIMITERS);
        if (locations != null) {
            Assert.noNullElements(locations, "Config locations must not be null");
            configLocations = new String[locations.length];
            for (int i = 0; i < locations.length; i++) {
                configLocations[i] = context.getEnvironment().resolveRequiredPlaceholders(locations[i]).trim();
            }
        }
    }
    return configLocations != null ? configLocations : getDefaultConfigLocations();
}

From source file:com.github.vanroy.springdata.jest.CriteriaFilterProcessor.java

private QueryBuilder processCriteriaEntry(OperationKey key, Object value, String fieldName) {
    if (value == null) {
        return null;
    }//from w w w.j a v a 2s.c  om
    QueryBuilder filter = null;

    switch (key) {
    case WITHIN: {
        GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(fieldName);

        Assert.isTrue(value instanceof Object[],
                "Value of a geo distance filter should be an array of two values.");
        Object[] valArray = (Object[]) value;
        Assert.noNullElements(valArray, "Geo distance filter takes 2 not null elements array as parameter.");
        Assert.isTrue(valArray.length == 2, "Geo distance filter takes a 2-elements array as parameter.");
        Assert.isTrue(
                valArray[0] instanceof GeoPoint || valArray[0] instanceof String
                        || valArray[0] instanceof Point,
                "First element of a geo distance filter must be a GeoPoint, a Point or a String");
        Assert.isTrue(valArray[1] instanceof String || valArray[1] instanceof Distance,
                "Second element of a geo distance filter must be a String or a Distance");

        StringBuilder dist = new StringBuilder();

        if (valArray[1] instanceof Distance) {
            extractDistanceString((Distance) valArray[1], dist);
        } else {
            dist.append((String) valArray[1]);
        }

        if (valArray[0] instanceof GeoPoint) {
            GeoPoint loc = (GeoPoint) valArray[0];
            geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString())
                    .geoDistance(GeoDistance.PLANE);
        } else if (valArray[0] instanceof Point) {
            GeoPoint loc = GeoPoint.fromPoint((Point) valArray[0]);
            geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString())
                    .geoDistance(GeoDistance.PLANE);
        } else {
            String loc = (String) valArray[0];
            if (loc.contains(",")) {
                String c[] = loc.split(",");
                geoDistanceQueryBuilder.lat(Double.parseDouble(c[0])).lon(Double.parseDouble(c[1]))
                        .distance(dist.toString()).geoDistance(GeoDistance.PLANE);
            } else {
                geoDistanceQueryBuilder.geohash(loc).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
            }
        }
        filter = geoDistanceQueryBuilder;

        break;
    }

    case BBOX: {
        filter = QueryBuilders.geoBoundingBoxQuery(fieldName);

        Assert.isTrue(value instanceof Object[],
                "Value of a boundedBy filter should be an array of one or two values.");
        Object[] valArray = (Object[]) value;
        Assert.noNullElements(valArray, "Geo boundedBy filter takes a not null element array as parameter.");

        if (valArray.length == 1) {
            //GeoEnvelop
            oneParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray[0]);
        } else if (valArray.length == 2) {
            //2x GeoPoint
            //2x String
            twoParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray);
        } else {
            //error
            Assert.isTrue(false,
                    "Geo distance filter takes a 1-elements array(GeoBox) or 2-elements array(GeoPoints or Strings(format lat,lon or geohash)).");
        }
        break;
    }
    }

    return filter;
}