所有工具類
比如異常通用處理,KV鍵值對處理,常量等都定義為通用類
zj.common.constant.Constants
package zj.common.constant;
/**
* 通用常量類
*
* @version 1.00 (2011.12.02)
* @author SHNKCS 張軍 {@link <a target=_blank href="http://www.dlhighland.cn">張軍個人網站</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.dlhighland.cn">張軍個人網站</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.dlhighland.cn">張軍個人網站</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.dlhighland.cn">張軍個人網站</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.dlhighland.cn">張軍個人網站</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.dlhighland.cn">張軍個人網站</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.dlhighland.cn
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

