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


Java Assert.state方法代码示例

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


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

示例1: getFieldGenricType

import org.springframework.util.Assert; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static Class getFieldGenricType(final Field field, final int index) {
   	Assert.notNull(field, "Parameter 'field' must be not null!");
   	Assert.state(index > -1, "Parameter 'index' must be > -1!");
   	Type type = field.getGenericType();
   	if(type instanceof ParameterizedType){
		ParameterizedType ptype = (ParameterizedType)type;
		type = ptype.getActualTypeArguments()[index];
		if(type instanceof ParameterizedType){
			return (Class)((ParameterizedType) type).getRawType();
		}else{
			return (Class) type;
		}
	}else{
		return (Class) type;
	}
   }
 
开发者ID:penggle,项目名称:xproject,代码行数:18,代码来源:ReflectionUtils.java

示例2: write

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public void write(InputStream inputStream, String destination) throws IOException {
	String[] tokens = getBucketAndObjectFromPath(destination);
	Assert.state(tokens.length == 2, "Can only write to files, not buckets.");

	BlobInfo gcsBlobInfo = BlobInfo.newBuilder(BlobId.of(tokens[0], tokens[1])).build();

	try (InputStream is = inputStream) {
		try (WriteChannel channel = this.gcs.writer(gcsBlobInfo)) {
			channel.write(ByteBuffer.wrap(StreamUtils.copyToByteArray(is)));
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:GcsSession.java

示例3: createAsyncRequest

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>Setting the {@link #setTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) taskExecutor} property
 * is required before calling this method.
 */
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
		throws IOException {
	Assert.state(this.taskExecutor != null, "Asynchronous execution requires an " +
			"AsyncTaskExecutor to be set");
	HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
	prepareConnection(connection, httpMethod.name());
	if (this.bufferRequestBody) {
		return new SimpleBufferingAsyncClientHttpRequest(connection, this.outputStreaming, this.taskExecutor);
	}
	else {
		return new SimpleStreamingAsyncClientHttpRequest(connection, this.chunkSize,
				this.outputStreaming, this.taskExecutor);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:SimpleClientHttpRequestFactory.java

示例4: checkConfigFileExists

import org.springframework.util.Assert; //导入方法依赖的package包/类
@PostConstruct
public void checkConfigFileExists() {
    if (this.properties.isCheckConfigLocation() && StringUtils.hasText(this.properties.getConfigLocation())) {
        Resource resource = this.resourceLoader.getResource(this.properties.getConfigLocation());
        Assert.state(resource.exists(), "Cannot find config location: " + resource
                + " (please add config file or check your Mybatis configuration)");
    }
}
 
开发者ID:abel533,项目名称:mapper-boot-starter,代码行数:9,代码来源:MapperAutoConfiguration.java

示例5: postProcessBeforeInitialization

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
	if (bean instanceof LoadTimeWeaverAware) {
		LoadTimeWeaver ltw = this.loadTimeWeaver;
		if (ltw == null) {
			Assert.state(this.beanFactory != null,
					"BeanFactory required if no LoadTimeWeaver explicitly specified");
			ltw = this.beanFactory.getBean(
					ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
		}
		((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
	}
	return bean;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:LoadTimeWeaverAwareProcessor.java

示例6: getCachedIntrospectionResults

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Obtain a lazily initializted CachedIntrospectionResults instance
 * for the wrapped object.
 */
private CachedIntrospectionResults getCachedIntrospectionResults() {
	Assert.state(this.object != null, "BeanWrapper does not hold a bean instance");
	if (this.cachedIntrospectionResults == null) {
		this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
	}
	return this.cachedIntrospectionResults;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:BeanWrapperImpl.java

示例7: initDirectFieldAccess

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Initialize direct field access for this DataBinder,
 * as alternative to the default bean property access.
 * @see #initBeanPropertyAccess()
 */
public void initDirectFieldAccess() {
	Assert.state(this.bindingResult == null,
			"DataBinder is already initialized - call initDirectFieldAccess before other configuration methods");
	this.bindingResult = new DirectFieldBindingResult(getTarget(), getObjectName());
	if (this.conversionService != null) {
		this.bindingResult.initConversion(this.conversionService);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:DataBinder.java

示例8: read

import org.springframework.util.Assert; //导入方法依赖的package包/类
public int read(byte[] b, int off, int len) {
    int length = Math.min(getAvailable(), len);
    Assert.state(length > 0, "No data available in buffer");
    System.arraycopy(this.buf, this.offset, b, off, length);
    offset += length;
    return length;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:8,代码来源:DynamicInputStream.java

示例9: getObject

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Get a {@link PagingQueryProvider} instance using the provided properties
 * and appropriate for the given database type.
 *
 * @see FactoryBean#getObject()
 */
@Override
public PagingQueryProvider getObject() throws Exception {

	DatabaseType type;
	try {
		type = databaseType != null ? DatabaseType.valueOf(databaseType.toUpperCase()) : DatabaseType
				.fromMetaData(dataSource);
	}
	catch (MetaDataAccessException e) {
		throw new IllegalArgumentException(
				"Could not inspect meta data for database type.  You have to supply it explicitly.", e);
	}

	AbstractSqlPagingQueryProvider provider = providers.get(type);
	Assert.state(provider != null, "Should not happen: missing PagingQueryProvider for DatabaseType=" + type);

	provider.setFromClause(fromClause);
	provider.setWhereClause(whereClause);
	provider.setSortKeys(sortKeys);
	if (StringUtils.hasText(selectClause)) {
		provider.setSelectClause(selectClause);
	}
	provider.init(dataSource);

	return provider;

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:34,代码来源:SqlPagingQueryProviderFactoryBean.java

示例10: compare

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public int compare(T o1, T o2) {
	Assert.state(this.comparators.size() > 0,
			"No sort definitions have been added to this CompoundComparator to compare");
	for (InvertibleComparator comparator : this.comparators) {
		int result = comparator.compare(o1, o2);
		if (result != 0) {
			return result;
		}
	}
	return 0;
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:14,代码来源:CompoundComparator.java

示例11: getCurrentRequest

import org.springframework.util.Assert; //导入方法依赖的package包/类
/**
 * Obtain the request through {@link RequestContextHolder}.
 * @return the active servlet request
 */
protected static HttpServletRequest getCurrentRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}
 
开发者ID:jaschenk,项目名称:Your-Microservice,代码行数:13,代码来源:YourServletUriComponentsBuilder.java

示例12: startWork

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public long startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	return executeWork(this.asyncTaskExecutor, work, startTimeout, true, executionContext, workListener);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:SimpleTaskWorkManager.java

示例13: fromPath

import org.springframework.util.Assert; //导入方法依赖的package包/类
public static MavenCoordinates fromPath(String path) {
	if (path.startsWith("/")) {
		path = path.substring(1);
	}
	Matcher folderMatcher = FOLDER_PATTERN.matcher(path);
	Assert.state(folderMatcher.matches(), "Unable to parse " + path);
	String groupId = folderMatcher.group(1).replace('/', '.');
	String artifactId = folderMatcher.group(2);
	String version = folderMatcher.group(3);
	String rootVersion = (version.endsWith(SNAPSHOT_SUFFIX)
			? version.substring(0, version.length() - SNAPSHOT_SUFFIX.length())
			: version);
	String name = folderMatcher.group(4);
	String snapshotVersionAndClassifier = name.substring(artifactId.length() + 1);
	String extension = StringUtils.getFilenameExtension(snapshotVersionAndClassifier);
	snapshotVersionAndClassifier = snapshotVersionAndClassifier.substring(0,
			snapshotVersionAndClassifier.length() - extension.length() - 1);
	String classifier = snapshotVersionAndClassifier;
	if (classifier.startsWith(rootVersion)) {
		classifier = classifier.substring(rootVersion.length());
		classifier = stripDash(classifier);
	}
	Matcher versionMatcher = VERSION_FILE_PATTERN.matcher(classifier);
	if (versionMatcher.matches()) {
		classifier = versionMatcher.group(3);
		classifier = stripDash(classifier);
	}
	if (classifier.startsWith(SNAPSHOT)) {
		classifier = classifier.substring(SNAPSHOT.length());
		classifier = stripDash(classifier);
	}
	String snapshotVersion = (classifier.isEmpty() ? snapshotVersionAndClassifier
			: snapshotVersionAndClassifier.substring(0,
					snapshotVersionAndClassifier.length() - classifier.length() - 1));
	return new MavenCoordinates(groupId, artifactId, version, classifier, extension,
			snapshotVersion);
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:38,代码来源:MavenCoordinates.java

示例14: createRequest

import org.springframework.util.Assert; //导入方法依赖的package包/类
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
	CloseableHttpClient client = (CloseableHttpClient) getHttpClient();
	Assert.state(client != null, "Synchronous execution requires an HttpClient to be set");
	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
       HttpContext context = createHttpContext(httpMethod, uri);
       if (context == null) {
           context = HttpClientContext.create();
       }
       // Request configuration not set in the context
       if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
           // Use request configuration given by the user, when available
           RequestConfig config = null;
           if (httpRequest instanceof Configurable) {
               config = ((Configurable) httpRequest).getConfig();
           }
           if (config == null) {
               if (this.socketTimeout > 0 || this.connectTimeout > 0) {
                   config = RequestConfig.custom()
                           .setConnectTimeout(this.connectTimeout)
                           .setSocketTimeout(this.socketTimeout)
                           .build();
               }
			else {
                   config = RequestConfig.DEFAULT;
               }
           }
           context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
       }
	if (this.bufferRequestBody) {
		return new HttpComponentsClientHttpRequest(client, httpRequest, context);
	}
	else {
		return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:HttpComponentsClientHttpRequestFactory.java

示例15: fromArgs

import org.springframework.util.Assert; //导入方法依赖的package包/类
public static Directory fromArgs(ApplicationArguments args) {
	List<String> nonOptionArgs = args.getNonOptionArgs();
	Assert.state(nonOptionArgs.size() >= 2, "No directory argument specified");
	return new Directory(nonOptionArgs.get(1));
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:6,代码来源:Directory.java


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