Commit 5c9855fc by stylefeng

整理包结构

parent 3647b776
package com.stylefeng.guns.core.util.qr;
package com.stylefeng.guns.core.qr;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.stylefeng.guns.core.util.qr;
package com.stylefeng.guns.core.qr;
import java.awt.image.BufferedImage;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.util.qr;
package com.stylefeng.guns.core.qr;
import com.google.zxing.common.BitMatrix;
......
package com.stylefeng.guns.core.util.qr;
package com.stylefeng.guns.core.qr;
/**
* 二维码图片对象
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import java.util.HashMap;
import java.util.Map;
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import com.stylefeng.guns.core.support.exception.ToolBoxException;
import com.stylefeng.guns.core.util.Convert;
import com.stylefeng.guns.core.util.support.exception.ToolBoxException;
import java.beans.*;
import java.lang.reflect.Method;
......@@ -34,14 +34,14 @@ public class BeanKit {
}
return false;
}
public static PropertyEditor findEditor(Class<?> type){
return PropertyEditorManager.findEditor(type);
}
/**
* 获得Bean字段描述数组
*
*
* @param clazz Bean类
* @return 字段描述数组
* @throws IntrospectionException
......@@ -49,7 +49,7 @@ public class BeanKit {
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws IntrospectionException {
return Introspector.getBeanInfo(clazz).getPropertyDescriptors();
}
/**
* 获得字段名和字段描述Map
* @param clazz Bean类
......@@ -67,7 +67,7 @@ public class BeanKit {
/**
* 获得Bean类属性描述
*
*
* @param clazz Bean类
* @param fieldName 字段名
* @return PropertyDescriptor
......@@ -82,10 +82,10 @@ public class BeanKit {
}
return null;
}
/**
* Map转换为Bean对象
*
*
* @param map Map
* @param beanClass Bean Class
* @return Bean
......@@ -97,7 +97,7 @@ public class BeanKit {
/**
* Map转换为Bean对象<br>
* 忽略大小写
*
*
* @param map Map
* @param beanClass Bean Class
* @return Bean
......@@ -108,7 +108,7 @@ public class BeanKit {
/**
* 使用Map填充Bean对象
*
*
* @param map Map
* @param bean Bean
* @return Bean
......@@ -121,10 +121,10 @@ public class BeanKit {
}
});
}
/**
* 使用Map填充Bean对象,可配置将下划线转换为驼峰
*
*
* @param map Map
* @param bean Bean
* @param isToCamelCase 是否将下划线模式转换为驼峰模式
......@@ -144,13 +144,13 @@ public class BeanKit {
}
return fillBeanWithMap(map2, bean);
}
return fillBeanWithMap(map, bean);
}
/**
* 使用Map填充Bean对象,忽略大小写
*
*
* @param map Map
* @param bean Bean
* @return Bean
......@@ -177,7 +177,7 @@ public class BeanKit {
/**
* ServletRequest 参数转Bean
*
*
* @param request ServletRequest
* @param beanClass Bean Class
* @return Bean
......@@ -188,7 +188,7 @@ public class BeanKit {
/**
* ServletRequest 参数转Bean
*
*
* @param request ServletRequest
* @param bean Bean
* @return Bean
......@@ -214,7 +214,7 @@ public class BeanKit {
/**
* ServletRequest 参数转Bean
*
*
* @param <T>
* @param beanClass Bean Class
* @param valueProvider 值提供者
......@@ -226,7 +226,7 @@ public class BeanKit {
/**
* 填充Bean
*
*
* @param <T>
* @param bean Bean
* @param valueProvider 值提供者
......@@ -259,10 +259,10 @@ public class BeanKit {
}
return bean;
}
/**
* 对象转Map
*
*
* @param bean bean对象
* @return Map
*/
......@@ -272,7 +272,7 @@ public class BeanKit {
/**
* 对象转Map
*
*
* @param bean bean对象
* @param isToUnderlineCase 是否转换为下划线模式
* @return Map
......@@ -311,7 +311,7 @@ public class BeanKit {
public static void copyProperties(Object source, Object target) {
copyProperties(source, target, CopyOptions.create());
}
/**
* 复制Bean对象属性<br>
* 限制类用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类
......@@ -322,7 +322,7 @@ public class BeanKit {
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
}
/**
* 复制Bean对象属性<br>
* 限制类用于限制拷贝的属性,例如一个类我只想复制其父类的一些属性,就可以将editable设置为父类
......@@ -334,7 +334,7 @@ public class BeanKit {
if(null == copyOptions){
copyOptions = new CopyOptions();
}
Class<?> actualEditable = target.getClass();
if (copyOptions.editable != null) {
//检查限制类是否为target的父类或接口
......@@ -351,7 +351,7 @@ public class BeanKit {
} catch (IntrospectionException e) {
throw new ToolBoxException(e);
}
HashSet<String> ignoreSet = copyOptions.ignoreProperties != null ? CollectionKit.newHashSet(copyOptions.ignoreProperties) : null;
for (PropertyDescriptor targetPd : targetPds) {
Method writeMethod = targetPd.getWriteMethod();
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import com.stylefeng.guns.core.util.support.exception.ToolBoxException;
import com.stylefeng.guns.core.support.exception.ToolBoxException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import com.stylefeng.guns.core.util.support.exception.ToolBoxException;
import com.stylefeng.guns.core.support.exception.ToolBoxException;
import java.lang.reflect.Array;
import java.util.*;
......@@ -88,7 +88,7 @@ public class CollectionKit {
final int[] startEnd = PageKit.transToStartEnd(pageNo, numPerPage);
return result.subList(startEnd[0], startEnd[1]);
}
/**
* 将多个集合排序并显示不同的段落(分页)
* @param pageNo 页码
......@@ -103,19 +103,19 @@ public class CollectionKit {
// for (Collection<T> coll : colls) {
// queue.addAll(coll);
// }
//
//
// //第一页且数目少于第一页显示的数目
// if(pageNo <=1 && queue.size() <= numPerPage) {
// return queue.toList();
// }
//
//
// final int[] startEnd = PageKit.transToStartEnd(pageNo, numPerPage);
// return queue.toList().subList(startEnd[0], startEnd[1]);
// }
/**
* 将Set排序(根据Entry的值)
*
*
* @param set 被排序的Set
* @return 排序后的Set
*/
......@@ -139,7 +139,7 @@ public class CollectionKit {
/**
* 切取部分数据
*
*
* @param <T> 集合元素类型
* @param surplusAlaDatas 原数据
* @param partSize 每部分数据的长度
......@@ -164,10 +164,10 @@ public class CollectionKit {
}
return currentAlaDatas;
}
/**
* 切取部分数据
*
*
* @param <T> 集合元素类型
* @param surplusAlaDatas 原数据
* @param partSize 每部分数据的长度
......@@ -195,13 +195,13 @@ public class CollectionKit {
/**
* 新建一个HashMap
*
*
* @return HashMap对象
*/
public static <T, K> HashMap<T, K> newHashMap() {
return new HashMap<T, K>();
}
/**
* 新建一个HashMap
* @param size 初始大小,由于默认负载因子0.75,传入的size会实际初始大小为size / 0.75
......@@ -213,16 +213,16 @@ public class CollectionKit {
/**
* 新建一个HashSet
*
*
* @return HashSet对象
*/
public static <T> HashSet<T> newHashSet() {
return new HashSet<T>();
}
/**
* 新建一个HashSet
*
*
* @return HashSet对象
*/
@SafeVarargs
......@@ -236,27 +236,27 @@ public class CollectionKit {
/**
* 新建一个ArrayList
*
*
* @return ArrayList对象
*/
public static <T> ArrayList<T> newArrayList() {
return new ArrayList<T>();
}
/**
* 新建一个ArrayList
*
*
* @return ArrayList对象
*/
@SafeVarargs
public static <T> ArrayList<T> newArrayList(T... values) {
return new ArrayList<T>(Arrays.asList(values));
}
/**
* 将新元素添加到已有数组中<br/>
* 添加新元素会生成一个新的数组,不影响原数组
*
*
* @param buffer 已有数组
* @param newElement 新元素
* @return 新数组
......@@ -269,7 +269,7 @@ public class CollectionKit {
/**
* 生成一个新的重新设置大小的数组
*
*
* @param buffer 原数组
* @param newSize 新的数组大小
* @param componentType 数组元素类型
......@@ -280,7 +280,7 @@ public class CollectionKit {
System.arraycopy(buffer, 0, newArray, 0, buffer.length >= newSize ? newSize : buffer.length);
return newArray;
}
/**
* 新建一个空数组
* @param componentType 元素类型
......@@ -295,7 +295,7 @@ public class CollectionKit {
/**
* 生成一个新的重新设置大小的数组<br/>
* 新数组的类型为原数组的类型
*
*
* @param buffer 原数组
* @param newSize 新的数组大小
* @return 调整后的新数组
......@@ -307,7 +307,7 @@ public class CollectionKit {
/**
* 将多个数组合并在一起<br>
* 忽略null的数组
*
*
* @param arrays 数组集合
* @return 合并后的数组
*/
......@@ -316,7 +316,7 @@ public class CollectionKit {
if (arrays.length == 1) {
return arrays[0];
}
int length = 0;
for (T[] array : arrays) {
if(array == null) {
......@@ -348,7 +348,7 @@ public class CollectionKit {
}
return array.clone();
}
/**
* 生成一个数字列表<br>
* 自动判定正序反序
......@@ -358,7 +358,7 @@ public class CollectionKit {
public static int[] range(int excludedEnd) {
return range(0, excludedEnd, 1);
}
/**
* 生成一个数字列表<br>
* 自动判定正序反序
......@@ -369,7 +369,7 @@ public class CollectionKit {
public static int[] range(int includedStart, int excludedEnd) {
return range(includedStart, excludedEnd, 1);
}
/**
* 生成一个数字列表<br>
* 自动判定正序反序
......@@ -384,11 +384,11 @@ public class CollectionKit {
includedStart = excludedEnd;
excludedEnd = tmp;
}
if(step <=0) {
step = 1;
}
int deviation = excludedEnd - includedStart;
int length = deviation / step;
if(deviation % step != 0) {
......@@ -401,7 +401,7 @@ public class CollectionKit {
}
return range;
}
/**
* 截取数组的部分
* @param list 被截取的数组
......@@ -413,20 +413,20 @@ public class CollectionKit {
if(list == null || list.isEmpty()) {
return null;
}
if(start < 0) {
start = 0;
}
if(end < 0) {
end = 0;
}
if(start > end) {
int tmp = start;
start = end;
end = tmp;
}
final int size = list.size();
if(end > size) {
if(start >= size) {
......@@ -434,10 +434,10 @@ public class CollectionKit {
}
end = size;
}
return list.subList(start, end);
}
/**
* 截取集合的部分
* @param list 被截取的数组
......@@ -449,10 +449,10 @@ public class CollectionKit {
if(list == null || list.isEmpty()) {
return null;
}
return sub(new ArrayList<T>(list), start, end);
}
/**
* 数组是否为空
* @param array 数组
......@@ -461,7 +461,7 @@ public class CollectionKit {
public static <T> boolean isEmpty(T[] array) {
return array == null || array.length == 0;
}
/**
* 数组是否为非空
* @param array 数组
......@@ -470,7 +470,7 @@ public class CollectionKit {
public static <T> boolean isNotEmpty(T[] array) {
return false == isEmpty(array);
}
/**
* 集合是否为空
* @param collection 集合
......@@ -479,7 +479,7 @@ public class CollectionKit {
public static boolean isEmpty(Collection<?> collection) {
return collection == null || collection.isEmpty();
}
/**
* 集合是否为非空
* @param collection 集合
......@@ -488,7 +488,7 @@ public class CollectionKit {
public static boolean isNotEmpty(Collection<?> collection) {
return false == isEmpty(collection);
}
/**
* Map是否为空
* @param map 集合
......@@ -497,7 +497,7 @@ public class CollectionKit {
public static boolean isEmpty(Map<?, ?> map) {
return map == null || map.isEmpty();
}
/**
* Map是否为非空
* @param map 集合
......@@ -506,7 +506,7 @@ public class CollectionKit {
public static <T> boolean isNotEmpty(Map<?, ?> map) {
return false == isEmpty(map);
}
/**
* 映射键值(参考Python的zip()函数)<br>
* 例如:<br>
......@@ -522,16 +522,16 @@ public class CollectionKit {
if(isEmpty(keys) || isEmpty(values)) {
return null;
}
final int size = Math.min(keys.length, values.length);
final Map<T, K> map = new HashMap<T, K>((int)(size / 0.75));
for(int i = 0; i < size; i++) {
map.put(keys[i], values[i]);
}
return map;
}
/**
* 映射键值(参考Python的zip()函数)<br>
* 例如:<br>
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import java.util.Date;
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import com.stylefeng.guns.core.util.support.exception.ToolBoxException;
import com.stylefeng.guns.core.support.exception.ToolBoxException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
......@@ -77,7 +77,7 @@ public class DateTimeKit {
/**
* 当前时间long
*
*
* @param isNano 是否为高精度时间
* @return 时间
*/
......@@ -87,7 +87,7 @@ public class DateTimeKit {
/**
* 当前日期,格式 yyyy-MM-dd
*
*
* @return 当前日期的标准形式字符串
*/
public static String today() {
......@@ -117,7 +117,7 @@ public class DateTimeKit {
/**
* Long类型时间转为Date
*
*
* @param date Long类型Date(Unix时间戳)
* @return 时间对象
*/
......@@ -127,7 +127,7 @@ public class DateTimeKit {
/**
* 转换为Calendar对象
*
*
* @param date 日期对象
* @return Calendar对象
*/
......@@ -139,7 +139,7 @@ public class DateTimeKit {
/**
* 获得月份,从1月开始计数
*
*
* @param date 日期
* @return 月份
*/
......@@ -149,7 +149,7 @@ public class DateTimeKit {
/**
* 获得年
*
*
* @param date 日期
* @return 年
*/
......@@ -159,7 +159,7 @@ public class DateTimeKit {
/**
* 获得季节
*
*
* @param date 日期
* @return 第几个季节
*/
......@@ -170,7 +170,7 @@ public class DateTimeKit {
/**
* 获得指定日期年份和季节<br>
* 格式:[20131]表示2013年第一季度
*
*
* @param date 日期
* @return Season ,类似于 20132
*/
......@@ -180,7 +180,7 @@ public class DateTimeKit {
/**
* 获得指定日期区间内的年份和季节<br>
*
*
* @param startDate 其实日期(包含)
* @param endDate 结束日期(包含)
* @return Season列表 ,元素类似于 20132
......@@ -215,7 +215,7 @@ public class DateTimeKit {
// ------------------------------------ Format start ----------------------------------------------
/**
* 根据特定格式格式化日期
*
*
* @param date 被格式化的日期
* @param format 格式
* @return 格式化后的字符串
......@@ -226,7 +226,7 @@ public class DateTimeKit {
/**
* 格式 yyyy-MM-dd HH:mm:ss
*
*
* @param date 被格式化的日期
* @return 格式化后的日期
*/
......@@ -239,7 +239,7 @@ public class DateTimeKit {
/**
* 格式 yyyy-MM-dd
*
*
* @param date 被格式化的日期
* @return 格式化后的字符串
*/
......@@ -252,7 +252,7 @@ public class DateTimeKit {
/**
* 格式化为Http的标准日期格式
*
*
* @param date 被格式化的日期
* @return HTTP标准形式日期字符串
*/
......@@ -268,7 +268,7 @@ public class DateTimeKit {
/**
* 构建DateTime对象
*
*
* @param dateStr Date字符串
* @param simpleDateFormat 格式化器
* @return DateTime对象
......@@ -283,7 +283,7 @@ public class DateTimeKit {
/**
* 将特定格式的日期转换为Date对象
*
*
* @param dateString 特定格式的日期
* @param format 格式,例如yyyy-MM-dd
* @return 日期对象
......@@ -294,7 +294,7 @@ public class DateTimeKit {
/**
* 格式yyyy-MM-dd HH:mm:ss
*
*
* @param dateString 标准形式的时间字符串
* @return 日期对象
*/
......@@ -304,7 +304,7 @@ public class DateTimeKit {
/**
* 格式yyyy-MM-dd
*
*
* @param dateString 标准形式的日期字符串
* @return 日期对象
*/
......@@ -314,7 +314,7 @@ public class DateTimeKit {
/**
* 格式HH:mm:ss
*
*
* @param timeString 标准形式的日期字符串
* @return 日期对象
*/
......@@ -328,7 +328,7 @@ public class DateTimeKit {
* 2、yyyy-MM-dd<br>
* 3、HH:mm:ss<br>
* 4、yyyy-MM-dd HH:mm 5、yyyy-MM-dd HH:mm:ss.SSS
*
*
* @param dateStr 日期字符串
* @return 日期
*/
......@@ -362,7 +362,7 @@ public class DateTimeKit {
// ------------------------------------ Offset start ----------------------------------------------
/**
* 获取某天的开始时间
*
*
* @param date 日期
* @return 某天的开始时间
*/
......@@ -378,7 +378,7 @@ public class DateTimeKit {
/**
* 获取某天的结束时间
*
*
* @param date 日期
* @return 某天的结束时间
*/
......@@ -394,7 +394,7 @@ public class DateTimeKit {
/**
* 昨天
*
*
* @return 昨天
*/
public static DateTime yesterday() {
......@@ -403,7 +403,7 @@ public class DateTimeKit {
/**
* 上周
*
*
* @return 上周
*/
public static DateTime lastWeek() {
......@@ -412,7 +412,7 @@ public class DateTimeKit {
/**
* 上个月
*
*
* @return 上个月
*/
public static DateTime lastMouth() {
......@@ -421,7 +421,7 @@ public class DateTimeKit {
/**
* 偏移天
*
*
* @param date 日期
* @param offsite 偏移天数,正数向未来偏移,负数向历史偏移
* @return 偏移后的日期
......@@ -432,7 +432,7 @@ public class DateTimeKit {
/**
* 偏移周
*
*
* @param date 日期
* @param offsite 偏移周数,正数向未来偏移,负数向历史偏移
* @return 偏移后的日期
......@@ -443,7 +443,7 @@ public class DateTimeKit {
/**
* 偏移月
*
*
* @param date 日期
* @param offsite 偏移月数,正数向未来偏移,负数向历史偏移
* @return 偏移后的日期
......@@ -454,7 +454,7 @@ public class DateTimeKit {
/**
* 获取指定日期偏移指定时间后的时间
*
*
* @param date 基准日期
* @param calendarField 偏移的粒度大小(小时、天、月等)使用Calendar中的常数
* @param offsite 偏移量,正数为向后偏移,负数为向前偏移
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import java.nio.charset.Charset;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
/**
* 一些通用的函数
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
/**
* 分页工具类
......
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import java.io.StringReader;
import java.io.StringWriter;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import java.util.regex.Pattern;
......
......@@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.stylefeng.guns.core.util.support;
package com.stylefeng.guns.core.support;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
......
......@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stylefeng.guns.core.util.support.exception;
package com.stylefeng.guns.core.support.exception;
import com.stylefeng.guns.core.util.support.StrKit;
import com.stylefeng.guns.core.support.StrKit;
/**
* 工具类初始化异常
......
package com.stylefeng.guns.core.util;
import com.stylefeng.guns.core.util.support.*;
import com.stylefeng.guns.core.util.support.exception.ToolBoxException;
import com.stylefeng.guns.core.support.*;
import com.stylefeng.guns.core.support.exception.ToolBoxException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
......
package com.stylefeng.guns.core.util;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;
/**
* 对比两个对象的变化的工具类
*
* @author fengshuonan
* @Date 2017/3/31 10:36
*/
public class SimpleContrast {
//记录每个修改字段的分隔符
public static final String separator = ";;;";
/**
* 比较两个对象,并返回不一致的信息
*
* @author stylefeng
* @Date 2017/5/9 19:34
*/
public static String contrastObj(Object pojo1, Object pojo2) {
String str = "";
try {
Class clazz = pojo1.getClass();
Field[] fields = pojo1.getClass().getDeclaredFields();
int i = 1;
for (Field field : fields) {
if ("serialVersionUID".equals(field.getName())) {
continue;
}
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
Method getMethod = pd.getReadMethod();
Object o1 = getMethod.invoke(pojo1);
Object o2 = getMethod.invoke(pojo2);
if (o1 == null || o2 == null) {
continue;
}
if (o1 instanceof Date) {
o1 = DateUtil.getDay((Date) o1);
}
if (!o1.toString().equals(o2.toString())) {
if (i != 1) {
str += separator;
}
str += "字段名称" + field.getName() + ",旧值:" + o1 + ",新值:" + o2;
i++;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
\ No newline at end of file
......@@ -15,7 +15,8 @@
*/
package com.stylefeng.guns.core.util;
import com.stylefeng.guns.core.util.support.StrKit;
import com.stylefeng.guns.core.support.StrKit;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
......
package com.stylefeng.guns.core.util.xss;
package com.stylefeng.guns.core.xss;
import javax.servlet.*;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment