当前位置: 首页>>代码示例>>Java>>正文


Java Assert类代码示例

本文整理汇总了Java中org.springframework.util.Assert的典型用法代码示例。如果您正苦于以下问题:Java Assert类的具体用法?Java Assert怎么用?Java Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Assert类属于org.springframework.util包,在下文中一共展示了Assert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkNewProject

import org.springframework.util.Assert; //导入依赖的package包/类
private boolean checkNewProject(Project helpProject) {
    Project existingProject = projectDao.loadProject(helpProject.getName());

    boolean newProject = false;
    if (helpProject.getId() == null) {
        helpProject.setCreatedBy(AuthUtils.getCurrentUserId());
        helpProject.setCreatedDate(new Date());

        // for new project ensure that there is no project with this name
        Assert.isNull(existingProject, MessageHelper.getMessage(MessagesConstants.ERROR_PROJECT_NAME_EXISTS,
                                                                helpProject.getName()));
        newProject = true;
    } else {
        // for updated one - ensure that if there is a project with that name,
        // its ID is equal to this project's id
        Assert.isTrue(existingProject == null || existingProject.getId().equals(helpProject.getId()),
                      MessageHelper.getMessage(MessagesConstants.ERROR_PROJECT_NAME_EXISTS, helpProject.getName()));
    }
    return newProject;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:21,代码来源:ProjectManager.java

示例2: hasAncestorOfType

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Determine whether the supplied {@link Tag} has any ancestor tag
 * of the supplied type.
 * @param tag the tag whose ancestors are to be checked
 * @param ancestorTagClass the ancestor {@link Class} being searched for
 * @return {@code true} if the supplied {@link Tag} has any ancestor tag
 * of the supplied type
 * @throws IllegalArgumentException if either of the supplied arguments is {@code null};
 * or if the supplied {@code ancestorTagClass} is not type-assignable to
 * the {@link Tag} class
 */
public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
	Assert.notNull(tag, "Tag cannot be null");
	Assert.notNull(ancestorTagClass, "Ancestor tag class cannot be null");
	if (!Tag.class.isAssignableFrom(ancestorTagClass)) {
		throw new IllegalArgumentException(
				"Class '" + ancestorTagClass.getName() + "' is not a valid Tag type");
	}
	Tag ancestor = tag.getParent();
	while (ancestor != null) {
		if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
			return true;
		}
		ancestor = ancestor.getParent();
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:TagUtils.java

示例3: editCommission

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Ouvre une fenêtre d'édition de commission.
 *
 * @param commission
 */
public void editCommission(final Commission commission, final Boolean isAdmin) {
	Assert.notNull(commission, applicationContext.getMessage("assert.notNull", null, UI.getCurrent().getLocale()));

	/* Verrou */
	if (!lockController.getLockOrNotify(commission, null)) {
		return;
	}
	if (commission.getI18nCommentRetourComm() == null) {
		commission.setI18nCommentRetourComm(
				new I18n(i18nController.getTypeTraduction(NomenclatureUtils.TYP_TRAD_COMM_COMMENT_RETOUR)));
	}
	CtrCandCommissionWindow window = new CtrCandCommissionWindow(commission, isAdmin);
	window.addCloseListener(e -> lockController.releaseLock(commission));
	UI.getCurrent().addWindow(window);
}
 
开发者ID:EsupPortail,项目名称:esup-ecandidat,代码行数:21,代码来源:CommissionController.java

示例4: findByCriteria

import org.springframework.util.Assert; //导入依赖的package包/类
@Override
public List<?> findByCriteria(final DetachedCriteria criteria, final int firstResult, final int maxResults)
		throws DataAccessException {

	Assert.notNull(criteria, "DetachedCriteria must not be null");
	return executeWithNativeSession(new HibernateCallback<List<?>>() {
		@Override
		@SuppressWarnings("unchecked")
		public List<?> doInHibernate(Session session) throws HibernateException {
			Criteria executableCriteria = criteria.getExecutableCriteria(session);
			prepareCriteria(executableCriteria);
			if (firstResult >= 0) {
				executableCriteria.setFirstResult(firstResult);
			}
			if (maxResults > 0) {
				executableCriteria.setMaxResults(maxResults);
			}
			return executableCriteria.list();
		}
	});
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HibernateTemplate.java

示例5: createQuery

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * 创建Query对象
 * @param hql HQL语句
 * @param values 可变条件
 * @return Query
 */
protected Query createQuery(final String hql, final Object... values)
{
	Assert.hasText(hql);
	Query query = (Query)getHibernateTemplate().execute(new HibernateCallback()
	{
		public Query doInHibernate(Session session) throws HibernateException//, SQLException
		{
			return session.createQuery(hql);
		}
	});
	for(int i = 0; i < values.length; i++)
	{
		query.setParameter(i, values[i]);
	}
	return query;
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:23,代码来源:HibernateDao.java

示例6: updateAcl

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * This implementation will simply delete all ACEs in the database and recreate them on each invocation of
 * this method. A more comprehensive implementation might use dirty state checking, or more likely use ORM
 * capabilities for create, update and delete operations of {@link MutableAcl}.
 */
@Override
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
    Assert.notNull(acl.getId(), "Object Identity doesn't provide an identifier");

    // Delete this ACL's ACEs in the acl_entry table
    aclDao.deleteEntries(retrieveObjectIdentityPrimaryKey(acl.getObjectIdentity()));

    // Create this ACL's ACEs in the acl_entry table
    createEntries(acl);

    // Change the mutable columns in acl_object_identity
    updateObjectIdentity(acl);

    // Clear the cache, including children
    clearCacheIncludingChildren(acl.getObjectIdentity());

    // Retrieve the ACL via superclass (ensures cache registration, proper retrieval etc)
    return (MutableAcl) readAclById(acl.getObjectIdentity());
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:25,代码来源:JpaMutableAclService.java

示例7: doScan

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Perform a scan within the specified base packages,
 * returning the registered bean definitions.
 * <p>This method does <i>not</i> register an annotation config processor
 * but rather leaves this up to the caller.
 * @param basePackages the packages to check for annotated classes
 * @return set of beans registered if any for tooling registration purposes (never {@code null})
 */
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
	Assert.notEmpty(basePackages, "At least one base package must be specified");
	Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>();
	for (String basePackage : basePackages) {
		Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
		for (BeanDefinition candidate : candidates) {
			ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
			candidate.setScope(scopeMetadata.getScopeName());
			String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
			if (candidate instanceof AbstractBeanDefinition) {
				postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
			}
			if (candidate instanceof AnnotatedBeanDefinition) {
				AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
			}
			if (checkCandidate(beanName, candidate)) {
				BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
				definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
				beanDefinitions.add(definitionHolder);
				registerBeanDefinition(definitionHolder, this.registry);
			}
		}
	}
	return beanDefinitions;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:ClassPathBeanDefinitionScanner.java

示例8: processDeferredClose

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Process all Hibernate Sessions that have been registered for deferred close
 * for the given SessionFactory.
 * @param sessionFactory the Hibernate SessionFactory to process deferred close for
 * @see #initDeferredClose
 * @see #releaseSession
 */
public static void processDeferredClose(SessionFactory sessionFactory) {
	Assert.notNull(sessionFactory, "No SessionFactory specified");
	Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
	if (holderMap == null || !holderMap.containsKey(sessionFactory)) {
		throw new IllegalStateException("Deferred close not active for SessionFactory [" + sessionFactory + "]");
	}
	logger.debug("Processing deferred close of Hibernate Sessions");
	Set<Session> sessions = holderMap.remove(sessionFactory);
	for (Session session : sessions) {
		closeSession(session);
	}
	if (holderMap.isEmpty()) {
		deferredCloseHolder.remove();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:SessionFactoryUtils.java

示例9: addDeclaredParameter

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Add a declared parameter to the list of parameters for the call.
 * Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter}
 * will be used to provide input values. This is different from the {@code StoredProcedure} class
 * which for backwards compatibility reasons allows input values to be provided for parameters declared
 * as {@code SqlOutParameter}.
 * @param parameter the {@link SqlParameter} to add
 */
public void addDeclaredParameter(SqlParameter parameter) {
	Assert.notNull(parameter, "The supplied parameter must not be null");
	if (!StringUtils.hasText(parameter.getName())) {
		throw new InvalidDataAccessApiUsageException(
				"You must specify a parameter name when declaring parameters for \"" + getProcedureName() + "\"");
	}
	this.declaredParameters.add(parameter);
	if (logger.isDebugEnabled()) {
		logger.debug("Added declared parameter for [" + getProcedureName() + "]: " + parameter.getName());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AbstractJdbcCall.java

示例10: AbstractTemplateProvider

import org.springframework.util.Assert; //导入依赖的package包/类
public AbstractTemplateProvider(CustomResourceLoader customResourceLoader) {
    Assert.notNull(customResourceLoader, "CustomResourceLoader must not be null!");
    this.postfix = customResourceLoader.getPostfix();
    this.debug = true;
    this.excludeClasses = new Class[]{};
    this.overwrite = customResourceLoader.isOverwrite();
}
 
开发者ID:cmeza20,项目名称:spring-data-generator,代码行数:8,代码来源:AbstractTemplateProvider.java

示例11: register

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Saves metadata information about a reference genome that should become available in the
 * system.
 *
 * @param reference {@code Reference} represents a reference genome metadata that should be
 *                  stored in the system.
 * @return {@code Reference} is the same with the passed one to this call, but after succeeded
 * call it provides access to ID values
 * @throws IllegalArgumentException will be thrown if reference ID isn't specified or reference
 *                                  doesn't provide information about related chromosomes
 */
@Transactional(propagation = Propagation.REQUIRED)
public Reference register(final Reference reference) {
    Assert.isTrue(CollectionUtils.isNotEmpty(reference.getChromosomes()),
            getMessage("error.reference.aborted.saving.chromosomes"));
    Assert.notNull(reference.getId(), getMessage(MessageCode.UNKNOWN_REFERENCE_ID));
    biologicalDataItemDao.createBiologicalDataItem(reference.getIndex());
    if (reference.getCreatedDate() == null) {
        reference.setCreatedDate(new Date());
    }
    reference.setCreatedBy(AuthUtils.getCurrentUserId());
    if (reference.getType() == null) {
        reference.setType(BiologicalDataItemResourceType.FILE);
    }
    if (reference.getBioDataItemId() == null) {
        final Long referenceId = reference.getId();
        biologicalDataItemDao.createBiologicalDataItem(reference);
        referenceGenomeDao.createReferenceGenome(reference, referenceId);
    } else {
        referenceGenomeDao.createReferenceGenome(reference);
    }
    referenceGenomeDao.saveChromosomes(reference.getId(), reference.getChromosomes());
    return reference;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:35,代码来源:ReferenceGenomeManager.java

示例12: beanNamesForTypeIncludingAncestors

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Get all bean names for the given type, including those defined in ancestor
 * factories. Will return unique names in case of overridden bean definitions.
 * <p>Does consider objects created by FactoryBeans if the "allowEagerInit"
 * flag is set, which means that FactoryBeans will get initialized. If the
 * object created by the FactoryBean doesn't match, the raw FactoryBean itself
 * will be matched against the type. If "allowEagerInit" is not set,
 * only raw FactoryBeans will be checked (which doesn't require initialization
 * of each FactoryBean).
 * @param lbf the bean factory
 * @param includeNonSingletons whether to include prototype or scoped beans too
 * or just singletons (also applies to FactoryBeans)
 * @param allowEagerInit whether to initialize <i>lazy-init singletons</i> and
 * <i>objects created by FactoryBeans</i> (or by factory methods with a
 * "factory-bean" reference) for the type check. Note that FactoryBeans need to be
 * eagerly initialized to determine their type: So be aware that passing in "true"
 * for this flag will initialize FactoryBeans and "factory-bean" references.
 * @param type the type that beans must match
 * @return the array of matching bean names, or an empty array if none
 */
public static String[] beanNamesForTypeIncludingAncestors(
		ListableBeanFactory lbf, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {

	Assert.notNull(lbf, "ListableBeanFactory must not be null");
	String[] result = lbf.getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
	if (lbf instanceof HierarchicalBeanFactory) {
		HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf;
		if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
			String[] parentResult = beanNamesForTypeIncludingAncestors(
					(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
			List<String> resultList = new ArrayList<String>();
			resultList.addAll(Arrays.asList(result));
			for (String beanName : parentResult) {
				if (!resultList.contains(beanName) && !hbf.containsLocalBean(beanName)) {
					resultList.add(beanName);
				}
			}
			result = StringUtils.toStringArray(resultList);
		}
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:BeanFactoryUtils.java

示例13: single

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * 更新mainStem的同步状态数据
 */
public void single(MainStemEventData data) {
    Assert.notNull(data);
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    if (!check()) {
        return;
    }

    data.setNid(nid);// 设置当前的nid
    String path = StagePathUtils.getMainStem(data.getPipelineId());
    byte[] bytes = JsonUtils.marshalToByte(data);// 初始化的数据对象
    try {
        zookeeper.writeData(path, bytes);
    } catch (ZkException e) {
        throw new ArbitrateException("mainStem_single", data.toString(), e);
    }
    activeData = data;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:21,代码来源:MainstemMonitor.java

示例14: DefaultHandlerResult

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Instantiates a new handler result.
 *
 * @param source the source
 * @param metaData the meta data
 * @param p the p
 * @param warnings the warnings
 */
public DefaultHandlerResult(
        final AuthenticationHandler source,
        final CredentialMetaData metaData,
        final Principal p,
        final List<MessageDescriptor> warnings) {
    Assert.notNull(source, "Source cannot be null.");
    Assert.notNull(metaData, "Credential metadata cannot be null.");
    this.handlerName = source.getName();
    if (!StringUtils.hasText(this.handlerName)) {
        this.handlerName = source.getClass().getSimpleName();
    }
    this.credentialMetaData = metaData;
    this.principal = p;
    this.warnings = warnings;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:DefaultHandlerResult.java

示例15: BootstrappingDependenciesEvent

import org.springframework.util.Assert; //导入依赖的package包/类
/**
 * Constructs a new <code>BootstrappingDependencyEvent</code> instance.
 * 
 * @param source
 */
public BootstrappingDependenciesEvent(ApplicationContext source, Bundle bundle,
		Collection<OsgiServiceDependencyEvent> nestedEvents, Filter filter, long timeLeft) {
	super(source, bundle);
	Assert.notNull(nestedEvents);
	this.dependencyEvents = nestedEvents;
	this.dependenciesFilter = filter;
	this.timeLeft = timeLeft;

	List<String> depFilters = new ArrayList<String>(dependencyEvents.size());

	for (OsgiServiceDependencyEvent dependency : nestedEvents) {
		depFilters.add(dependency.getServiceDependency().getServiceFilter().toString());
	}

	dependencyFilters = Collections.unmodifiableCollection(depFilters);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:BootstrappingDependenciesEvent.java


注:本文中的org.springframework.util.Assert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。