List of usage examples for org.springframework.util Assert notNull
public static void notNull(@Nullable Object object, Supplier<String> messageSupplier)
From source file:Main.java
/** * Checks in under a given root element whether it can find a child element * which matches the name supplied. Returns {@link Element} if exists. * //from www . j a va 2 s. c om * @param name the Element name (required) * @param root the parent DOM element (required) * * @return the Element if discovered */ public static Element findFirstElementByName(String name, Element root) { Assert.hasText(name, "Element name required"); Assert.notNull(root, "Root element required"); return (Element) root.getElementsByTagName(name).item(0); }
From source file:com.devnexus.ting.model.AuthorityType.java
public static AuthorityType fromId(Long presentationTypeId) { Assert.notNull(presentationTypeId, "Parameter roleTypeId, must not be null."); for (AuthorityType presentationType : AuthorityType.values()) { if (presentationType.getId().equals(presentationTypeId)) { return presentationType; }//from w ww.ja v a 2 s . co m } return null; }
From source file:com.frank.search.solr.core.query.ExistsFunction.java
/** * Creates new {@link ExistsFunction} representing {@code exists(field)} * * @param field/* www . j a va 2 s .c o m*/ * @return */ public static ExistsFunction exists(Field field) { Assert.notNull(field, "Field cannot be 'null' for exists operation."); return exists(field.getName()); }
From source file:curly.commons.web.hateoas.PageProcessor.java
public static <T> Page<T> toPage(Collection<T> list, PageMetadata metadata) { Assert.notNull(list, "List content must be not null"); return new PageImpl<T>(new ArrayList<>(list), new PageRequest((int) metadata.getNumber(), (int) metadata.getSize()), metadata.getTotalElements()); }
From source file:example.springdata.cassandra.util.CassandraVersion.java
/** * Retrieve the Cassandra release version. * * @param session must not be {@literal null}. * @return the release {@link Version}./*from ww w .ja va 2 s. co m*/ */ public static Version getReleaseVersion(Session session) { Assert.notNull(session, "Session must not be null"); ResultSet resultSet = session.execute("SELECT release_version FROM system.local;"); Row row = resultSet.one(); return Version.parse(row.getString(0)); }
From source file:com.azaptree.services.command.util.CommandUtils.java
@SuppressWarnings("unchecked") public static <T> T put(final Context ctx, final TypeReferenceKey<T> key, final T value) { Assert.notNull(ctx, "ctx is required"); Assert.notNull(key, "key is required"); Assert.notNull(value, "value is required"); return (T) ctx.put(key.getName(), value); }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.CompassGpsUtils.java
/** * Calls CompassGps's index method, starting and stopping it if required * @param compassGps aCompassGps instance, cannot be null *///from w w w. ja v a 2 s. com public static void index(CompassGps compassGps) { Assert.notNull(compassGps, "compassGps cannot be null"); long start = System.currentTimeMillis(); LOG.info("Starting Searchable Plugin bulk index"); boolean gpsRunning = compassGps.isRunning(); try { if (!gpsRunning) { compassGps.start(); } compassGps.index(); } finally { if (!gpsRunning) { compassGps.stop(); } } LOG.info("Finished Searchable Plugin bulk index, " + TimeUtils.formatMillisAsShortHumanReadablePeriod(System.currentTimeMillis() - start)); }
From source file:lab.mage.spring.cassandra.connector.core.OptionProvider.java
@Nonnull public static final Mapper.Option deleteConsistencyLevel(@Nonnull final Environment env) { Assert.notNull(env, "An environment must be given!"); if (OptionProvider.CACHED_OPTIONS.isEmpty()) { OptionProvider.lazyOptionInit(env); }/* w w w . j av a 2 s. c o m*/ return OptionProvider.CACHED_OPTIONS.get(CassandraConnectorConstants.CONSISTENCY_LEVEL_DELETE_PROP); }
From source file:oz.hadoop.yarn.api.utils.ConfigUtils.java
/** * Will dynamically add configuration directory to the classpath. * //w ww. j ava 2 s . com * @param configurationDirectoryPath */ public static void addToClasspath(File configurationDirectoryPath) { Assert.notNull(configurationDirectoryPath, "'configurationDirectoryPath' must not be null"); Assert.isTrue(configurationDirectoryPath.exists(), "'configurationDirectoryPath' must exist"); Assert.isTrue(configurationDirectoryPath.isDirectory(), "'configurationDirectoryPath' must be a directory"); URL configUrl = null; try { configUrl = new URL("file:" + configurationDirectoryPath.getAbsolutePath() + "/"); } catch (Exception e) { throw new IllegalArgumentException("Failed to construct URL for " + configurationDirectoryPath, e); } URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader(); Method addUrlMethod = ReflectionUtils.getMethodAndMakeAccessible(URLClassLoader.class, "addURL", URL.class); try { addUrlMethod.invoke(cl, configUrl); } catch (Exception e) { throw new IllegalStateException("Failed to add URL: " + configUrl + " to the classpath", e); } }
From source file:cn.guoyukun.spring.jpa.entity.search.filter.Condition.java
/** * ?key?Condition/* w w w. j a v a 2 s . c o m*/ * * @param key name_like * @param value * @return */ static Condition newCondition(final String key, final Object value) throws SearchException { Assert.notNull(key, "Condition key must not null"); String[] searchs = StringUtils.split(key, separator); if (searchs.length == 0) { throw new SearchException("Condition key format must be : property or property_op"); } String searchProperty = searchs[0]; SearchOperator operator = null; if (searchs.length == 1) { operator = SearchOperator.custom; } else { try { operator = SearchOperator.valueOf(searchs[1]); } catch (IllegalArgumentException e) { throw new InvlidSearchOperatorException(searchProperty, searchs[1]); } } boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator); boolean isValueBlank = (value == null); isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value)); isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0); //??? if (!allowBlankValue && isValueBlank) { return null; } Condition searchFilter = newCondition(searchProperty, operator, value); return searchFilter; }