List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:com.redblackit.web.server.HostNetUtils.java
/** * Returns the number of a free port in the given range, starting from * supplied value. Note that the supplied value need not be between the min * and max values, but will be ignored if <= 0. * /* w w w .j av a2 s. c o m*/ * @param minPort * minimum port value (default MIN_SAFE_PORT) * @param maxPort * maximum port value (default MAX_PORT) * @param startPort * port value to try first */ public static int getFreePort(int minPort, int maxPort, int startPort) { if (minPort <= 0) { logger.info("defaulting minPort:" + minPort + "->" + MIN_SAFE_PORT); minPort = MIN_SAFE_PORT; } if (maxPort <= 0 || maxPort > MAX_PORT) { logger.info("defaulting maxPort:" + maxPort + "->" + MAX_PORT); maxPort = MAX_PORT; } Assert.state(minPort < maxPort, "after defaulting, minPort=" + minPort + " >= maxPort=" + maxPort); if (startPort > 0 && isPortAvailable(startPort)) { logger.info("Using startPort=" + startPort); return startPort; } int candidatePort; int portRange = maxPort - minPort; int searchCounter = 0; do { if (++searchCounter > portRange) { throw new IllegalStateException( String.format("There were no ports available in the range %d to %d", minPort, maxPort)); } candidatePort = getRandomPort(minPort, portRange); logger.info("Trying candidatePort=" + candidatePort); } while (!isPortAvailable(candidatePort)); logger.info("Using candidatePort=" + candidatePort); return candidatePort; }
From source file:org.kuali.maven.plugins.graph.validate.IncludedDependencyNodeValidator.java
@Override protected void validateState(List<DependencyNode> nodes) { Map<String, Artifact> ids = new HashMap<String, Artifact>(); Map<String, Artifact> partialIds = new HashMap<String, Artifact>(); for (DependencyNode node : nodes) { Artifact a = node.getArtifact(); Assert.state(node.getRelatedArtifact() == null, "Included nodes can't contain related artifacts"); String id = TreeHelper.getArtifactId(a); String partialId = TreeHelper.getPartialArtifactId(a); ids.put(id, a);//from w w w .ja v a 2 s . c o m partialIds.put(partialId, a); } int c1 = nodes.size(); int c2 = ids.size(); int c3 = partialIds.size(); boolean valid = c1 == c2 && c2 == c3; Assert.state(valid, "Unique included artifact id counts don't match. c1=" + c1 + " c2=" + c2 + " c3=" + c3); }
From source file:org.spring.data.gemfire.cache.NamedNumbersCacheLoader.java
protected Map<String, Integer> getNamedNumbers() { Assert.state(namedNumbers != null, "The reference to the 'NamedNumbers' Map was not properly configured and initialized!"); return namedNumbers; }
From source file:org.cloudfoundry.identity.uaa.social.SocialClientAuthenticationFilter.java
@Override public void afterPropertiesSet() { Assert.state(socialClientUserDetailsSource != null, "User info source must be provided"); super.afterPropertiesSet(); }
From source file:org.spring.data.gemfire.app.dao.vendor.SQLFireJpaUserDao.java
@Override protected EntityManager prepare(final EntityManager entityManager) { Assert.notNull(entityManager, "The JPA EntityManager must not be null!"); Assert.state(entityManager.isOpen(), "The EntityManager is closed!"); if (entityManager.getDelegate() instanceof Session) { Session session = (Session) entityManager.getDelegate(); if (session instanceof SessionImpl) { try { ((SessionImpl) session).connection() .setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); //((SessionImpl) session).connection().setTransactionIsolation(Connection.TRANSACTION_NONE); } catch (SQLException e) { //System.err.printf("Failed to set the JDBC Connection Transaction Isolation Level to (READ_COMMITTED)!%n%1$s%n", e); throw new PersistenceException( "Failed to set the JDBC Connection Transaction Isolation-level to (READ_COMMITTED)!", e);//from w w w . jav a 2 s . c om } } } return entityManager; }
From source file:cz.jirutka.spring.data.jdbc.TableDescription.java
/** * @see #setTableName(String)/*from w ww. j a va2 s . c o m*/ * @throws IllegalStateException if {@code tableName} is not set. */ public String getTableName() { Assert.state(tableName != null, "tableName must not be null"); return tableName; }
From source file:com.oreilly.springdata.neo4j.order.Order.java
public Order withBillingAddress(Address billingAddress) { Assert.state(customer.hasAddress(billingAddress), "valid customer address for " + customer); this.billingAddress = billingAddress; return this; }
From source file:org.spring.data.gemfire.app.main.AbstractApp.java
protected ConfigurableApplicationContext getApplicationContext() { ConfigurableApplicationContext localApplicationContext = applicationContextReference.get(); Assert.state(localApplicationContext != null, "The Spring ApplicationContext was not properly configured and initialized!"); return localApplicationContext; }
From source file:org.carewebframework.api.FrameworkUtil.java
/** * Asserts that the application framework has been initialized. *///from w w w . j av a 2 s . c o m public static void assertInitialized() { Assert.state(isInitialized(), "AppFramework must be initialized"); }
From source file:example.app.service.GeocodingService.java
@SuppressWarnings("all") protected GeocodingRepository getGeocodingRepository() { Assert.state(geocodingRepository != null, "GeocodingRepository was not properly configured and initialized"); return this.geocodingRepository; }