List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.wallride.autoconfigure.WebGuestComponentScanRegistrar.java
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(WebGuestComponentScan.class.getName())); String[] value = attributes.getStringArray("value"); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); if (!ObjectUtils.isEmpty(value)) { Assert.state(ObjectUtils.isEmpty(basePackages), "@WebGuestComponentScan basePackages and value attributes are mutually exclusive"); }//from w w w . j av a 2s . c om Set<String> packagesToScan = new LinkedHashSet<String>(); packagesToScan.addAll(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterMessageSource.java
public Message<Tweet> receive() { Assert.state(this.twitterMessageType != null, "the twitterMessageType can't be null!"); Assert.state(cachedStatuses != null, "the cachedStatuses can't be null!"); if (cachedStatuses.peek() == null) { Paging paging = new Paging(); paging.setCount(getPagingCount()); if (-1 != lastStatusIdRetreived) { paging.sinceId(lastStatusIdRetreived); }/*w ww. j a va 2s .c om*/ try { List<Status> statuses = new ArrayList<Status>(); switch (getTwitterMessageType()) { case DM: throw new UnsupportedOperationException("we don't support receiving direct mentions yet!"); case FRIENDS: statuses = twitter.getFriendsTimeline(paging); break; case MENTIONS: statuses = twitter.getMentions(paging); break; } if (cachedStatuses.peek() == null) { for (Status status : statuses) { this.cachedStatuses.add(buildTweetFromStatus(status)); } } } catch (TwitterException e) { logger.info(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } } if (cachedStatuses.peek() != null) { // size() == 0 would be more obvious a test, but size() isn't constant time Tweet cachedStatus = cachedStatuses.poll(); lastStatusIdRetreived = cachedStatus.getTweetId(); return MessageBuilder.withPayload(cachedStatus).build(); } return null; }
From source file:net.sf.gazpachoquest.services.core.impl.QuestionnaireAnswersServiceImpl.java
@Transactional @Override/*from ww w . ja v a 2s . co m*/ public Map<String, Object> findByQuestionnaire(Questionnaire questionnaire) { Assert.state(!questionnaire.isNew(), "Persist the questionnaire before saving answers"); Questionnaire fetched = questionnaireRepository.findOne(questionnaire.getId()); Integer questionnairDefinitionId = fetched.getQuestionnaireDefinition().getId(); Integer answersId = fetched.getAnswersId(); if (fetched.getAnswersId() == null) { return null; } QuestionnaireAnswers answers = repository.findByOne(questionnairDefinitionId, answersId); return answers.getAnswers(); }
From source file:fr.mby.portal.coreimpl.message.AbstractMimeReply.java
@Override public synchronized OutputStream getOutputStream() throws IOException, IllegalStateException { Assert.state(!this.writerUsed, "getWriter() has previously been called !"); this.outputStreamUsed = true; if (this.outputStream == null) { this.outputStream = new OutputStreamProxy(); }/* w w w . j a v a 2 s .c om*/ return this.outputStream; }
From source file:example.app.model.Person.java
@Transient @SuppressWarnings("all") public int getAge() { LocalDate birthDate = getBirthDate(); Assert.state(birthDate != null, String.format("birth date of person [%s] is unknown", getName())); Period period = Period.between(birthDate, LocalDate.now()); return period.getYears(); }
From source file:egovframework.rte.bat.core.item.file.transform.EgovFixedLengthLineAggregator.java
/** * Object fixedLength ? String ./*from ww w .j a va 2 s . c o m*/ * @param fieldValueLength item? ??? length * @param fields field * @return String ? */ private String aggregateFixedLength(int[] fieldValueLength, Object[] fields) { int fieldsLength = fields.length; //1. XML? field ? (ranges) field (fields) ? . if (fieldsLength != fieldRanges.length) { Assert.state(fieldsLength == fieldRanges.length, "The number of field's ranges: " + fieldRanges.length + " is must match the number of field: " + fieldsLength); } StringBuilder value = new StringBuilder(); for (int k = 0; k < fieldsLength; k++) { if (fieldRanges[k] >= fieldValueLength[k]) { value.append(fields[k].toString()); if (fieldRanges[k] > fieldValueLength[k]) { int needPaddingSize = fieldRanges[k] - fieldValueLength[k]; if (needPaddingSize <= paddingListSize) { value.append(paddingList.get(needPaddingSize - 1)); } else { int addMaxPaddingCount = needPaddingSize / paddingListSize; int remainderPaddingSize = needPaddingSize % paddingListSize; for (int i = 0; i < addMaxPaddingCount; i++) { value.append(paddingList.get(paddingListSize - 1)); } if (remainderPaddingSize != 0) { value.append(paddingList.get(remainderPaddingSize - 1)); } } } } else { //2. VO? field ? XML? field ? ?. Assert.state(fieldRanges[k] >= fieldValueLength[k], "Supplied text: " + fields[k] + " is longer than defined length: " + fieldRanges[k]); } } return value.toString(); }
From source file:org.opennms.ng.dao.support.RrdStatisticAttributeVisitor.java
/** * <p>afterPropertiesSet</p> * * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() *//*from w w w .j ava2 s. c om*/ @Override public void afterPropertiesSet() { Assert.state(m_rrdDao != null, "property rrdDao must be set to a non-null value"); Assert.state(m_consolidationFunction != null, "property consolidationFunction must be set to a non-null value"); Assert.state(m_startTime != null, "property startTime must be set to a non-null value"); Assert.state(m_endTime != null, "property endTime must be set to a non-null value"); Assert.state(m_statisticVisitor != null, "property statisticVisitor must be set to a non-null value"); }
From source file:net.sf.gazpachoquest.services.core.impl.SectionServiceImpl.java
@Override @Transactional(readOnly = false)/*w w w. j ava2 s .com*/ public Section save(final Section section) { Assert.state(!section.isNew(), "Section must be already persisted. Try by adding to QuestionnaireDefinition first."); Section existing = repository.findOne(section.getId()); existing.setLanguageSettings(section.getLanguageSettings()); existing.setRandomizationEnabled(section.isRandomizationEnabled()); for (Question question : section.getQuestions()) { if (!question.isNew()) { continue; } if (question.getLanguage() == null) { question.setLanguage(section.getLanguage()); } for (Question subquestion : question.getSubquestions()) { if (subquestion.getLanguage() == null) { subquestion.setLanguage(question.getLanguage()); } } existing.addQuestion(question); } return existing; }
From source file:org.pivotal.gemfire.cache.GemFireBasedParallelAsyncEventQueueTest.java
protected AsyncEventQueue getEventQueue() { Assert.state(eventQueue != null, "The 'AsyncEventQueue' was not properly initialized!"); return eventQueue; }
From source file:com.springdeveloper.data.jdbc.batch.JdbcTasklet.java
public void afterPropertiesSet() throws Exception { Assert.state(jdbcTemplate != null, "A DataSource must be provided"); Assert.state(sql != null, "A SQL query must be provided"); }