Skip to content

Commit

Permalink
代码优化 com.feilong.core.lang.StringUtil.formatPattern(String, Object...)
Browse files Browse the repository at this point in the history
换成static import fix #689
  • Loading branch information
venusdrogon committed Jan 24, 2024
1 parent 1126063 commit 8c9e304
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.feilong.component.upload;

import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.CollectionsUtil.newArrayList;

import java.io.IOException;
Expand All @@ -27,7 +28,6 @@
import org.springframework.web.multipart.MultipartFile;

import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.io.IOWriteUtil;
import com.feilong.json.JsonUtil;

Expand Down Expand Up @@ -76,7 +76,7 @@ public String upload(MultipartFile multipartFile,String directoryName,String fil
try (InputStream inputStream = multipartFile.getInputStream()){
return IOWriteUtil.write(inputStream, directoryName, fileName);
}catch (IOException e){
throw new UncheckedIOException(StringUtil.formatPattern("directoryName:[{}],fileName:[{}]", directoryName, fileName), e);
throw new UncheckedIOException(formatPattern("directoryName:[{}],fileName:[{}]", directoryName, fileName), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.feilong.component.upload;

import static com.feilong.core.date.DateUtil.nowTimestamp;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.lang.SystemUtil.USER_HOME;

import java.util.List;
Expand All @@ -30,7 +31,6 @@

import com.feilong.context.fileparser.FileParser;
import com.feilong.context.fileparser.RequestFileParserDetector;
import com.feilong.core.lang.StringUtil;
import com.feilong.io.FilenameUtil;

public class UploadController{
Expand Down Expand Up @@ -69,7 +69,7 @@ private static String[] resolverNewFileNames(MultipartFile...multipartFiles){
for (int i = 0; i < multipartFiles.length; ++i){
MultipartFile multipartFile = multipartFiles[i];
if (!multipartFile.isEmpty()){
fileNames[i] = StringUtil.formatPattern(
fileNames[i] = formatPattern(
"{}.{}",
nowTimestamp() + "-" + i,
FilenameUtil.getExtension(multipartFile.getOriginalFilename()));//文件后缀
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
package com.feilong.context;

import static com.feilong.core.lang.StringUtil.formatPattern;

import java.util.Map;

import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.core.lang.reflect.FieldUtil;
import com.feilong.json.JsonUtil;

Expand Down Expand Up @@ -83,6 +84,6 @@ public static String buildFieldsSimpleMessage(Object obj){
* @since 1.11.5
*/
private static String build(Object obj,String mapInfo){
return StringUtil.formatPattern("[{}] field's value map:\n[{}]", obj.getClass().getCanonicalName(), mapInfo);
return formatPattern("[{}] field's value map:\n[{}]", obj.getClass().getCanonicalName(), mapInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
package com.feilong.context.converter;

import static com.feilong.core.Validator.isNullOrEmpty;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.formatter.FormatterUtil.formatToSimpleTable;
import static java.lang.System.lineSeparator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.feilong.core.lang.StringUtil;

/**
* 抽象的将 字符串转成 bean 的转换器.
*
Expand Down Expand Up @@ -73,9 +71,9 @@ public T convert(String value){
private void preHandlerLog(String value){
if (LOGGER.isDebugEnabled()){
try{
LOGGER.debug("input String:[{}],after format:{} {}", value, lineSeparator(), formatValue(value));
LOGGER.debug("inputString:[{}],afterFormat: {}", value, formatValue(value));
}catch (Exception e){
String message = StringUtil.formatPattern("inputString:[{}] can't format,message:[{}]", value, e.getMessage());
String message = formatPattern("inputString:[{}] can't format,message:[{}]", value, e.getMessage());
throw new IllegalArgumentException(message, e);
}
}
Expand Down Expand Up @@ -112,8 +110,7 @@ protected String formatValue(String value){
* @param inputString
* the input string
*/
@SuppressWarnings("unused")
protected void preHandler(String inputString){
protected void preHandler(@SuppressWarnings("unused") String inputString){
}

//---------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.feilong.coreextension.awt;

import static com.feilong.core.CharsetType.UTF8;
import static com.feilong.core.lang.StringUtil.formatPattern;

import java.awt.Desktop;
import java.awt.Desktop.Action;
Expand All @@ -25,7 +26,6 @@
import java.net.URI;

import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.core.net.URIUtil;

/**
Expand Down Expand Up @@ -141,7 +141,7 @@ private static void desktopAction(String urlPattern,Action action,Object...args)
Validate.notNull(action, "action can't be null!");

//---------------------------------------------------------------
String url = StringUtil.formatPattern(urlPattern, args);
String url = formatPattern(urlPattern, args);

Desktop desktop = getDesktop(action);

Expand All @@ -163,10 +163,10 @@ private static void desktopAction(String urlPattern,Action action,Object...args)
desktop.print(new File(url));
break;
default:
throw new UnsupportedOperationException(StringUtil.formatPattern("[{}] not support!", action));
throw new UnsupportedOperationException(formatPattern("[{}] not support!", action));
}
}catch (IOException e){
throw new UncheckedIOException(StringUtil.formatPattern("[{}],[{}]", url, action), e);
throw new UncheckedIOException(formatPattern("[{}],[{}]", url, action), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package com.feilong.core;

import static com.feilong.core.Validator.isNullOrEmpty;

import com.feilong.core.lang.StringUtil;
import static com.feilong.core.lang.StringUtil.formatPattern;

/**
* 默认的 RuntimeException.
Expand Down Expand Up @@ -199,7 +198,7 @@ public DefaultRuntimeException(String message){
* the args
*/
public DefaultRuntimeException(String messagePattern, Object...args){
super(StringUtil.formatPattern(messagePattern, args));
super(formatPattern(messagePattern, args));
}

//---------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions feilong-core/src/main/java/com/feilong/core/bean/BeanUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.feilong.core.Validator.isNotNullOrEmpty;
import static com.feilong.core.Validator.isNullOrEmpty;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.MapUtil.newHashMap;
import static java.util.Collections.emptyMap;

Expand All @@ -28,7 +29,6 @@
import org.apache.commons.beanutils.DynaBean;

import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.lib.beanutils.BeanUtils;
import com.feilong.lib.beanutils.LazyDynaBean;
import com.feilong.lib.lang3.reflect.FieldUtils;
Expand Down Expand Up @@ -296,7 +296,7 @@ public static void copyProperties(Object toObj,Object fromObj,String...includePr
return;
}catch (Exception e){
String pattern = "copyProperties exception,toObj:[{}],fromObj:[{}],includePropertyNames:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, toObj, fromObj, includePropertyNames), e);
throw new BeanOperationException(formatPattern(pattern, toObj, fromObj, includePropertyNames), e);
}
}

Expand Down Expand Up @@ -338,7 +338,7 @@ private static void setProperty(Object bean,String propertyName,Object value){
BeanUtils.setProperty(bean, propertyName, value);
}catch (Exception e){
String pattern = "setProperty exception,bean:[{}],propertyName:[{}],value:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyName, value), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyName, value), e);
}
}

Expand Down Expand Up @@ -380,7 +380,7 @@ private static String getProperty(Object bean,String propertyName){
return BeanUtils.getProperty(bean, propertyName);
}catch (Exception e){
String pattern = "getProperty exception,bean:[{}],propertyName:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyName), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyName), e);
}
}

Expand Down Expand Up @@ -437,7 +437,7 @@ public static <T> T cloneBean(T bean){
try{
return (T) BeanUtils.cloneBean(bean);
}catch (Exception e){
String message = StringUtil.formatPattern("cloneBean exception,bean:[{}]]", bean);
String message = formatPattern("cloneBean exception,bean:[{}]]", bean);
throw new BeanOperationException(message, e);
}
}
Expand Down Expand Up @@ -699,7 +699,7 @@ public static <T> T populate(T bean,Map<String, ?> properties){
BeanUtils.populate(bean, properties);
return bean;
}catch (Exception e){
String message = StringUtil.formatPattern("can't populate:[{}] to bean:{}", properties, bean);
String message = formatPattern("can't populate:[{}] to bean:{}", properties, bean);
throw new BeanOperationException(message, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.feilong.core.Validator.isNotNullOrEmpty;
import static com.feilong.core.Validator.isNullOrEmpty;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.MapUtil.newLinkedHashMap;

import java.beans.PropertyDescriptor;
Expand All @@ -28,7 +29,6 @@

import com.feilong.core.Validate;
import com.feilong.core.lang.ClassUtil;
import com.feilong.core.lang.StringUtil;
import com.feilong.lib.beanutils.PropertyUtils;
import com.feilong.lib.lang3.ClassUtils;

Expand Down Expand Up @@ -100,7 +100,7 @@ public static PropertyDescriptor[] getPropertyDescriptors(Class<?> klass){
return PropertyUtils.getPropertyDescriptors(klass);
}catch (Exception e){
String pattern = "getPropertyDescriptors exception,klass:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, klass), e);
throw new BeanOperationException(formatPattern(pattern, klass), e);
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public static void copyProperties(Object toObj,Object fromObj,String...includePr
return;
}catch (Exception e){
String pattern = "copyProperties exception,toObj:[{}],fromObj:[{}],includePropertyNames:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, toObj, fromObj, includePropertyNames), e);
throw new BeanOperationException(formatPattern(pattern, toObj, fromObj, includePropertyNames), e);
}
}

Expand Down Expand Up @@ -370,7 +370,7 @@ public static Map<String, Object> describe(Object bean,String...propertyNames){
return PropertyUtils.describe(bean);
}catch (Exception e){
String pattern = "describe exception,bean:[{}],propertyNames:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyNames), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyNames), e);
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ public static void setProperty(Object bean,String propertyName,Object value){
PropertyUtils.setProperty(bean, propertyName, value);
}catch (Exception e){
String pattern = "setProperty exception,bean:[{}],propertyName:[{}],value:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyName, value), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyName, value), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.feilong.core.bean.ConvertUtil.convert;
import static com.feilong.core.bean.PropertyDescriptorUtil.getSpringPropertyDescriptor;
import static com.feilong.core.bean.PropertyDescriptorUtil.isUseSpringOperate;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.CollectionsUtil.first;

import java.beans.PropertyDescriptor;
Expand All @@ -29,7 +30,6 @@

import com.feilong.core.DefaultRuntimeException;
import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.lib.beanutils.PropertyUtils;

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ private static <T> T getDataUseApache(Object bean,String propertyName){
return (T) PropertyUtils.getProperty(bean, propertyName);
}catch (Exception e){
String pattern = "getProperty exception,bean:[{}],propertyName:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyName), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyName), e);
}
}

Expand All @@ -113,7 +113,7 @@ private static <T> T getDataUseSpring(Object bean,String propertyName){
return getValue(bean, propertyDescriptor);
}catch (Exception e){
String pattern = "getProperty exception,bean:[{}],propertyName:[{}]";
throw new BeanOperationException(StringUtil.formatPattern(pattern, bean, propertyName), e);
throw new BeanOperationException(formatPattern(pattern, bean, propertyName), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.feilong.core.date.CalendarUtil.resetDayBegin;
import static com.feilong.core.date.CalendarUtil.resetDayEnd;
import static com.feilong.core.date.CalendarUtil.resetYearEnd;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.ResourceBundleUtil.getResourceBundle;
import static com.feilong.core.util.ResourceBundleUtil.toMap;
import static java.util.Calendar.DAY_OF_MONTH;
Expand All @@ -51,7 +52,6 @@
import com.feilong.core.DatePattern;
import com.feilong.core.TimeInterval;
import com.feilong.core.Validate;
import com.feilong.core.lang.StringUtil;
import com.feilong.lib.lang3.time.DateFormatUtils;
import com.feilong.lib.lang3.time.DateUtils;
import com.feilong.lib.lang3.tuple.Pair;
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public static Date toDate(String dateString,String...datePatterns){
return DateUtils.parseDate(dateString, datePatterns);
}catch (ParseException e){
String pattern = "dateString:[{}],use patterns:[{}],parse to date exception,message:[{}]";
throw new IllegalArgumentException(StringUtil.formatPattern(pattern, dateString, datePatterns, e.getMessage()), e);
throw new IllegalArgumentException(formatPattern(pattern, dateString, datePatterns, e.getMessage()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.feilong.core.lang;

import static com.feilong.core.bean.ConvertUtil.toList;
import static com.feilong.core.lang.StringUtil.formatPattern;
import static com.feilong.core.util.MapUtil.newLinkedHashMap;

import java.io.InputStream;
Expand Down Expand Up @@ -346,7 +347,7 @@ private static ClassLoader getClassLoaderByClass(Class<?> callingClass){
*/
private static String getLogInfo(String resourceName,ClassLoader classLoader,boolean isFouned){
String message = "{}found [{}],in ClassLoader:[{}]";
return StringUtil.formatPattern(message, isFouned ? "" : "not ", resourceName, formatClassLoader(classLoader));
return formatPattern(message, isFouned ? "" : "not ", resourceName, formatClassLoader(classLoader));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.feilong.core.lang;

import static com.feilong.core.lang.StringUtil.formatPattern;

import java.lang.reflect.Modifier;

import com.feilong.core.Validate;
Expand Down Expand Up @@ -445,7 +447,7 @@ public static Class<?> getClass(String className){
try{
return com.feilong.lib.lang3.ClassUtils.getClass(className);
}catch (Exception e){
throw new ReflectException(StringUtil.formatPattern("className:[{}]", className), e);
throw new ReflectException(formatPattern("className:[{}]", className), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.feilong.core.lang;

import static com.feilong.core.lang.StringUtil.formatPattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -241,7 +243,7 @@ private static <E extends Enum<?>, T> E getEnumByPropertyValue(
//---------------------------------------------------------------
if (LOGGER.isDebugEnabled()){
String messagePattern = "[{}],propertyName:[{}],value:[{}],ignoreCase:[{}],constants not found";
LOGGER.debug(StringUtil.formatPattern(messagePattern, enumClass, propertyName, specifiedValue, ignoreCase));
LOGGER.debug(formatPattern(messagePattern, enumClass, propertyName, specifiedValue, ignoreCase));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static byte[] getBytes(String value,String charsetName){
return value.getBytes(charsetName);
}catch (UnsupportedEncodingException e){
String pattern = "value:[{}],charsetName:[{}],suggest you use [{}] constants";
String message = StringUtil.formatPattern(pattern, value, charsetName, CharsetType.class.getCanonicalName());
String message = formatPattern(pattern, value, charsetName, CharsetType.class.getCanonicalName());
throw new UncheckedIOException(message, e);
}
}
Expand Down
Loading

0 comments on commit 8c9e304

Please sign in to comment.