3 Star 8 Fork 4

易水风萧 / tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

快速启动

本工具包主要集成了目前在项目开发过程中个人经常会使用到的一些工具类,对工具类进行了一下简单的封装。该工具常用的工具有:

工具类路径 作用说明
com.yishuifengxiao.common.tool.bean java bean 操作工具
com.yishuifengxiao.common.tool.collections java 集合操作工具
com.yishuifengxiao.common.tool.context 数据存储工具
com.yishuifengxiao.common.tool.converter 数据转换工具
com.yishuifengxiao.common.tool.datetime 日期时间工具
com.yishuifengxiao.common.tool.encoder 加解密工具
com.yishuifengxiao.common.tool.entity 基础通用对象
com.yishuifengxiao.common.tool.exception 自定义异常
com.yishuifengxiao.common.tool.exception.constant 异常错误码常量
com.yishuifengxiao.common.tool.http HTTP操作工具
com.yishuifengxiao.common.tool.io IO流和文件操作工具
com.yishuifengxiao.common.tool.lang 常见数据类型的封装工具
com.yishuifengxiao.common.tool.log 日志工具
com.yishuifengxiao.common.tool.random 随机工具
com.yishuifengxiao.common.tool.sensitive 脱敏工具
com.yishuifengxiao.common.tool.utils 自定义工具
com.yishuifengxiao.common.tool.validate 自定义校验工具

工具包已经发布到maven中央仓库,使用方法如下:

<dependency>
	<groupId>com.yishuifengxiao.common</groupId>
	<artifactId>common-tool</artifactId>
	<version>4.3.0</version>
</dependency>

最新版的版本号参见 https://mvnrepository.com/artifact/com.yishuifengxiao.common/common-tool

工具类说明文档的地址为 https://apidoc.gitee.com/zhiyubujian/tool/

一 Bean操作工具

1.1 对象转换工具

该工具的主要目的是将源对象转换为目标对象,其主要功能如下:

  • 将源对象里属性值复制给目标对象
  • 将Java对象序列化为二进制数据
  • 将序列化化后的二进制数据反序列化为对象

工具路径:

 com.yishuifengxiao.common.tool.bean.BeanUtil

使用示例:


CustomException e = new CustomException();
DataException ex = new DataException();

//将CustomException复制为DataException
// 在使用此方法时,属性名一致的将会被复制,该方法是一个线程安全类的
// 第一个参数为源对象,第二个参数为目标对象
DataException copy = BeanUtil.copy(e, ex);

//将CustomException序列化为二进制数组
byte[] bytes = BeanUtil.objectToByte(e);

// 将转换后的二进制数据反序列化为对象
Object object = BeanUtil.byteToObject(bytes);

// 将转换后的二进制数据反序列化为指定的对象
CustomException exception = BeanUtil.byteToObject(bytes, CustomException.class);

二 集合操作工具

2.1 集合元素处理工具

该工具的主要目的是对集合进行处理,让用户在无须考虑NPE的情况下安全地操作集合。主要作用如下:

  • 将集合转换成java8中的stream流
  • 获取集合中的第一个元素
  • 将数据转换成集合
  • 安全地创建集合

该工具是线程安全类的

工具路径:

com.yishuifengxiao.common.tool.collections.DataUtil

使用示例:

// 安全地创建集合,该方法与Arrays.asList不同,
// 创建出来的是ArrayList,可以放心地对创建出来的list进行各种操作
//List<String> list = Arrays.asList("a", "b", "c", "d");
List<String> list = DataUtil.asList("a", "b", "c", "d");

//将集合转换成并行流
Stream<String> parallelStream = DataUtil.parallelStream(list);

//将集合转换成串行流
Stream<String> stream = DataUtil.stream(list);

// 获取集合的第一个元素
String first = DataUtil.first(list);

//将数组转换成集合
String[] strs = {"a", "b", "c", "d"};
List<String> asList = DataUtil.asList(strs);

2.2 空集合判断工具

该工具的主要目的在于快速地判断一个集合是否为空集合或者为NULL。其主要作用如下:

  • 判断集合是否为空
  • 判断分页对象是否为空
  • 判断集合是否仅有一个元素

工具路径:

com.yishuifengxiao.common.tool.collections.CollUtil

使用示例:

//判断改分页对象是否为空或者null
Page<FileRecord> page = Page.empty();
boolean empty = EmptyUtil.isEmpty(page);

//判断该集合是否为空或者null
List<String> list = new ArrayList<>();
boolean empty1 = EmptyUtil.isEmpty(list);

//判断该集合是否仅有一个元素
boolean onlyOneElement = EmptyUtil.onlyOneElement(list);

2.3 字典链式构建工具

该工具的主要目的是能通过链式方法快速地构建一个字典对象。

工具路径:

com.yishuifengxiao.common.tool.collections.MapUtil

使用示例:

Map<String, Object> map = MapUtil.instance().put("k1", "v1").
        put("k2", "v2").put("k3", "v3").build();

三 日期时间工具

3.1 Date时间工具

该工具主要是基于java.util.Date实现的日期时间获取工具,其主要作用如下:

  • 获取今天的开始时间点(00:00:00)
  • 获取昨天的开始时间点(00:00:00)和结束时间点(23:59:59)
  • 获取前天的开始时间点(00:00:00)
  • 获取7天前的那个时间的开始时间点(00:00:00)
  • 获取14天前的那个时间的开始时间点(00:00:00)
  • 获取本周一的那个时间的开始时间点(00:00:00)
  • 获取上周一的那个时间的开始时间点(00:00:00)
  • 获取过去指定时间的那个时间的开始时间点(00:00:00)
  • 获取本月1号的那个时间的开始时间点(00:00:00)
  • 获取过去指定月份的那个月份的1号的开始时间点(00:00:00)
  • 获取过去指定年份的那个时间的1月1号的那个时间的开始时间点(00:00:00)

该工具是线程安全类的

工具路径:

com.yishuifengxiao.common.tool.datetime.DateOffsetUtil

使用示例:

//今天的开始时间(今天的00:00:00)
Date todayStart = DateOffsetUtil.todayStart();
//获取昨天的开始时间(昨天的00:00:00)
Date yesterdayStart = DateOffsetUtil.yesterdayStart();
//获取昨天的结束时间(昨天的23:59:59)
Date yesterdayEnd = DateOffsetUtil.yesterdayEnd();
//获取前天的开始时间(前天的00:00:00)
Date last2DayStart = DateOffsetUtil.last2DayStart();
//获取7天前那一天0时0分0秒这个时间(七天前的00:00:00)
Date last7DayStart = DateOffsetUtil.last7DayStart();
//获取本周一的开始时间(本周一的00:00:00)
Date mondayStart = DateOffsetUtil.mondayStart();
//获取本月的开始时间(本月1号的00:00:00)
Date monthStart = DateOffsetUtil.monthStart();
//获取1个月前的那个月的开始时间(1个月前的那个月的00:00:00)
Date monthStart1 = DateOffsetUtil.monthStart(1);

3.2 LocalDateTime时间工具

该工具主要是基于java.time.LocalDateTime实现的日期时间获取工具,其主要作用如下:

  • 获取今天的开始时间点(00:00:00)
  • 获取昨天的开始时间点(00:00:00)和结束时间点(23:59:59)
  • 获取前天的开始时间点(00:00:00)
  • 获取7天前的那个时间的开始时间点(00:00:00)
  • 获取14天前的那个时间的开始时间点(00:00:00)
  • 获取本周一的那个时间的开始时间点(00:00:00)
  • 获取上周一的那个时间的开始时间点(00:00:00)
  • 获取过去指定时间的那个时间的开始时间点(00:00:00)
  • 获取本月1号的那个时间的开始时间点(00:00:00)
  • 获取过去指定月份的那个月份的1号的开始时间点(00:00:00)
  • 获取过去指定年份的那个时间的1月1号的那个时间的开始时间点(00:00:00)

该工具是线程安全类的

工具路径:

com.yishuifengxiao.common.tool.datetime.LocalDateTimeUtil

使用示例:

//今天的开始时间(今天的00:00:00)
LocalDateTime todayStart = TemporalUtil.todayStart();
//获取昨天的开始时间(昨天的00:00:00)
LocalDateTime yesterdayStart = TemporalUtil.yesterdayStart();
//获取昨天的结束时间(昨天的23:59:59)
LocalDateTime yesterdayEnd = TemporalUtil.yesterdayEnd();
//获取前天的开始时间(前天的00:00:00)
LocalDateTime last2DayStart = TemporalUtil.last2DayStart();
//获取7天前那一天0时0分0秒这个时间(七天前的00:00:00)
LocalDateTime last7DayStart = TemporalUtil.last7DayStart();
//获取本周一的开始时间(本周一的00:00:00)
LocalDateTime mondayStart = TemporalUtil.mondayStart();
//获取本月的开始时间(本月1号的00:00:00)
LocalDateTime monthStart = TemporalUtil.monthStart();
//获取1个月前的那个月的开始时间(1个月前的那个月的00:00:00)
LocalDateTime monthStart1 = TemporalUtil.monthStart(1);

3.3 时间解析与格式化工具

该工具的主要目的是实现字符串与时间的转换以及不同格式时间的转换,主要功能如下

  • 获取中国时区
  • LocalDateTime与Date相互转换
  • 将时间转换成毫秒数
  • 将字符串解析为时间
  • 将时间格式化为字符串

该工具是线程安全类的

工具路径:

com.yishuifengxiao.common.tool.datetime.DateTimeUtil

使用示例:

// 获取中国时区
ZoneId china = DateTimeUtil.zoneIdOfChina();

// 将 Date 转换成 LocalDateTime
LocalDateTime localDateTime = DateTimeUtil.date2LocalDateTime(new Date());

// 将 LocalDateTime 转换成 Date
Date date = DateTimeUtil.localDateTime2Date(LocalDateTime.now());

//将时间转换成毫秒数
Long time = DateTimeUtil.getTime(date);
Long time1 = DateTimeUtil.getTime(localDateTime);


//将时间格式化为字符串
String format = DateTimeUtil.format(date);
String format1 = DateTimeUtil.format(localDateTime);

//按照指定格式将时间格式化为字符串
String format3 = DateTimeUtil.format(date, "yyyy-MM-dd HH:mm:ss");
String format4 = DateTimeUtil.format(localDateTime, "yyyy-MM-dd HH:mm:ss");

//将字符串转换成时间
LocalDateTime parse = DateTimeUtil.parse("2021-10-10 12:12:12");
//按照指定格式将字符串转换成时间
LocalDateTime parse1 = DateTimeUtil.parse("2021-10-10 12:12:12", "yyyy-MM-dd HH:mm:ss");

四 加解密工具

4.1 AES加解密工具

该工具是基于AES算法实现的加解密工具。其主要作用如下:

  • 实现AES算法加密
  • 实现AES算法解密

工具路径:

com.yishuifengxiao.common.tool.encoder.AES

使用示例:

//使用指定的秘钥对数据进行加密
String encrypt = AES.encrypt("秘钥", "待加密的数据");
// 使用指定的秘钥对加密后的数据进行解密,若待解密的数据为空或解密出现问题时返回为null
AES.decrypt("秘钥", encrypt);

4.2 DES加解密工具

该工具是基于DES算法实现的加解密工具。其主要作用如下:

  • 实现DES算法加密
  • 实现DES算法解密

工具路径:

com.yishuifengxiao.common.tool.encoder.DES

使用示例:

//使用指定的秘钥对数据进行加密
String encrypt = DES.encrypt("秘钥", "待加密的数据");
// 使用指定的秘钥对加密后的数据进行解密,若待解密的数据为空或解密出现问题时返回为null
DES.decrypt("秘钥", encrypt);

4.3 MD5加密工具

该工具主要是使用MD5算法对字符串进行加密操作。

工具路径:

com.yishuifengxiao.common.tool.encoder.Md5

使用示例:

//对字符串进行MD5加密,输入32位小写的MD5值
String md5 = Md5.md5("待加密码的数据");
//对字符串进行MD5加密,输入16位小写的MD5值
String md5Short = Md5.md5Short("待加密码的数据");

五 通用实体类

5.1 通用响应对象

该对象的主要目的是在进行后端开发时统一响应数据的格式,使得全体应用中接口的返回数据的格式能够保持一致性,方便前端开发处理的同时让全局风格保持一定的规范性。

通用响应对象的属性及定义如下:

修饰符 数据类型 属性及含义
protected int code请求的响应码
protected T data响应数据,在基本基本信息无法满足时会出现此信息,一般情况下无此信息
protected Date date响应时间
protected String id请求ID,用于请求追踪 .无论调用接口成功与否,都会返回请求 ID,该序列号全局唯一且随机
protected String msg响应提示信息,一般与响应码的状态对应,对响应结果进行简单地描述

5.1.1 赋值说明

  • 响应码code : 在默认情况下借鉴了HttpStatus的响应值和含义,其定义可参见 https://developer.mozilla.org/en-US/docs/Web/HTTP/Statu
  • 响应数据data : 在定义中该属性是一个泛型,用户可以传输各种必需的响应数据。如果用户不需要传输数据仅仅通过响应码表达请求操作结果时,该属性可以置空或使用默认值
  • 响应信息 msg : 该属性在一般情况用于辅助描述响应码希望表达的含义

5.1.2 常用创建方法

修饰符及响应 `方法使用及说明
static Response<Object> badParam()生成一个默认的表示参数有误的响应对象(响应码400)
static Response<Object> badParam(String msg)根据响应提示信息生成一个表示参数有误的响应对象(响应码400)
static <T> Response<T> badParam(String msg, T data)根据响应提示信息和响应数据生成一个表示参数有误的响应对象(响应码400)
static Response<Object> error()生成一个默认表示请求业务未完成的响应对象(500响应码)
static Response<Object> error(String msg)根据响应提示信息生成一个表示服务器内部异常500时的返回信息
static <T> Response<T> error(String msg, T data)根据响应提示信息和响应数据生成表示服务器内部异常500时的返回信息
static <T> Response<T> error(T data)根据响应数据生成表示服务器内部异常500时的返回信息
static <T> Response<T> errorData(T data)生成一个默认表示请求业务未完成的响应对象(500响应码)
static Response<Object> notAllow()生成一个默认的表示资源不可用的响应对象(403响应码)
static Response<Object> notAllow(String msg)根据响应提示信息生成表示资源不可用的响应对象(403响应码)
static Response<Object> notFoundt()生成一个默认的表示资源不存在的响应对象(404响应码)
static <T> Response<T> of(int code, String msg, T data)构建一个通用的响应对象
static Response<Object> suc()生成一个默认的一个表示成功的响应对象
static Response<Object> suc(String msg)根据响应提示信息生成一个表示成功的响应对象
static <T> Response<T> suc(String msg, T data)根据响应提示信息和响应数据生成一个表示成功的响应对象
static <T> Response<T> suc(T data)根据响应数据生成一个表示成功的响应对象
static <T> Response<T> sucData(T data)根据响应提示信息生成一个表示成功的响应对象
static Response<Object> unAuth()生成一个默认的表示资源未授权的响应对象(401响应码)
static Response<Object> unAuth(String msg)根据响应提示信息生成一个表示资源未授权的响应对象(401响应码)
static <T> Response<T> unAuth(String msg, T data)根据响应提示信息和响应数据生成一个表示资源未授权的响应对象(401响应码)

5.1.3 示例代码

工具路径:

com.yishuifengxiao.common.tool.entity.Response

使用示例:

//默认的请求成功响应,响应码为200
Response<Object> suc = Response.suc();
//默认的请求成功响应,响应码为200,其中:响应描述信息修改为 响应描述信息:成功
Response<Object> suc1 = Response.suc("响应描述信息:成功");
//默认的请求成功响应,响应码为200,其中:响应具体信息修改成功 响应具体信息:成功
Response<String> sucData = Response.sucData("响应具体信息:成功");
//构建一个请求成功响应,响应码为200,其中: 响应描述信息修改为 响应描述信息:成功 ,响应具体信息修改成功 响应具体信息:成功
Response<String> suc2 = Response.suc("响应描述信息:成功", "响应具体信息:成功");


//默认的请求失败响应,响应码为500
Response<Object> error = Response.error();
//默认的请求失败响应,响应码为500,其中:响应描述信息修改为 响应描述信息:失败
Response<Object> error1 = Response.error("响应描述信息:失败");
//默认的请求失败响应,响应码为500,其中:响应具体信息修改成功 响应具体信息:失败
Response<String> errorData = Response.errorData("响应具体信息:失败");
//默认的请求失败响应,响应码为500,其中: 响应描述信息修改为 响应描述信息:失败 ,响应具体信息修改成功 响应具体信息:失败
Response<String> error2 = Response.error("响应描述信息:失败", "响应具体信息:失败");

//通用的构建方法
Response<Object> response = Response.of(响应码, "响应描述信息", 响应具体信息);

5.2 通用分页对象

本对象主要是解决后端开发时在使用不同的分页插件时造成分页对象不同从而导致数据结构不一致的问题,本工具主要是适配了jpa里的org.springframework.data.domain.Page和pagehelper里的com.github.pagehelper.PageInfo这两个分页对象。

该工具主要作用如下:

  • 适配不同类型的分页对象
  • 转换分页对象里的数据

该分页对象中的当前页页码从1开始,默认的分页大小为20

工具路径:

//创建一个默认的空的分页对象
Page<Object> empty = Page.ofEmpty();

// 转换 jpa 里的分页对象
Page<Object> page = JpaPage.of(org.springframework.data.domain.Page.empty());

//转换 pagehelper 的分页对象
Page<Object> page1 = TkPage.of(PageInfo.of(new ArrayList<>()));


// 转换分页对象里的数据
Page<Object> convert = page.convert(原始数据 -> {
    
    return 转换后的数据
});

5.3 自定义异常

该工具的主要目的是统一项目中使用的各种异常,其定义如下:

image-20211011144459610

六 IO流和文件操作工具

6.1 IO流关闭工具

该工具的主要目的是在安全地关闭各种Closeable实例。

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.io.CloseUtil

使用示例

InputStream inputStream = new FileInputStream("input");

OutputStream outputStream = new FileOutputStream("out");

CloseUtil.close(inputStream, outputStream);

6.2 文件处理工具

该工具的主要目的是进行文件和base64字符串之间进行互相转换和获取文件的MD5值。

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.io.IoUtil

示例代码:

File file = new File("待处理的文件");

// 将文件转换成base64格式的字符串
String base64Str = FileUtil.file2Base64(file);

//将base64格式的字符串转换成文件
File toFile = FileUtil.base64ToFile(base64Str);

//获取文件的MD5值(32位小写)
String md5 = FileUtil.getMd5(file);

6.3 base64与图片转换工具

该工具的主要目的是进行图片和base64字符串之间进行互相转换

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.io.IoUtil

代码示例:

//base64字符串转换成图片
ImageUtil.base64ToImage("图片转成base64格式后的字符串", "目标图片的地址");

//BufferedImage格式的图片转换为base64字符串,结果不包含base64信息头
String image2Base64 = ImageUtil.image2Base64(
    new BufferedImage(255, 255, BufferedImage.TYPE_INT_RGB));

//BufferedImage格式的图片转换为base64字符串,结果包含png格式的base64信息头
String _image2Base64 = ImageUtil.image2Base64Png(
    new BufferedImage(255, 255, BufferedImage.TYPE_INT_RGB));

//base64字符串转换为ufferedImage格式的图片
ImageUtil.base64ToImage(image2Base64, "待保存的图片的地址");

七 缓存工具

7.1 全局存储工具

该工具的主要目的是构建一个基于内存的全局字典缓存工具。在使用该工具时注意防止内存泄露。

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.context.LocalCache

示例代码:

        //存放一个数据
        LocalStorage.put(new FileRecord());

        //使用指定的索引存放一个数据
        LocalStorage.put("k1", new FileRecord());

        //根据索引获取一个数据
        Object object = LocalStorage.get("k1");

        //根据数据类型获取一个数据
        FileRecord record = LocalStorage.get(FileRecord.class);

        //根据索引从缓存中删除一个数据
        LocalStorage.remove("k1");

        //根据索引获取一个数据,然后从缓存中删除该数据
        Object obj = LocalStorage.pop("k1");

        //清除缓存中所有的数据
        LocalStorage.clear();

7.2 上下文存储工具

该工具与全局存储工具基本类似,但不同的是,该工具是基于当前线程实现的,在当前线程中存储的数据不能再其他线程中访问。在使用该工具时注意防止内存泄露。

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.context.SessionStorage

示例代码:

//存放一个数据
SessionStorage.put(new FileRecord());

//使用指定的索引存放一个数据
SessionStorage.put("k1", new FileRecord());

//根据索引获取一个数据
Object object = SessionStorage.get("k1");

//根据数据类型获取一个数据
FileRecord record = SessionStorage.get(FileRecord.class);

//根据索引从缓存中删除一个数据
SessionStorage.remove("k1");

//根据索引获取一个数据,然后从缓存中删除该数据
Object obj = SessionStorage.pop("k1");

//清除缓存中所有的数据
SessionStorage.clear();

八 常见数据封装工具

该工具的主要目的是对常见的基础数据类型的数据进行处理,实现数值大小比较和字符串处理等功能。

该工具包的功能如下:

工具名称 功能说明
BetweenUtil 比较工具工具类
HumpUtil 下划线与驼峰互转工具
NumberUtil 数字转换与操作比较工具
ObjUtil 集合对象判断工具
RegexUtil 正则工具
StringUtil 字符串工具

8.1 下划线与驼峰互转工具

该工具主要目的是实现下划线与驼峰互相转换。

工具路径:

com.yishuifengxiao.common.tool.lang.HumpUtil

示例代码:

//转换为驼峰,例如:将call_back转换成 CallBack
String camelCaseName = HumpUtil.camelCaseName("call_back");
System.out.println(camelCaseName);
//转换为下划线,例如:将CallBack转换成 call_back
String underscoreName = HumpUtil.underscoreName("camelCaseName");
System.out.println(underscoreName);

8.2 数字转换与操作比较工具

该工具的主要目的是实现字符串与数字之间互相转换以及进行数据大小比较

工具路径

com.yishuifengxiao.common.tool.lang.NumberUtil

示例代码:

//将字符串转换成数字
Integer integer = NumberUtil.parseInt("11");
//判断数字是否小于0
boolean lessZero = NumberUtil.lessZero(integer);
//判断数字是否小于或等于0
boolean lessEqualZero = NumberUtil.lessEqualZero(integer);
//判断数字是否大于0
boolean greaterZero = NumberUtil.greaterZero(integer);
//判断数字是否大于或等于0
boolean greaterEqualZero = NumberUtil.greaterEqualZero(integer);
//判断两个数字是否相等
boolean equals = NumberUtil.equals(Integer.parseInt("2322"), Integer.parseInt("5865"));
//将数字转成Boolean值,如果数字为null,返回为false,数字小于或等于0返回为false,数字大于0返回为true
Boolean num2Bool = NumberUtil.num2Bool(1);
//将boolean值转换成数字,value为true时返回1,否则为0
int bool2Int = NumberUtil.bool2Int(true);

九 自定义工具

9.1 回调工具类

该工具类的主要目的是使用内置线程池执行一个回调操作,节省创建线程和线程管理所需的资源。

工具路径:

com.yishuifengxiao.common.tool.utils.ExecuteUtil

示例代码:

ExecuteUtil.execute(() -> {
    System.out.println("-------- 回调");
});

9.2 身份证操作工具

该工具的主要目的是对字符串格式的身份证号进行判断。主要功能如下:

  • 判断该字符串是否为一个合法的身份证号
  • 从字符串格式的身份证号里提取出出生日期

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.utils.CertNoUtil

示例代码:

//判断该身份证号是否为一个正确的身份证号
boolean valid = CertNoUtil.isValid("421111198705164213");
System.out.println(valid);
//从身份证号中提取出出生日期
LocalDate birthday = CertNoUtil.extractBirthday("421111198705164213");
System.out.println(birthday);

9.3 经纬度距离计算工具

该工具的主要目的是计算两个经纬度之间距离。

该工具是一个线程安全类的工具

工具路径:

com.yishuifengxiao.common.tool.utils.GpsUtil

示例代码:

//通过经纬度计算出来的结果单位为米
long distance = GpsUtil.distance(111, 30, 156, 35);
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

本工具包主要集成了目前在项目开发过程中个人经常会使用到的一些工具类,对工具类进行了一下简单的封装。工具包目前集成了通用响应实体、对象拷贝、集合转换、加密工具、格式化工具、随机中文、JSR校验、常用自定义异常、swagger-ui和驼峰转换等工具 展开 收起
Java
Apache-2.0
取消

发行版 (8)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zhiyubujian/tool.git
git@gitee.com:zhiyubujian/tool.git
zhiyubujian
tool
tool
master

搜索帮助