Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
609ffc62
Commit
609ffc62
authored
Mar 20, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式化
parents
Pipeline
#115
failed with stages
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1234 additions
and
0 deletions
+1234
-0
.gitignore
.gitignore
+9
-0
vcs.xml
.idea/vcs.xml
+7
-0
pom.xml
pom.xml
+124
-0
readme.md
readme.md
+2
-0
ByteConvertHelper.java
...ain/java/com/yanzuoguang/util/base/ByteConvertHelper.java
+454
-0
MemoryCache.java
src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
+232
-0
MemoryCacheCenter.java
...in/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
+33
-0
MemoryCacheItem.java
...main/java/com/yanzuoguang/util/cache/MemoryCacheItem.java
+57
-0
CodeException.java
...in/java/com/yanzuoguang/util/exception/CodeException.java
+137
-0
StatusException.java
.../java/com/yanzuoguang/util/exception/StatusException.java
+151
-0
readme.md
src/main/java/com/yanzuoguang/util/extend/readme.md
+2
-0
readme.md
src/main/java/com/yanzuoguang/util/readme.md
+0
-0
BaseVo.java
src/main/java/com/yanzuoguang/util/vo/BaseVo.java
+26
-0
No files found.
.gitignore
0 → 100644
View file @
609ffc62
.idea
*.iml
*.suo
.vs
Debug
bin
obj
target
\ No newline at end of file
.idea/vcs.xml
0 → 100644
View file @
609ffc62
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
""
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
pom.xml
0 → 100644
View file @
609ffc62
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.yanzuoguang
</groupId>
<artifactId>
yzg-util
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<spring.version>
4.3.7.RELEASE
</spring.version>
<fastjson.version>
1.2.47
</fastjson.version>
</properties>
<dependencies>
<!-- Spring依赖 -->
<!-- 1.Spring核心依赖 -->
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-beans
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<!-- 2.Spring dao依赖 -->
<!-- spring-jdbc包括了一些如jdbcTemplate的工具类 -->
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-jdbc
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-tx
</artifactId>
<version>
${spring.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
${fastjson.version}
</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<build>
<directory>
${project.basedir}/target/
</directory>
<finalName>
${project.artifactId}
</finalName>
<pluginManagement>
<plugins>
<!-- ===========只打源码包,应用于公共组件打包=========== -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<configuration>
<overwrite>
true
</overwrite>
</configuration>
</plugin>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
${maven.compiler.source}
</source>
<target>
${maven.compiler.target}
</target>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
<!-- ===========可运行Jar包=========== -->
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
1.5.10.RELEASE
</version>
<executions>
<execution>
<goals>
<goal>
repackage
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.xml
</include>
</includes>
</resource>
<resource>
<directory>
src/main/resources
</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.xml
</include>
</includes>
</testResource>
<testResource>
<directory>
src/main/resources
</directory>
</testResource>
</testResources>
</build>
</project>
\ No newline at end of file
readme.md
0 → 100644
View file @
609ffc62
工具类
\ No newline at end of file
src/main/java/com/yanzuoguang/util/base/ByteConvertHelper.java
0 → 100644
View file @
609ffc62
package
com
.
yanzuoguang
.
util
.
base
;
/**
* 通信格式转换
* <p>
* Java和一些windows编程语言如c、c++、delphi所写的网络程序进行通讯时,需要进行相应的转换 高、低字节之间的转换
* windows的字节序为低字节开头 linux,unix的字节序为高字节开头 java则无论平台变化,都是高字节开头
*/
public
class
ByteConvertHelper
{
// --------------------------------------- toLH -------------------------------------
/**
* 将 long 值转成低字节在前,高字节在后的byte数组
*
* @param n 需要转换的值
* @param max 字节最大长度
* @return
*/
public
static
byte
[]
toLH
(
long
n
,
int
max
)
{
byte
[]
b
=
new
byte
[
max
];
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
int
offset
=
i
*
8
;
b
[
i
]
=
(
byte
)
(
n
>>
offset
&
0xff
);
}
return
b
;
}
/**
* 将 long 值转成低字节在前,高字节在后的byte数组
*
* @param n 需要转换的值
* @return
*/
public
static
byte
[]
toLH
(
long
n
)
{
return
toLH
(
n
,
8
);
}
/**
* 将int转为低字节在前,高字节在后的byte数组
*
* @param n int
* @return byte[]
*/
public
static
byte
[]
toLH
(
int
n
)
{
return
toLH
(
n
,
4
);
}
/**
* 将short转为低字节在前,高字节在后的byte数组
*
* @param n short
* @return byte[]
*/
public
static
byte
[]
toLH
(
short
n
)
{
return
toLH
(
n
,
2
);
}
/**
* 将float转为低字节在前,高字节在后的byte数组
*/
public
static
byte
[]
toLH
(
float
f
)
{
return
toLH
(
Float
.
floatToRawIntBits
(
f
));
}
// --------------------------------------- toHL -------------------------------------
/**
* 将 long 值转成高字节在前,低字节在后的byte数组
*
* @param n 需要转换的值
* @param max 字节最大长度
* @return
*/
public
static
byte
[]
toHL
(
long
n
,
int
max
)
{
byte
[]
b
=
new
byte
[
max
];
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
int
offset
=
(
max
-
1
-
i
)
*
8
;
b
[
i
]
=
(
byte
)
(
n
>>
offset
&
0xff
);
}
return
b
;
}
/**
* 将 long 值转成高字节在前,低字节在后的byte数组
*
* @param n 需要转换的值
* @return
*/
public
static
byte
[]
toHL
(
long
n
)
{
return
toHL
(
n
,
8
);
}
/**
* 将int转为高字节在前,低字节在后的byte数组
*
* @param n int
* @return byte[]
*/
public
static
byte
[]
toHL
(
int
n
)
{
return
toHL
(
n
,
4
);
}
/**
* 将short转为高字节在前,低字节在后的byte数组
*
* @param n short
* @return byte[]
*/
public
static
byte
[]
toHL
(
short
n
)
{
return
toHL
(
n
,
2
);
}
/**
* 将float转为高字节在前,低字节在后的byte数组
*/
public
static
byte
[]
toHL
(
float
f
)
{
return
toHL
(
Float
.
floatToRawIntBits
(
f
));
}
// --------------------------------------- byLH -------------------------------------
/**
* 将低字节转换为长整形
*
* @param bytes 字节
* @param off 开始位置
* @param max 最大位置
* @return
*/
public
static
long
toLongByLH
(
byte
[]
bytes
,
int
off
,
int
max
)
{
long
ret
=
0
;
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
int
b
=
bytes
[
off
+
i
]
&
0xFF
;
int
offset
=
i
*
8
;
ret
|=
(
b
<<
offset
);
}
return
ret
;
}
/**
* 将低字节数组转换为long
*
* @param b byte[]
* @return long
*/
public
static
long
toLongByLH
(
byte
[]
b
)
{
return
toLongByLH
(
b
,
0
);
}
/**
* 将低字节数组转换为long
*
* @param b
* @param off
* @return
*/
public
static
long
toLongByLH
(
byte
[]
b
,
int
off
)
{
return
toLongByLH
(
b
,
off
,
8
);
}
/**
* 将低字节数组转换为int
*
* @param b byte[]
* @return int
*/
public
static
int
toIntByLH
(
byte
[]
b
)
{
return
toIntByLH
(
b
,
0
);
}
/**
* 将低字节数组转换为int
*
* @param b
* @param off
* @return
*/
public
static
int
toIntByLH
(
byte
[]
b
,
int
off
)
{
return
(
int
)
toLongByLH
(
b
,
off
,
4
);
}
/**
* 低字节数组到short的转换
*
* @param b
* @return
*/
public
static
short
toShortByLH
(
byte
[]
b
)
{
return
toShortByLH
(
b
,
0
);
}
/**
* 低字节数组到short的转换
*
* @param b
* @param off
* @return
*/
public
static
short
toShortByLH
(
byte
[]
b
,
int
off
)
{
return
(
short
)
toLongByLH
(
b
,
off
,
2
);
}
/**
* 低字节数组转换为float
*
* @param b byte[]
* @return float
*/
public
static
float
toFloatByLH
(
byte
[]
b
)
{
int
i
=
toIntByLH
(
b
);
return
Float
.
intBitsToFloat
(
i
);
}
// --------------------------------------- byHL -------------------------------------
/**
* 将高字节转换为长整型
*
* @param bytes 字节
* @param off 开始位置
* @param max 最大位置
* @return
*/
public
static
long
toLongByHL
(
byte
[]
bytes
,
int
off
,
int
max
)
{
long
ret
=
0
;
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
int
b
=
bytes
[
off
+
i
]
&
0xFF
;
int
offset
=
(
max
-
1
-
i
)
*
8
;
ret
|=
(
b
<<
offset
);
}
return
ret
;
}
/**
* 将高字节数组转换为long
*
* @param b
* @return
*/
public
static
long
toLongByHL
(
byte
[]
b
)
{
return
toLongByHL
(
b
,
0
);
}
/**
* 将高字节数组转换为long
*
* @param b byte[]
* @param off long
* @return long
*/
public
static
long
toLongByHL
(
byte
[]
b
,
int
off
)
{
return
toLongByHL
(
b
,
off
,
8
);
}
/**
* 将高字节数组转换为int
*
* @param b
* @return
*/
public
static
int
toIntByHL
(
byte
[]
b
)
{
return
toIntByHL
(
b
,
0
);
}
/**
* 将高字节数组转换为int
*
* @param b byte[]
* @param off int
* @return int
*/
public
static
int
toIntByHL
(
byte
[]
b
,
int
off
)
{
return
(
int
)
toLongByHL
(
b
,
off
,
4
);
}
/**
* 高字节数组到short的转换
*
* @param b
* @return
*/
public
static
short
toShortByHL
(
byte
[]
b
)
{
return
toShortByHL
(
b
,
0
);
}
/**
* 高字节数组到short的转换
*
* @param b
* @param off
* @return
*/
public
static
short
toShortByHL
(
byte
[]
b
,
int
off
)
{
return
(
short
)
toLongByHL
(
b
,
off
,
2
);
}
/**
* 高字节数组转换为float
*
* @param b byte[]
* @return float
*/
public
static
float
toFloatByHL
(
byte
[]
b
)
{
int
i
=
toIntByHL
(
b
);
return
Float
.
intBitsToFloat
(
i
);
}
/**
* 获取短整形的字节,高字节在前,低字节在后的byte数组
*
* @param value
* @return
*/
public
static
byte
[]
getBytes
(
short
value
)
{
return
toHL
(
value
);
}
/**
* 获取短整形的字节,高字节在前,低字节在后的byte数组
*
* @param value
* @return
*/
public
static
byte
[]
getBytes
(
int
value
)
{
return
toHL
(
value
);
}
/**
* 获取短整形的字节,高字节在前,低字节在后的byte数组
*
* @param value
* @return
*/
public
static
byte
[]
getBytes
(
long
value
)
{
return
toHL
(
value
);
}
/**
* 将byte数组中的元素倒序排列
*/
public
static
byte
[]
bytesReverseOrder
(
byte
[]
b
)
{
int
length
=
b
.
length
;
byte
[]
result
=
new
byte
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
result
[
length
-
i
-
1
]
=
b
[
i
];
}
return
result
;
}
/**
* 将本机的 short 转换成网络上传输支持的 short ,用于多语言通讯时处理, 将 short 类型的值转换为字节序颠倒过来对应的 short 值
*
* @param from
* @return
*/
public
static
short
reverse
(
short
from
)
{
return
toShortByHL
(
toLH
(
from
));
}
/**
* 将本机的 int 转换成网络上传输支持的 int ,用于多语言通讯时处理, 将 int 类型的值转换为字节序颠倒过来对应的 int 值
*
* @param from
* @return
*/
public
static
int
reverse
(
int
from
)
{
return
toIntByHL
(
toLH
(
from
));
}
/**
* 将本机的 long 转换成网络上传输支持的 long ,用于多语言通讯时处理, 将 long 类型的值转换为字节序颠倒过来对应的 long 值
*
* @param from
* @return
*/
public
static
long
reverse
(
long
from
)
{
return
toLongByHL
(
toLH
(
from
));
}
/**
* 将本机的 float 转换成网络上传输支持的 float ,用于多语言通讯时处理, 将 float 类型的值转换为字节序颠倒过来对应的 float 值
*
* @param f float
* @return float
*/
public
static
float
reverse
(
float
f
)
{
float
result
=
toFloatByHL
(
toLH
(
f
));
return
result
;
}
/**
* 将String转为byte数组
*/
public
static
byte
[]
stringToBytes
(
String
s
,
int
length
)
{
while
(
s
.
getBytes
().
length
<
length
)
{
s
+=
" "
;
}
return
s
.
getBytes
();
}
/**
* 将字节数组转换为String
*
* @param b byte[] 需要转换的字节,如 [0x00,0x01]
* @return String 返回转换成功的字符串 如: 0001
*/
public
static
String
bytesToString
(
byte
[]
b
)
{
StringBuffer
result
=
new
StringBuffer
();
int
length
=
b
.
length
;
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
result
.
append
((
char
)
(
b
[
i
]
&
0xff
));
}
return
result
.
toString
();
}
/**
* 将字符串转换为byte数组
*
* @param s String
* @return byte[]
*/
public
static
byte
[]
stringToBytes
(
String
s
)
{
return
s
.
getBytes
();
}
/**
* 将字节转换为字节字符串。如 [0x00,0x01]转成成 00 01
*
* @param bb
* @return
*/
public
static
String
logBytes
(
byte
[]
bb
)
{
int
length
=
bb
.
length
;
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
bb
+
" "
);
}
return
sb
.
toString
();
}
// public static void main(String[] args) {
// long old = 99L;
// long from = reverse(old);
// long to = reverse(from);
// System.out.println(String.format("old:%d %d %d", old, from, to));
// }
}
src/main/java/com/yanzuoguang/util/cache/MemoryCache.java
0 → 100644
View file @
609ffc62
//package com.yanzuoguang.util.cache;
//
//import com.tourbida.sys.core.util.StringHelper;
//
//import java.util.Date;
//import java.util.Hashtable;
//
///**
// * 内存缓存
// *
// * @param <T>
// */
//public class MemoryCache<T> {
//
// /**
// * 缓存的对象
// */
// private Hashtable<String, MemoryCacheItem<T>> cache = new Hashtable<String, MemoryCacheItem<T>>();
//
// /**
// * 清除时间
// */
// private int clearSecond;
//
// /**
// * 是否自动清除缓存
// */
// private boolean isAutoClear;
//
// /**
// * 读取时是否激活
// */
// private boolean isGetActive;
//
// /**
// * 构造函数,不会自动清除对象
// */
// public MemoryCache() {
// this(false, 0);
// }
//
// /**
// * 构造函数
// *
// * @param clearSecond 清除缓存的时间
// */
// public MemoryCache(int clearSecond) {
// this(true, clearSecond);
// }
//
// /**
// * 构造函数
// *
// * @param isAutoClear 是否自动清除
// * @param clearSecond 清除缓存的时间
// */
// public MemoryCache(boolean isAutoClear, int clearSecond) {
// this.isAutoClear = isAutoClear;
// this.clearSecond = clearSecond;
// this.isGetActive = false;
// if (isAutoClear) {
// MemoryCacheCenter.CLEAR_LIST.add(this);
// }
// }
//
// public boolean isGetActive() {
// return isGetActive;
// }
//
// public void setGetActive(boolean getActive) {
// isGetActive = getActive;
// }
//
// public int getClearSecond() {
// return clearSecond;
// }
//
// public void setClearSecond(int clearSecond) {
// this.clearSecond = clearSecond;
// }
//
// /**
// * 写入数据
// *
// * @param key 关键字
// * @param data 数据
// */
// public synchronized T put(String key, T data) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return data;
// }
// MemoryCacheItem<T> item = cache.getOrDefault(key, new MemoryCacheItem<T>());
// item.setData(data);
// if (StringHelper.IsEmpty(item.getName())) {
// item.setName(key);
// cache.put(key, item);
// }
// return item.getData();
// }
//
// /**
// * 读取数据
// *
// * @param key 关键字
// */
// public synchronized T get(String key) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return null;
// }
// MemoryCacheItem<T> item = cache.get(key);
// if (item == null) {
// return null;
// }
// this.getActive(item);
// return item.getData();
// }
//
// /**
// * 读取数据
// *
// * @param key 关键字
// * @param defData 默认数据
// * @return
// */
// public synchronized T get(String key, T defData) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return defData;
// }
// MemoryCacheItem<T> item = cache.getOrDefault(key, new MemoryCacheItem<T>());
// if (StringHelper.IsEmpty(item.getName())) {
// item.setName(key);
// item.setData(defData);
// cache.put(key, item);
// } else {
// if (defData instanceof MemoryCache) {
// ((MemoryCache) defData).close();
// }
// }
// this.getActive(item);
// return item.getData();
// }
//
// /**
// * 在获取时重新激活数据
// */
// private void getActive(MemoryCacheItem<T> item) {
// if (isGetActive) {
// item.active();
// }
// }
//
// /**
// * 删除一个数据
// *
// * @param key 关键字
// */
// public synchronized T remove(String key) {
// MemoryCacheItem<T> item = cache.remove(key);
// if (item == null) {
// return null;
// }
// T data = item.getData();
// if (data instanceof MemoryCache) {
// ((MemoryCache) data).close();
// }
// return data;
// }
//
// /**
// * 清除所有的缓存
// */
// public synchronized void clear() {
// Object[] keys = cache.keySet().toArray();
// for (Object keyObject : keys) {
// // 关键字
// String key = keyObject.toString();
// this.remove(key);
// }
// }
//
// /**
// * 清除超时的数据
// */
// public synchronized void clearTimeout() {
// if (this.clearSecond < 0) {
// return;
// }
// Object[] keys = cache.keySet().toArray();
// Date now = new Date();
// for (Object keyObject : keys) {
// // 关键字
// String key = keyObject.toString();
// // 获取到数据
// MemoryCacheItem<T> itemValue = this.cache.get(key);
// if (itemValue == null) {
// continue;
// }
// // 判断是否过期
// if (now.getTime() - itemValue.getDate().getTime() > this.clearSecond * 1000) {
// this.remove(key);
// }
// }
// }
//
// /**
// * 将缓存对象从缓存对象中清除
// */
// public synchronized void close() {
// this.clear();
// MemoryCacheCenter.CLEAR_LIST.remove(this);
// }
//
// /**
// * 获取所有的关键字
// *
// * @return
// */
// public synchronized String[] getKeys() {
// String[] items = new String[this.cache.size()];
// return this.cache.keySet().toArray(items);
// }
//
// /**
// * 析构函数
// *
// * @throws Throwable
// */
// @Override
// protected void finalize() throws Throwable {
// this.close();
// }
//}
src/main/java/com/yanzuoguang/util/cache/MemoryCacheCenter.java
0 → 100644
View file @
609ffc62
//package com.yanzuoguang.util.cache;
//
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Vector;
//
//@Component
//public class MemoryCacheCenter {
//
// /**
// * 缓存的对象
// */
// public static List<MemoryCache> CLEAR_LIST = new Vector<MemoryCache>();
//
// /**
// * 间隔5秒执行
// */
// @Scheduled(cron = "0/5 * * * * ? ")
// public void clear(){
// // 死循环处理
// ThreadList<MemoryCache> threadList = new ThreadList<MemoryCache>(1) {
// @Override
// public void Execute(MemoryCache item) {
// item.clearTimeout();
// }
// };
// threadList.setPrint(false);
// threadList.add(CLEAR_LIST);
// threadList.waitSucccess(true);
// }
//}
src/main/java/com/yanzuoguang/util/cache/MemoryCacheItem.java
0 → 100644
View file @
609ffc62
package
com
.
yanzuoguang
.
util
.
cache
;
import
java.util.Date
;
/**
* 内存缓存值
* @param <T>
*/
public
class
MemoryCacheItem
<
T
>
{
/**
* 时间
*/
private
Date
date
=
new
Date
();
/**
* 名称
*/
private
String
name
;
/**
* 数据
*/
private
T
data
;
/**
* 激活数据
*/
public
void
active
()
{
date
=
new
Date
();
}
public
Date
getDate
()
{
return
date
;
}
public
void
setDate
(
Date
date
)
{
this
.
date
=
date
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
}
src/main/java/com/yanzuoguang/util/exception/CodeException.java
0 → 100644
View file @
609ffc62
package
com
.
yanzuoguang
.
util
.
exception
;
/**
* 途比达异常信息
* Created by yanzu on 2018/7/13.
*/
public
class
CodeException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
-
4625832188480820883L
;
/**
* 错误码
*/
private
String
code
=
"99"
;
/**
* 包含的数据
*/
private
Object
target
=
null
;
/**
* 获取错误码
*
* @return 返回的结果
*/
public
String
getCode
()
{
return
this
.
code
;
}
/**
* 来源数据
*
* @return
*/
public
Object
getTarget
()
{
return
target
;
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public
CodeException
(
String
code
,
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
code
=
code
;
}
public
CodeException
(
String
code
,
String
message
,
Object
target
)
{
super
(
message
);
this
.
code
=
code
;
this
.
target
=
target
;
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public
CodeException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Constructs a new runtime exception with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
public
CodeException
()
{
super
();
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public
CodeException
(
String
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public
CodeException
(
String
message
)
{
super
(
message
);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public
CodeException
(
Throwable
cause
)
{
super
(
cause
);
}
}
src/main/java/com/yanzuoguang/util/exception/StatusException.java
0 → 100644
View file @
609ffc62
package
com
.
yanzuoguang
.
util
.
exception
;
/**
* 状态异常错误
*/
public
class
StatusException
extends
RuntimeException
{
/**
* 错误状态码
*/
private
int
code
;
/**
* 错误结果
*/
private
Object
result
;
/**
* 状态异常错误
*/
public
StatusException
()
{
super
();
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public
StatusException
(
String
message
)
{
super
(
message
);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public
StatusException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Constructs a new runtime exception with the specified cause and a
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
* (which typically contains the class and detail message of
* <tt>cause</tt>). This constructor is useful for runtime exceptions
* that are little more than wrappers for other throwables.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public
StatusException
(
Throwable
cause
)
{
super
(
cause
);
}
/**
* Constructs a new runtime exception with the specified detail
* message, cause, suppression enabled or disabled, and writable
* stack trace enabled or disabled.
*
* @param message the detail message.
* @param cause the cause. (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
* @param enableSuppression whether or not suppression is enabled
* or disabled
* @param writableStackTrace whether or not the stack trace should
* be writable
* @since 1.7
*/
protected
StatusException
(
String
message
,
Throwable
cause
,
boolean
enableSuppression
,
boolean
writableStackTrace
)
{
super
(
message
,
cause
,
enableSuppression
,
writableStackTrace
);
}
/**
* 途必达自定义异常
*
* @param code 错误码
* @param format 格式化字符串
* @param paras 参数
*/
public
StatusException
(
int
code
,
String
format
,
Object
...
paras
)
{
super
(
String
.
format
(
format
,
paras
));
this
.
result
=
null
;
this
.
code
=
code
;
}
/**
* 途必达自定义异常
*
* @param result 结果
* @param code 错误码
* @param format 格式化字符串
* @param paras 参数
*/
public
StatusException
(
Object
result
,
int
code
,
String
format
,
Object
...
paras
)
{
super
(
String
.
format
(
format
,
paras
));
this
.
result
=
result
;
this
.
code
=
code
;
}
/**
* 获取状态
* @return
*/
public
int
getCode
()
{
return
code
;
}
/**
* 状态码
* @param code
*/
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
/**
* 结果
* @return
*/
public
Object
getResult
()
{
return
result
;
}
/**
* 结果
* @param result
*/
public
void
setResult
(
Object
result
)
{
this
.
result
=
result
;
}
}
src/main/java/com/yanzuoguang/util/extend/readme.md
0 → 100644
View file @
609ffc62
扩展时,需要实现的接口
\ No newline at end of file
src/main/java/com/yanzuoguang/util/readme.md
0 → 100644
View file @
609ffc62
src/main/java/com/yanzuoguang/util/vo/BaseVo.java
0 → 100644
View file @
609ffc62
//package com.yanzuoguang.util.vo;
//
//import com.tourbida.sys.core.util.JSONHelper;
//
//import java.io.Serializable;
//
///**
// * 基本实体
// *
// * @author: Kang
// * @time: 2018年04月27日 10:19
// */
//public class BaseVo implements Serializable {
//
// private static final long serialVersionUID = -2611225711795496063L;
//
// /**
// * over ride object toString
// *
// * @return
// */
// @Override
// public String toString() {
// return JSONHelper.SerializeObject(this);
// }
//}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment