所有工具类
比如异常通用处理,KV键值对处理,常量等都定义为通用类
zj.common.constant.Constants
package zj.common.constant;
/**
* 通用常量类
*
* @version 1.00 (2011.12.02)
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
public class Constants {
/** 全局分割符号0 **/
public static final String GLOBAL_SPLIT_0 = "5c7c66e58a944e4682bf73c9f2969079";
/** 全局分割符号1 **/
public static final String GLOBAL_SPLIT_1 = "f8aeef2a2ef0a2aa2d8f55acadb3e646";
/** 全局分割符号2 **/
public static final String GLOBAL_SPLIT_2 = "b534c1ed5cdeaf4ab0fbcb1ec1672c16";
/** 全局分割符号3 **/
public static final String GLOBAL_SPLIT_3 = "67c3085c00afdbcb58da67fefb797745";
}zj.common.enums.Enums
package zj.common.enums;
/**
* 通用枚举类
*
* @version 1.00 (2011.12.02)
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
public class Enums {
/**
* 是否标识
*/
public static enum _YN {
N("0", "否"), Y("1", "是");
private final String value;
public String getValue() {
return value;
}
private final String name;
public String getName() {
return name;
}
_YN(String value, String name) {
this.value = value;
this.name = name;
}
// 普通方法
public static String getName(String value) {
for (_YN entity : _YN.values()) {
if (entity.getValue().equals(value)) {
return entity.name;
}
}
return "未知";
}
}
/**
* 删除标识
*
* @see _YN
*/
@Deprecated
public static enum _Delete {
NOT_DELETE("0", "未删除"), DELETE("1", "已删除");
private final String value;
public String getValue() {
return value;
}
private final String name;
public String getName() {
return name;
}
_Delete(String value, String name) {
this.value = value;
this.name = name;
}
// 普通方法
public static String getName(String value) {
for (_Delete entity : _Delete.values()) {
if (entity.getValue().equals(value)) {
return entity.name;
}
}
return "未知";
}
}
/**
* 升序降序
*/
public static enum _Order {
DESC(" desc", "降序"), ASC(" asc", "升序");
private final String value;
public String getValue() {
return value;
}
private final String name;
public String getName() {
return name;
}
_Order(String value, String name) {
this.value = value;
this.name = name;
}
// 普通方法
public static String getName(String value) {
for (_Order entity : _Order.values()) {
if (entity.getValue().equals(value)) {
return entity.name;
}
}
return "未知";
}
}
}zj.common.exception.ServiceException
package zj.common.exception;
/**
* 自定义异常处理
*
* @version 1.00 (2014.09.15)
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
public class ServiceException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ServiceException() {
super();
}
public ServiceException(String message) {
super(message);
}
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
public ServiceException(Throwable cause) {
super(cause);
}
}zj.common.KV<K, V>
package zj.common;
/**
* K、V值
*
* @Description KV.java
* @author 张军
* @date 2017年10月10日 下午6:19:30
* @version V1.0
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
public class KV<K, V> {
// K值
private K k;
// V值
private V v;
/**
* @see with(K,V)
*/
@Deprecated
public KV() {
}
/**
* @see with(K,V)
*/
@Deprecated
public KV(K k, V v) {
this.k = k;
this.v = v;
}
public static <K, V> KV<K, V> with(K k, V v) {
return new KV<K, V>(k, v);
}
public void setK(K k) {
this.k = k;
}
public void setV(V v) {
this.v = v;
}
public K getK() {
return k;
}
public V getV() {
return v;
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
try {
if (this == obj) {
return true;// 地址相等
}
if (obj == null) {
return false;// 非空性:对于任意非空引用x,x.equals(null)应该返回false。
}
if (obj instanceof KV) {
KV<K, V> other = (KV<K, V>) obj;
// 需要比较的字段相等,则这两个对象相等
if (other.k.equals(this.k) && other.v.equals(this.v)) {
return true;
}
}
} catch (Exception e) {
// 不做处理
}
return false;
}
@Override
public int hashCode() {
final int prime = 31;// 为什么是31?因为这个数需要是质数 31是经验验证的一个能够很好地减小哈希碰撞的质数
int result = 17;
result = prime * result + (this.k == null ? 0 : this.k.hashCode());
result = prime * result + (this.v == null ? 0 : this.v.hashCode());
return result;
}
@Override
public String toString() {
return this.k + "->" + this.v;
}
}zj.common.VVV<V1, V2, V3>
package zj.common;
import lombok.Data;
/**
* V1、V2、V3值
*
* @Description KV.java
* @author 张军
* @date 2017年10月10日 下午6:19:30
* @version V1.0
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
@Data
// @EqualsAndHashCode(callSuper = true)
public class VVV<V1, V2, V3> {
private V1 v1;
private V2 v2;
private V3 v3;
/**
* @see with(V1,V2,V3)
*/
@Deprecated
public VVV() {
}
/**
* @see with(V1,V2,V3)
*/
@Deprecated
public VVV(V1 v1, V2 v2, V3 v3) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}
public static <V1, V2, V3> VVV<V1, V2, V3> with(V1 v1, V2 v2, V3 v3) {
return new VVV<V1, V2, V3>(v1, v2, v3);
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
try {
if (this == obj) {
return true;// 地址相等
}
if (obj == null) {
return false;// 非空性:对于任意非空引用x,x.equals(null)应该返回false。
}
if (obj instanceof VVV) {
VVV<V1, V2, V3> other = (VVV<V1, V2, V3>) obj;
// 需要比较的字段相等,则这两个对象相等
if (other.v1.equals(this.v1) && other.v2.equals(this.v2) && other.v3.equals(this.v3)) {
return true;
}
}
} catch (Exception e) {
// 不做处理
}
return false;
}
@Override
public int hashCode() {
final int prime = 31;// 为什么是31?因为这个数需要是质数 31是经验验证的一个能够很好地减小哈希碰撞的质数
int result = 17;
result = prime * result + (this.v1 == null ? 0 : this.v1.hashCode());
result = prime * result + (this.v2 == null ? 0 : this.v2.hashCode());
result = prime * result + (this.v3 == null ? 0 : this.v3.hashCode());
return result;
}
@Override
public String toString() {
return this.v1 + "->" + this.v2 + "->" + this.v3;
}
}zj.common.VVVV<V1, V2, V3, V4>
package zj.common;
import lombok.Data;
/**
* V1、V2、V3、V4值
*
* @Description KV.java
* @author 张军
* @date 2017年10月10日 下午6:19:30
* @version V1.0
* @author SHNKCS 张军 {@link <a target=_blank href="http://www.zhangjunbk.com">张军个人网站</a> <a target=_blank href="http://user.qzone.qq.com/360901061/">张军QQ空间</a>}
*/
@Data
// @EqualsAndHashCode(callSuper = true)
public class VVVV<V1, V2, V3, V4> {
private V1 v1;
private V2 v2;
private V3 v3;
private V4 v4;
/**
* @see with(V1,V2,V3,V4)
*/
@Deprecated
public VVVV() {
}
/**
* @see with(V1,V2,V3,V4)
*/
@Deprecated
public VVVV(V1 v1, V2 v2, V3 v3, V4 v4) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
}
public static <V1, V2, V3, V4> VVVV<V1, V2, V3, V4> with(V1 v1, V2 v2, V3 v3, V4 v4) {
return new VVVV<V1, V2, V3, V4>(v1, v2, v3, v4);
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object obj) {
try {
if (this == obj) {
return true;// 地址相等
}
if (obj == null) {
return false;// 非空性:对于任意非空引用x,x.equals(null)应该返回false。
}
if (obj instanceof VVV) {
VVVV<V1, V2, V3, V4> other = (VVVV<V1, V2, V3, V4>) obj;
// 需要比较的字段相等,则这两个对象相等
if (other.v1.equals(this.v1) && other.v2.equals(this.v2) && other.v3.equals(this.v3) && other.v4.equals(this.v4)) {
return true;
}
}
} catch (Exception e) {
// 不做处理
}
return false;
}
@Override
public int hashCode() {
final int prime = 31;// 为什么是31?因为这个数需要是质数 31是经验验证的一个能够很好地减小哈希碰撞的质数
int result = 17;
result = prime * result + (this.v1 == null ? 0 : this.v1.hashCode());
result = prime * result + (this.v2 == null ? 0 : this.v2.hashCode());
result = prime * result + (this.v3 == null ? 0 : this.v3.hashCode());
result = prime * result + (this.v4 == null ? 0 : this.v4.hashCode());
return result;
}
@Override
public String toString() {
return this.v1 + "->" + this.v2 + "->" + this.v3 + "->" + this.v4;
}
}
本文为张军原创文章,转载无需和我联系,但请注明来自张军的军军小站,个人博客http://www.zhangjunbk.com

