List of usage examples for org.springframework.util Assert isTrue
public static void isTrue(boolean expression, Supplier<String> messageSupplier)
From source file:org.kmnet.com.fw.common.codelist.NumberRangeCodeList.java
/** * Initializes the codelist with the range of numbers.<br> * <p>//from w w w. j a v a 2 s .co m * <code>to</code> must be more than <code>from</code>. * </p> * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() * @throws IllegalArgumentException when if from is greater than to. */ @Override public void afterPropertiesSet() { Assert.isTrue(interval > 0, "interval should be greater than 0"); Assert.hasLength(valueFormat, "valueFormat must not be empty"); Assert.hasLength(labelFormat, "labelFormat must not be empty"); LinkedHashMap<String, String> numbers = new LinkedHashMap<String, String>(); if (from <= to) { for (int i = from; i <= to; i = i + interval) { putInMap(numbers, i); } } else { for (int i = from; i >= to; i = i - interval) { putInMap(numbers, i); } } map = Collections.unmodifiableMap(numbers); }
From source file:org.cleverbus.core.throttling.ThrottleCounterMemoryImpl.java
@Override public int count(ThrottleScope throttleScope, int interval) { Assert.notNull(throttleScope, "the throttleScope must not be null"); Assert.isTrue(interval > 0, "the interval must be positive value"); int counter = 0; boolean toLock = false; // is it necessary to lock thread? Only if two same throttle scopes are processed at the same time synchronized (OBJ_LOCK) { if (scopesInProgress.contains(throttleScope)) { toLock = true;//from w w w.jav a2 s . co m } else { scopesInProgress.add(throttleScope); } } if (toLock) { lock.lock(); } try { if (requests.get(throttleScope) == null) { requests.put(throttleScope, new Stack<Long>()); } long now = DateTime.now().getMillis(); long from = now - (interval * 1000); // get timestamps for specified throttling scope List<Long> timestamps = requests.get(throttleScope); timestamps.add(now); // count requests for specified interval int lastIndex = -1; for (int i = timestamps.size() - 1; i >= 0; i--) { long timestamp = timestamps.get(i); if (timestamp >= from) { counter++; } else { lastIndex = i; break; } } // remove old timestamps if (lastIndex > 0) { for (int i = 0; i <= lastIndex; i++) { timestamps.remove(0); } } } finally { synchronized (OBJ_LOCK) { scopesInProgress.remove(throttleScope); } if (toLock) { lock.unlock(); } } // make dump only once in the specified interval if (Log.isDebugEnabled() && (DateUtils.addSeconds(new Date(), -DUMP_PERIOD).after(lastDumpTimestamp))) { dumpMemory(); lastDumpTimestamp = new Date(); } return counter; }
From source file:com.nortal.petit.orm.relation.RelationMapper.java
public RelationMapper(Class<T> target, Class<R> relation, String targetProperty, String relationProperty, String targetMapping, WherePart where) { Assert.notNull(target, "RelationMapper.construct: target is mandatory"); Assert.notNull(relation, "RelationMapper.construct: relation is mandatory"); Assert.isTrue(StringUtils.isNotEmpty(targetProperty) || StringUtils.isNotEmpty(relationProperty), "RelationMapper.construct: targetProperty or relationProperty is mandatory"); this.relationClass = relation; this.targetMapper = BeanMappings.get(target); this.relationMapper = BeanMappings.get(relation); // Init target mapping property if (StringUtils.isEmpty(targetProperty)) { this.targetProperty = targetMapper.id(); } else {/*from ww w . ja v a 2 s. c o m*/ this.targetProperty = targetMapper.props().get(targetProperty); } Assert.notNull(this.targetProperty, "RelationMapper.construct: targetProperty is mandatory"); targetId = new PropertyFunction<T, Object>(this.targetProperty); // Init target mapping property if (StringUtils.isEmpty(relationProperty)) { this.relationProperty = relationMapper.id(); } else { this.relationProperty = relationMapper.props().get(relationProperty); } Assert.notNull(this.relationProperty, "RelationMapper.construct: relationProperty is mandatory"); relationId = new PropertyFunction<R, Object>(this.relationProperty); if (StringUtils.isNotEmpty(targetMapping)) { PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(target, targetMapping); this.associateMethod = pd.getWriteMethod(); } // Mapping conditions this.where = where; }
From source file:com.google.code.maven.plugin.http.client.Proxy.java
/** * port setter.// w w w . ja v a2 s.c o m * * @param port * the port to set */ public void setPort(int port) { Assert.isTrue(port > 0 && port < 65536, "port number should be strictly positive and less than 65536"); this.port = port; }
From source file:com.mike.angry.dm.DataModel.java
public List<Digital> getByYPosition(int y) { List<Digital> result = new ArrayList<Digital>(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (bigSquare[i][j].getY() == y) { result.add(bigSquare[i][j]); }/*w w w.jav a 2s .c om*/ } } Assert.isTrue(result.size() == 9, "one square num should be 9! y " + y + "result.size()" + result.size()); return result; }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.TrustedIdpDAOJPATest.java
@Test public void testReadExistingTrustedIdp() { TrustedIdp trustedIdp = trustedIdpDAO.getTrustedIDP("urn:org:apache:cxf:fediz:idp:realm-B"); Assert.isTrue("realmb.cert".equals(trustedIdp.getCertificate()), "Certificate name doesn't match"); Assert.isTrue("Realm B description".equals(trustedIdp.getDescription()), "Description name doesn't match"); Assert.isTrue(FederationType.FEDERATE_IDENTITY.equals(trustedIdp.getFederationType()), "FederationType doesn't match"); Assert.isTrue("Realm B".equals(trustedIdp.getName()), "Name doesn't match"); Assert.isTrue("http://docs.oasis-open.org/wsfed/federation/200706".equals(trustedIdp.getProtocol()), "Protocol doesn't match"); Assert.isTrue("urn:org:apache:cxf:fediz:idp:realm-B".equals(trustedIdp.getRealm()), "Realm doesn't match"); Assert.isTrue(TrustType.PEER_TRUST.equals(trustedIdp.getTrustType()), "TrustType doesn't match"); Assert.isTrue("https://localhost:12443/fediz-idp-remote/federation".equals(trustedIdp.getUrl()), "Url doesn't match"); Assert.isTrue(trustedIdp.isCacheTokens(), "CacheTokens doesn't match"); }
From source file:com.miko.demo.neo4j.model.EntityC.java
public EntityC(String name, BigDecimal value) { Assert.hasText(name, "Name can not be empty"); Assert.isTrue(BigDecimal.ZERO.compareTo(value) < 0, "Value must be greater than zero!"); this.name = name; this.value = value; }
From source file:com.crossover.trial.weather.domain.DataPointRepositoryImpl.java
@Override @Transactional(propagation = Propagation.MANDATORY) public Measurement createMeasurement(Airport airport, DataPoint dataPoint) { Assert.isTrue(airport != null, "airport is required"); Assert.isTrue(dataPoint != null, "dataPoint is required"); manager.persist(dataPoint);/*from www. j a v a2s . c o m*/ Measurement measurement = dataPoint.createMeasurement(airport); if (measurement != null) manager.persist(measurement); else manager.remove(dataPoint); return measurement; }
From source file:com.azaptree.services.http.HttpServiceConfig.java
public HttpServiceConfig(final String name, final Handler httpRequestHandler, final ExecutorService requestExcecutor, final int port) { Assert.hasText(name, "name is required"); Assert.notNull(httpRequestHandler, "httpRequestHandler is required"); this.name = name; this.httpRequestHandler = httpRequestHandler; Assert.notNull(requestExcecutor, "requestExcecutor is required"); Assert.isTrue(port > 0, "port must be > 0"); requestExcecutorService = requestExcecutor; this.port = port; }
From source file:cz.cvut.portal.kos.services.support.ListPaginator.java
public void goToPage(int page) throws IllegalArgumentException { Assert.isTrue(page > 0, "Page number must be greater than zero"); fetch((page - 1) * itemsPerPage);/*from w ww. j a v a2s .c o m*/ }