本文整理匯總了Java中org.springframework.util.ObjectUtils.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectUtils.isEmpty方法的具體用法?Java ObjectUtils.isEmpty怎麽用?Java ObjectUtils.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.ObjectUtils
的用法示例。
在下文中一共展示了ObjectUtils.isEmpty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: splitArrayElementsIntoProperties
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* Take an array Strings and split each element based on the given delimiter.
* A {@code Properties} instance is then generated, with the left of the
* delimiter providing the key, and the right of the delimiter providing the value.
* <p>Will trim both the key and value before adding them to the
* {@code Properties} instance.
* @param array the array to process
* @param delimiter to split each element using (typically the equals symbol)
* @param charsToDelete one or more characters to remove from each element
* prior to attempting the split operation (typically the quotation mark
* symbol), or {@code null} if no removal should occur
* @return a {@code Properties} instance representing the array contents,
* or {@code null} if the array to process was {@code null} or empty
*/
public static Properties splitArrayElementsIntoProperties(
String[] array, String delimiter, String charsToDelete) {
if (ObjectUtils.isEmpty(array)) {
return null;
}
Properties result = new Properties();
for (String element : array) {
if (charsToDelete != null) {
element = deleteAny(element, charsToDelete);
}
String[] splittedElement = split(element, delimiter);
if (splittedElement == null) {
continue;
}
result.setProperty(splittedElement[0].trim(), splittedElement[1].trim());
}
return result;
}
示例2: toString
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@Override
public String toString() {
if (ObjectUtils.isEmpty(this.messageExceptions)) {
return super.toString();
}
else {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("; message exceptions (").append(this.messageExceptions.length).append(") are:");
for (int i = 0; i < this.messageExceptions.length; i++) {
Exception subEx = this.messageExceptions[i];
sb.append('\n').append("Failed message ").append(i + 1).append(": ");
sb.append(subEx);
}
return sb.toString();
}
}
示例3: getServiceReference
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
public static ServiceReference getServiceReference(ServiceReference... references) {
if (ObjectUtils.isEmpty(references)) {
return null;
}
ServiceReference winningReference = references[0];
if (references.length > 1) {
long winningId = getServiceId(winningReference);
int winningRanking = getServiceRanking(winningReference);
// start iterating in order to find the best match
for (int i = 1; i < references.length; i++) {
ServiceReference reference = references[i];
int serviceRanking = getServiceRanking(reference);
long serviceId = getServiceId(reference);
if ((serviceRanking > winningRanking) || (serviceRanking == winningRanking && winningId > serviceId)) {
winningReference = reference;
winningId = serviceId;
winningRanking = serviceRanking;
}
}
}
return winningReference;
}
示例4: getConfigurations
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
public String[] getConfigurations(Bundle bundle) {
String[] locations = ConfigUtils.getHeaderLocations(bundle.getHeaders());
// if no location is specified in the header, try the defaults
if (ObjectUtils.isEmpty(locations)) {
// check the default locations if the manifest doesn't provide any info
Enumeration defaultConfig = bundle.findEntries(CONTEXT_DIR, CONTEXT_FILES, false);
if (defaultConfig != null && defaultConfig.hasMoreElements()) {
return new String[] { DEFAULT_CONFIG };
}
else {
return new String[0];
}
}
else {
return locations;
}
}
示例5: getDirectChildNodeList
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
public <R> List<R> getDirectChildNodeList(I parentTreeNodeId, List<T> allTreeNodeList, TreeNodeConverter<T, R> treeNodeBuilder) {
List<R> childList = new ArrayList<R>();
if(CollectionUtils.isEmpty(allTreeNodeList) || ObjectUtils.isEmpty(parentTreeNodeId) || treeNodeBuilder == null){
return childList;
}
for(T treeNode : allTreeNodeList){
if(treeNode != null && parentTreeNodeId.equals(getParentTreeNodeId(treeNode))){
childList.add(treeNodeBuilder.convertTreeNode(treeNode));
}
}
return childList;
}
示例6: headersToMap
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
private static String[] headersToMap(KinesisBinderConfigurationProperties configurationProperties) {
Assert.notNull(configurationProperties, "'configurationProperties' must not be null");
if (ObjectUtils.isEmpty(configurationProperties.getHeaders())) {
return BinderHeaders.STANDARD_HEADERS;
}
else {
String[] combinedHeadersToMap = Arrays.copyOfRange(BinderHeaders.STANDARD_HEADERS, 0,
BinderHeaders.STANDARD_HEADERS.length + configurationProperties.getHeaders().length);
System.arraycopy(configurationProperties.getHeaders(), 0, combinedHeadersToMap,
BinderHeaders.STANDARD_HEADERS.length, configurationProperties.getHeaders().length);
return combinedHeadersToMap;
}
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-aws-kinesis,代碼行數:14,代碼來源:KinesisMessageChannelBinder.java
示例7: parseAttributes
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* Generic attribute callback. Will parse the given callback array, w/o any standard callback.
*
* @param element XML element
* @param builder current bean definition builder
* @param callbacks array of callbacks (can be null/empty)
*/
public static void parseAttributes(Element element, BeanDefinitionBuilder builder, AttributeCallback[] callbacks) {
NamedNodeMap attributes = element.getAttributes();
for (int x = 0; x < attributes.getLength(); x++) {
Attr attr = (Attr) attributes.item(x);
boolean shouldContinue = true;
if (!ObjectUtils.isEmpty(callbacks))
for (int i = 0; i < callbacks.length && shouldContinue; i++) {
AttributeCallback callback = callbacks[i];
shouldContinue = callback.process(element, attr, builder);
}
}
}
示例8: prePersist
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@PrePersist
public void prePersist(){
if (ObjectUtils.isEmpty(getId()))
setId(UUID.randomUUID().toString());
if (ObjectUtils.isEmpty(getUpdateTime()))
setUpdateTime(new Date());
if (ObjectUtils.isEmpty(getCreateTime()))
setCreateTime(new Date());
if (ObjectUtils.isEmpty(getDel()))
setDel(0);
}
示例9: removeParents
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* Parses the given class array and eliminate parents of existing classes. Useful when creating proxies to minimize
* the number of implemented interfaces and redundant class information.
*
* @see #containsUnrelatedClasses(Class[])
* @see #configureFactoryForClass(ProxyFactory, Class[])
*
* @param classes array of classes
* @return a new array without superclasses
*/
public static Class<?>[] removeParents(Class<?>[] classes) {
if (ObjectUtils.isEmpty(classes))
return new Class[0];
List<Class<?>> clazz = new ArrayList<Class<?>>(classes.length);
for (int i = 0; i < classes.length; i++) {
clazz.add(classes[i]);
}
// remove null elements
while (clazz.remove(null)) {
}
// only one class is allowed
// there can be multiple interfaces
// parents of classes inside the array are removed
boolean dirty;
do {
dirty = false;
for (int i = 0; i < clazz.size(); i++) {
Class<?> currentClass = clazz.get(i);
for (int j = 0; j < clazz.size(); j++) {
if (i != j) {
if (currentClass.isAssignableFrom(clazz.get(j))) {
clazz.remove(i);
i--;
dirty = true;
break;
}
}
}
}
} while (dirty);
return (Class[]) clazz.toArray(new Class[clazz.size()]);
}
示例10: setConfigLocations
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@Override
public void setConfigLocations(String[] configLocations) {
if (!ObjectUtils.isEmpty(configLocations)) {
throw new UnsupportedOperationException(
"GenericWebApplicationContext does not support setConfigLocations(). " +
"Do you still have an 'contextConfigLocations' init-param set?");
}
}
示例11: getServiceReferences
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* Returns references to <em>all</em> services matching the given class names and OSGi filter.
*
* @param bundleContext OSGi bundle context
* @param classes array of fully qualified class names
* @param filter valid OSGi filter (can be <code>null</code>)
* @return non-<code>null</code> array of references to matching services
*/
public static ServiceReference[] getServiceReferences(BundleContext bundleContext, String[] classes, String filter) {
// use #getServiceReferences(BundleContext, String, String) method to
// speed the service lookup process by
// giving one class as a hint to the OSGi implementation
// additionally this allows type filtering
String clazz = (ObjectUtils.isEmpty(classes) ? null : classes[0]);
return getServiceReferences(bundleContext, clazz, OsgiFilterUtils.unifyFilter(classes, filter));
}
示例12: queryForObject
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@Override
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException {
return (ObjectUtils.isEmpty(args) ?
getJdbcOperations().queryForObject(sql, requiredType) :
getJdbcOperations().queryForObject(sql, getArguments(args), requiredType));
}
示例13: getHeaderValues
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
@Override
public String[] getHeaderValues(String headerName) {
String[] headerValues = StringUtils.toStringArray(getRequest().getHeaders(headerName));
return (!ObjectUtils.isEmpty(headerValues) ? headerValues : null);
}
示例14: createSqlSessionFactory
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
private @Nullable
SqlSessionFactory createSqlSessionFactory(
ConfigurableListableBeanFactory configurableListableBeanFactory,
String prefixName, MybatisProperties mybatisProperties) {
DataSource dataSource = configurableListableBeanFactory
.getBean(prefixName + "Ds", DataSource.class);
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setVfs(LocSpringBootVFS.class);
Optional.ofNullable(mybatisProperties.getConfigLocation()).map(this.resourceLoader::getResource)
.ifPresent(sqlSessionFactoryBean::setConfigLocation);
org.apache.ibatis.session.Configuration configuration = mybatisProperties.getConfiguration();
if (configuration == null && !StringUtils.hasText(mybatisProperties.getConfigLocation())) {
configuration = new org.apache.ibatis.session.Configuration();
}
sqlSessionFactoryBean.setConfiguration(configuration);
Optional.ofNullable(mybatisProperties.getConfigurationProperties())
.ifPresent(sqlSessionFactoryBean::setConfigurationProperties);
Optional.ofNullable(mybatisProperties.getTypeAliasesPackage())
.ifPresent(sqlSessionFactoryBean::setTypeAliasesPackage);
Optional.ofNullable(mybatisProperties.getTypeHandlersPackage())
.ifPresent(sqlSessionFactoryBean::setTypeHandlersPackage);
if (!ObjectUtils.isEmpty(mybatisProperties.resolveMapperLocations())) {
sqlSessionFactoryBean.setMapperLocations(mybatisProperties.resolveMapperLocations());
}
try {
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
if (sqlSessionFactory == null) {
log.error("sqlSessionFactoryBean get object is null");
return null;
}
register(configurableListableBeanFactory, sqlSessionFactory, prefixName + "SessionFactory",
prefixName + "Sf");
if (!Strings.isNullOrEmpty(mybatisProperties.getBasePackage())) {
createBasePackageScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
mybatisProperties.getBasePackage(), prefixName);
} else {
createClassPathMapperScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
prefixName);
}
return sqlSessionFactory;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
示例15: mybatisSqlSessionFactoryBean
import org.springframework.util.ObjectUtils; //導入方法依賴的package包/類
/**
* 這裏全部使用mybatis-autoconfigure 已經自動加載的資源。不手動指定
* 配置文件和mybatis-boot的配置文件同步
* @return
*/
@Bean
@ConditionalOnMissingBean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
mybatisPlus.setDataSource(dataSource);
mybatisPlus.setVfs(SpringBootVFS.class);
if (StringUtils.hasText(this.properties.getConfigLocation())) {
mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
}
mybatisPlus.setConfiguration(properties.getConfiguration());
if (!ObjectUtils.isEmpty(this.interceptors)) {
mybatisPlus.setPlugins(this.interceptors);
}
// MP 全局配置,更多內容進入類看注釋
GlobalConfiguration globalConfig = new GlobalConfiguration();
//駝峰下劃線規則
globalConfig.setDbColumnUnderline(true);
globalConfig.setDbType(DBType.MYSQL.name());
// ID 策略
// AUTO->`0`("數據庫ID自增")
// INPUT->`1`(用戶輸入ID")
// ID_WORKER->`2`("全局唯一ID")
// UUID->`3`("全局唯一ID")
globalConfig.setIdType(3);
mybatisPlus.setGlobalConfig(globalConfig);
MybatisConfiguration mc = new MybatisConfiguration();
mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
mybatisPlus.setConfiguration(mc);
if (this.databaseIdProvider != null) {
mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
}
if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
}
if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
}
if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
}
return mybatisPlus;
}