x:开头的参数才会被使用
- *
- * @param params 待过滤的用户自定义参数
- * @return 过滤后的用户自定义参数
- */
- private static StringMap filterParam(StringMap params) {
- final StringMap ret = new StringMap();
- if (params == null) {
- return ret;
- }
-
- params.forEach(new StringMap.Consumer() {
- @Override
- public void accept(String key, Object value) {
- if (value == null) {
- return;
- }
- String val = value.toString();
- if (key.startsWith("x:") && !val.equals("")) {
- ret.put(key, val);
- }
- }
- });
-
- return ret;
- }
-
- /**
- * 上传字节数组
- *
- * @param data 上传的数据
- * @param key 上传数据保存的文件名
- * @param token 上传凭证
- */
- public Response put(final byte[] data, final String key, final String token) throws QiniuException {
- return put(data, key, token, null, null, false);
- }
-
- /**
- * 上传字节数组
- *
- * @param data 上传的数据
- * @param key 上传数据保存的文件名
- * @param token 上传凭证
- * @param params 自定义参数,如 params.put("x:foo", "foo")
- * @param mime 指定文件mimetype
- * @param checkCrc 是否验证crc32
- * @return
- * @throws QiniuException
- */
- public Response put(final byte[] data, final String key, final String token, StringMap params,
- String mime, boolean checkCrc) throws QiniuException {
- checkArgs(key, data, null, token);
- if (mime == null) {
- mime = Client.DefaultMime;
- }
- params = filterParam(params);
- return new FormUploader(client, token, key, data, params, mime, checkCrc, configuration).upload();
- }
-
- /**
- * 上传文件
- *
- * @param filePath 上传的文件路径
- * @param key 上传文件保存的文件名
- * @param token 上传凭证
- */
- public Response put(String filePath, String key, String token) throws QiniuException {
- return put(filePath, key, token, null, null, false);
- }
-
- /**
- * 上传文件
- *
- * @param filePath 上传的文件路径
- * @param key 上传文件保存的文件名
- * @param token 上传凭证
- * @param params 自定义参数,如 params.put("x:foo", "foo")
- * @param mime 指定文件mimetype
- * @param checkCrc 是否验证crc32
- */
- public Response put(String filePath, String key, String token, StringMap params,
- String mime, boolean checkCrc) throws QiniuException {
- return put(new File(filePath), key, token, params, mime, checkCrc);
- }
-
- /**
- * 上传文件
- *
- * @param file 上传的文件对象
- * @param key 上传文件保存的文件名
- * @param token 上传凭证
- */
- public Response put(File file, String key, String token) throws QiniuException {
- return put(file, key, token, null, null, false);
- }
-
- /**
- * 上传文件
- *
- * @param file 上传的文件对象
- * @param key 上传文件保存的文件名
- * @param token 上传凭证
- * @param mime 指定文件mimetype
- * @param checkCrc 是否验证crc32
- */
- public Response put(File file, String key, String token, StringMap params,
- String mime, boolean checkCrc) throws QiniuException {
- checkArgs(key, null, file, token);
- if (mime == null) {
- mime = Client.DefaultMime;
- }
- params = filterParam(params);
- long size = file.length();
- if (size <= configuration.putThreshold) {
- return new FormUploader(client, token, key, file, params, mime, checkCrc, configuration).upload();
- }
-
- ResumeUploader uploader = new ResumeUploader(client, token, key, file,
- params, mime, recorder, configuration);
- return uploader.upload();
- }
-
- /**
- * 异步上传数据
- *
- * @param data 上传的数据
- * @param key 上传数据保存的文件名
- * @param token 上传凭证
- * @param params 自定义参数,如 params.put("x:foo", "foo")
- * @param mime 指定文件mimetype
- * @param checkCrc 是否验证crc32
- * @param handler 上传完成的回调函数
- */
- public void asyncPut(final byte[] data, final String key, final String token, StringMap params,
- String mime, boolean checkCrc, UpCompletionHandler handler) throws IOException {
- checkArgs(key, data, null, token);
- if (mime == null) {
- mime = Client.DefaultMime;
- }
- params = filterParam(params);
- new FormUploader(client, token, key, data, params, mime, checkCrc, configuration).asyncUpload(handler);
- }
-
- /**
- * 流式上传,通常情况建议文件上传,可以使用持久化的断点记录。
- *
- * @param stream sha
- * @param key 上传文件保存的文件名
- * @param token 上传凭证
- * @param params 自定义参数,如 params.put("x:foo", "foo")
- * @param mime 指定文件mimetype
- */
- public Response put(InputStream stream, String key, String token, StringMap params,
- String mime) throws QiniuException {
- String message = null;
- if (stream == null) {
- message = "no input data";
- } else if (token == null || token.equals("")) {
- message = "no token";
- }
- if (message != null) {
- throw new IllegalArgumentException(message);
- }
- StreamUploader uploader = new StreamUploader(client, token, key, stream,
- params, mime, configuration);
- return uploader.upload();
- }
-}
\ No newline at end of file
diff --git a/luqj-common/src/main/java/com/luqj/sso/config/OssConfig.java b/luqj-common/src/main/java/com/luqj/sso/config/OssConfig.java
deleted file mode 100644
index 70d7c6b..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/config/OssConfig.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.luqj.sso.config;
-
-import com.aliyun.oss.OSSClient;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Created by luqj on 2018/5/17.
- */
-@Configuration
-public class OssConfig {
- @Value("${luqj.oss.endpoint}")
- private String ALIYUN_OSS_ENDPOINT;
- @Value("${luqj.oss.accessKey}")
- private String ALIYUN_OSS_ACCESSKEYID;
- @Value("${luqj.oss.secretKey}")
- private String ALIYUN_OSS_ACCESSKEYSECRET;
- @Bean
- public OSSClient ossClient(){
- return new OSSClient(ALIYUN_OSS_ENDPOINT,ALIYUN_OSS_ACCESSKEYID,ALIYUN_OSS_ACCESSKEYSECRET);
- }
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/controller/OssController.java b/luqj-common/src/main/java/com/luqj/sso/controller/OssController.java
deleted file mode 100644
index bd629ea..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/controller/OssController.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.luqj.sso.controller;
-
-
-import com.luqj.sso.entity.OssCallbackResult;
-import com.luqj.sso.entity.OssPolicyResult;
-import com.luqj.sso.service.OssService;
-import com.ruoyi.common.core.domain.AjaxResult;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * Oss相关操作接口
- * Created by luqj on 2018/4/26.
- */
-@Controller
-@Api(tags = "Oss管理-后台", description = "Oss管理")
-@RequestMapping("/common/oss")
-public class OssController {
- @Autowired
- private OssService ossService;
-
- @ApiOperation(value = "oss上传签名生成")
- @RequestMapping(value = "/policy", method = RequestMethod.GET)
- @ResponseBody
- public AjaxResult policy() {
- OssPolicyResult result = ossService.policy();
- return AjaxResult.success(result);
- }
-
- @ApiOperation(value = "oss上传成功回调")
- @RequestMapping(value = "callback", method = RequestMethod.POST)
- @ResponseBody
- public AjaxResult callback(HttpServletRequest request) {
- OssCallbackResult ossCallbackResult = ossService.callback(request);
- return AjaxResult.success(ossCallbackResult);
- }
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackParam.java b/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackParam.java
deleted file mode 100644
index 1f7c0a0..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackParam.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.luqj.sso.entity;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * oss上传成功后的回调参数
- * Created by luqj on 2018/5/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class OssCallbackParam {
- @ApiModelProperty("请求的回调地址")
- private String callbackUrl;
- @ApiModelProperty("回调是传入request中的参数")
- private String callbackBody;
- @ApiModelProperty("回调时传入参数的格式,比如表单提交形式")
- private String callbackBodyType;
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackResult.java b/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackResult.java
deleted file mode 100644
index 4e57a3d..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/entity/OssCallbackResult.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.luqj.sso.entity;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * oss上传文件的回调结果
- * Created by luqj on 2018/5/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class OssCallbackResult {
- @ApiModelProperty("文件名称")
- private String filename;
- @ApiModelProperty("文件大小")
- private String size;
- @ApiModelProperty("文件的mimeType")
- private String mimeType;
- @ApiModelProperty("图片文件的宽")
- private String width;
- @ApiModelProperty("图片文件的高")
- private String height;
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/entity/OssPolicyResult.java b/luqj-common/src/main/java/com/luqj/sso/entity/OssPolicyResult.java
deleted file mode 100644
index 03a36d1..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/entity/OssPolicyResult.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.luqj.sso.entity;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * 获取OSS上传文件授权返回结果
- * Created by luqj on 2018/5/17.
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class OssPolicyResult {
- @ApiModelProperty("访问身份验证中用到用户标识")
- private String accessKeyId;
- @ApiModelProperty("用户表单上传的策略,经过base64编码过的字符串")
- private String policy;
- @ApiModelProperty("对policy签名后的字符串")
- private String signature;
- @ApiModelProperty("上传文件夹路径前缀")
- private String dir;
- @ApiModelProperty("oss对外服务的访问域名")
- private String host;
- @ApiModelProperty("上传成功后的回调设置")
- private String callback;
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/service/OssService.java b/luqj-common/src/main/java/com/luqj/sso/service/OssService.java
deleted file mode 100644
index 2d349e3..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/service/OssService.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.luqj.sso.service;
-
-import com.luqj.sso.entity.OssCallbackResult;
-import com.luqj.sso.entity.OssPolicyResult;
-
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * oss上传管理Service
- * Created by luqj on 2018/5/17.
- */
-public interface OssService {
- /**
- * oss上传策略生成
- */
- OssPolicyResult policy();
- /**
- * oss上传成功回调
- */
- OssCallbackResult callback(HttpServletRequest request);
-}
diff --git a/luqj-common/src/main/java/com/luqj/sso/service/impl/OssServiceImpl.java b/luqj-common/src/main/java/com/luqj/sso/service/impl/OssServiceImpl.java
deleted file mode 100644
index 2d9be0c..0000000
--- a/luqj-common/src/main/java/com/luqj/sso/service/impl/OssServiceImpl.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.luqj.sso.service.impl;
-
-import cn.hutool.json.JSONUtil;
-import com.aliyun.oss.OSSClient;
-import com.aliyun.oss.common.utils.BinaryUtil;
-import com.aliyun.oss.model.MatchMode;
-import com.aliyun.oss.model.PolicyConditions;
-import com.luqj.sso.entity.OssCallbackParam;
-import com.luqj.sso.entity.OssCallbackResult;
-import com.luqj.sso.entity.OssPolicyResult;
-import com.luqj.sso.service.OssService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-import javax.servlet.http.HttpServletRequest;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * oss上传管理Service实现类
- * Created by luqj on 2018/5/17.
- */
-@Service
-public class OssServiceImpl implements OssService {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(OssServiceImpl.class);
- @Value("${luqj.oss.policy.expire}")
- private int ALIYUN_OSS_EXPIRE;
- @Value("${luqj.oss.maxSize}")
- private int ALIYUN_OSS_MAX_SIZE;
- @Value("${luqj.oss.callback}")
- private String ALIYUN_OSS_CALLBACK;
- @Value("${luqj.oss.bucketName}")
- private String ALIYUN_OSS_BUCKET_NAME;
- @Value("${luqj.oss.endpoint}")
- private String ALIYUN_OSS_ENDPOINT;
- @Value("${luqj.oss.dir.prefix}")
- private String ALIYUN_OSS_DIR_PREFIX;
-
- @Autowired
- private OSSClient ossClient;
-
- /**
- * 签名生成
- */
- @Override
- public OssPolicyResult policy() {
- OssPolicyResult result = new OssPolicyResult();
- // 存储目录
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
- String dir = ALIYUN_OSS_DIR_PREFIX + sdf.format(new Date());
- // 签名有效期
- long expireEndTime = System.currentTimeMillis() + ALIYUN_OSS_EXPIRE * 1000;
- Date expiration = new Date(expireEndTime);
- // 文件大小
- long maxSize = ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
- // 回调
- OssCallbackParam callback = new OssCallbackParam();
- callback.setCallbackUrl(ALIYUN_OSS_CALLBACK);
- callback.setCallbackBody("filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}");
- callback.setCallbackBodyType("application/x-www-form-urlencoded");
- // 提交节点
- String action = "http://" + ALIYUN_OSS_BUCKET_NAME + "." + ALIYUN_OSS_ENDPOINT;
- try {
- PolicyConditions policyConds = new PolicyConditions();
- policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, maxSize);
- policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
- String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);
- byte[] binaryData = postPolicy.getBytes("utf-8");
- String policy = BinaryUtil.toBase64String(binaryData);
- String signature = ossClient.calculatePostSignature(postPolicy);
- String callbackData = BinaryUtil.toBase64String(JSONUtil.parse(callback).toString().getBytes("utf-8"));
- // 返回结果
- result.setAccessKeyId(ossClient.getCredentialsProvider().getCredentials().getAccessKeyId());
- result.setPolicy(policy);
- result.setSignature(signature);
- result.setDir(dir);
- result.setCallback(callbackData);
- result.setHost(action);
- } catch (Exception e) {
- LOGGER.error("签名生成失败", e);
- }
- return result;
- }
-
- @Override
- public OssCallbackResult callback(HttpServletRequest request) {
- OssCallbackResult result = new OssCallbackResult();
- String filename = request.getParameter("filename");
- filename = "http://".concat(ALIYUN_OSS_BUCKET_NAME).concat(".").concat(ALIYUN_OSS_ENDPOINT).concat("/").concat(filename);
- result.setFilename(filename);
- result.setSize(request.getParameter("size"));
- result.setMimeType(request.getParameter("mimeType"));
- result.setWidth(request.getParameter("width"));
- result.setHeight(request.getParameter("height"));
- return result;
- }
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/ArithmeticEnum.java b/luqj-common/src/main/java/com/luqj/util/ArithmeticEnum.java
deleted file mode 100644
index 112950c..0000000
--- a/luqj-common/src/main/java/com/luqj/util/ArithmeticEnum.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.luqj.util;
-
-
-/**
- * 算术符号
- * @author chenzm
- */
-public enum ArithmeticEnum {
-
- /**左括号**/
- lb("(", "左括号", -1),
- /**右括号**/
- rb(")", "右括号", -1),
-
- /**乘**/
- multiply("*", "乘", -3),
- /**除**/
- division("/", "除", -3),
-
- /**加**/
- addition("+", "加", -4),
- /**减**/
- subtract("-", "减", -4),
-
- /**大于**/
- gt(">", "大于", -6),
- /**小于**/
- lt("<", "小于", -6),
- /**大于等于**/
- gte(">=", "大于等于", -6),
- /**小于等于**/
- lte("<=", "小于等于", -6);
-
- /**符号**/
- private String symbol;
-
- /**优先级**/
- private int priority;
-
- private String desc;
-
- private ArithmeticEnum(String symbol, String desc, int priority) {
- this.symbol = symbol;
- this.desc = desc;
- this.priority = priority;
- }
-
- public boolean isEqualBySymbol(String c) {
- return this.getSymbol().equals(c);
- }
-
- public boolean isEqualBySymbol(char c) {
- return this.getSymbol().equals("" + c);
- }
-
- public String getSymbol() {
- return symbol;
- }
-
- public void setSymbol(String symbol) {
- this.symbol = symbol;
- }
-
- public String getDesc() {
- return desc;
- }
-
- public void setDesc(String desc) {
- this.desc = desc;
- }
-
- public int getPriority() {
- return priority;
- }
-
- public void setPriority(int priority) {
- this.priority = priority;
- }
-
- /**
- * 获取符号等级
- */
- public static int getSymbolLevel(String c) {
- return getArithmeticEnum(c).getPriority();
- }
-
- public static ArithmeticEnum getArithmeticEnum(String c) {
- for(ArithmeticEnum t : ArithmeticEnum.values()) {
- if(t.getSymbol().equals(c)) {
- return t;
- }
- }
- return null;
- }
-
- public static boolean containsKey(String c) {
- if(getArithmeticEnum(c) != null) {
- return true;
- }
- return false;
- }
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/CharBuffer.java b/luqj-common/src/main/java/com/luqj/util/CharBuffer.java
deleted file mode 100644
index 0d4b14f..0000000
--- a/luqj-common/src/main/java/com/luqj/util/CharBuffer.java
+++ /dev/null
@@ -1,567 +0,0 @@
-package com.luqj.util;
-
-
-import com.luqj.util.parse.SymbolSet;
-
-import java.util.NoSuchElementException;
-
-/**
- * 字符缓存
- */
-public class CharBuffer {
-
- transient int size = 0;
-
- transient Node first;
-
- transient Node last;
-
- transient int modCount = 0;
-
- public CharBuffer() {
- }
-
- public CharBuffer(String str) {
- for(char c : str.toCharArray()) {
- this.add(c);
- }
- }
-
- public CharBuffer(char[] chs) {
- for(char c : chs) {
- this.add(c);
- }
- }
-
- public String asString() {
- return new String(this.toArray());
- }
-
- public void addStr(String str) {
- for(char c : str.toCharArray()) {
- this.add(c);
- }
- }
-
- /**
- * Links e as first element.
- */
- private void linkFirst(char e) {
- final Node f = first;
- final Node newNode = new Node(null, e, f);
- first = newNode;
- if (f == null)
- last = newNode;
- else
- f.prev = newNode;
- size++;
- modCount++;
- }
-
-
- void linkLast(char e) {
- final Node l = last;
- final Node newNode = new Node(l, e, null);
- last = newNode;
- if (l == null)
- first = newNode;
- else
- l.next = newNode;
- size++;
- modCount++;
- }
-
- /**
- * Inserts element e before non-null Node succ.
- */
- void linkBefore(char e, Node succ) {
- // assert succ != null;
- final Node pred = succ.prev;
- final Node newNode = new Node(pred, e, succ);
- succ.prev = newNode;
- if (pred == null)
- first = newNode;
- else
- pred.next = newNode;
- size++;
- modCount++;
- }
-
- /**
- * Unlinks non-null first node f.
- */
- private char unlinkFirst(Node f) {
- // assert f == first && f != null;
- final char element = f.item;
- final Node next = f.next;
- //f.item = ' ';
- f.next = null; // help GC
- first = next;
- if (next == null)
- last = null;
- else
- next.prev = null;
- size--;
- modCount++;
- return element;
- }
-
- /**
- * Unlinks non-null last node l.
- */
- private char unlinkLast(Node l) {
- // assert l == last && l != null;
- final char element = l.item;
- final Node prev = l.prev;
- //l.item = null;
- l.prev = null; // help GC
- last = prev;
- if (prev == null)
- first = null;
- else
- prev.next = null;
- size--;
- modCount++;
- return element;
- }
-
- /**
- * Unlinks non-null node x.
- */
- char unlink(Node x) {
- // assert x != null;
- final char element = x.item;
- final Node next = x.next;
- final Node prev = x.prev;
-
- if (prev == null) {
- first = next;
- } else {
- prev.next = next;
- x.prev = null;
- }
-
- if (next == null) {
- last = prev;
- } else {
- next.prev = prev;
- x.next = null;
- }
-
- //x.item = null;
- size--;
- modCount++;
- return element;
- }
-
- /**
- * Returns the first element in this list.
- *
- * @return the first element in this list
- * @throws NoSuchElementException if this list is empty
- */
- public char getFirst() {
- final Node f = first;
- if (f == null)
- throw new NoSuchElementException();
- return f.item;
- }
-
- /**
- * Returns the last element in this list.
- *
- * @return the last element in this list
- * @throws NoSuchElementException if this list is empty
- */
- public char getLast() {
- final Node l = last;
- if (l == null)
- throw new NoSuchElementException();
- return l.item;
- }
-
- /**
- * Removes and returns the first element from this list.
- *
- * @return the first element from this list
- * @throws NoSuchElementException if this list is empty
- */
- public char removeFirst() {
- final Node f = first;
- if (f == null)
- throw new NoSuchElementException();
- return unlinkFirst(f);
- }
-
- /**
- * Removes and returns the last element from this list.
- *
- * @return the last element from this list
- * @throws NoSuchElementException if this list is empty
- */
- public char removeLast() {
- final Node l = last;
- if (l == null)
- throw new NoSuchElementException();
- return unlinkLast(l);
- }
-
- /**
- * Inserts the specified element at the beginning of this list.
- *
- * @param e the element to add
- */
- public void addFirst(char e) {
- linkFirst(e);
- }
-
- /**
- * Appends the specified element to the end of this list.
- *
- * This method is equivalent to {@link #add}. - * - * @param e the element to add - */ - public void addLast(char e) { - linkLast(e); - } - - /** - * Returns the number of elements in this list. - * - * @return the number of elements in this list - */ - public int size() { - return size; - } - - /** - * Appends the specified element to the end of this list. - * - *
This method is equivalent to {@link #addLast}. - * - * @param e element to be appended to this list - * @return {@code true} (as specified by - */ - public boolean add(char e) { - linkLast(e); - return true; - } - - - - - /** - * Removes all of the elements from this list. - * The list will be empty after this call returns. - */ - public void clear() { - // Clearing all of the links between nodes is "unnecessary", but: - // - helps a generational GC if the discarded nodes inhabit - // more than one generation - // - is sure to free memory even if there is a reachable Iterator - for (Node x = first; x != null; ) { - Node next = x.next; - //x.item = null; - x.next = null; - x.prev = null; - x = next; - } - first = last = null; - size = 0; - modCount++; - } - - - // Positional Access Operations - - /** - * Returns the element at the specified position in this list. - * - * @param index index of the element to return - * @return the element at the specified position in this list - * @throws IndexOutOfBoundsException {@inheritDoc} - */ - public char get(int index) { - //checkElementIndex(index); - return node(index).item; - } - - - - /** - * Tells if the argument is the index of an existing element. - */ - private boolean isElementIndex(int index) { - return index >= 0 && index < size; - } - - /** - * Tells if the argument is the index of a valid position for an - * iterator or an add operation. - */ - private boolean isPositionIndex(int index) { - return index >= 0 && index <= size; - } - - /** - * Constructs an IndexOutOfBoundsException detail message. - * Of the many possible refactorings of the error handling code, - * this "outlining" performs best with both server and client VMs. - */ - private String outOfBoundsMsg(int index) { - return "Index: "+index+", Size: "+size; - } - - /*private void checkElementIndex(int index) { - if (!isElementIndex(index)) - throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); - }*/ - - /* private void checkPositionIndex(int index) { - if (!isPositionIndex(index)) - throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); - }*/ - - /** - * Returns the (non-null) Node at the specified element index. - */ - Node node(int index) { - // assert isElementIndex(index); - - if (index < (size >> 1)) { - Node x = first; - for (int i = 0; i < index; i++) - x = x.next; - return x; - } else { - Node x = last; - for (int i = size - 1; i > index; i--) - x = x.prev; - return x; - } - } - - - /** - * Retrieves and removes the head (first element) of this list. - * - * @return the head of this list, or {@code null} if this list is empty - * @since 1.5 - */ - public char poll() { - final Node f = first; - return (f == null) ? null : unlinkFirst(f); - } - - /** - * Retrieves and removes the head (first element) of this list. - * - * @return the head of this list - * @throws NoSuchElementException if this list is empty - * @since 1.5 - */ - public char remove() { - return removeFirst(); - } - - /** - * Adds the specified element as the tail (last element) of this list. - * - * @param e the element to add - * @since 1.5 - */ - public boolean offer(char e) { - return add(e); - } - - // Deque operations - /** - * Inserts the specified element at the front of this list. - * - * @param e the element to insert - * @since 1.6 - */ - public boolean offerFirst(char e) { - addFirst(e); - return true; - } - - /** - * Inserts the specified element at the end of this list. - * - * @param e the element to insert - * @since 1.6 - */ - public boolean offerLast(char e) { - addLast(e); - return true; - } - - /** - * Retrieves, but does not remove, the first element of this list, - * or returns {@code null} if this list is empty. - * - * @return the first element of this list, or {@code null} - * if this list is empty - * @since 1.6 - */ - public char peekFirst() { - final Node f = first; - return (f == null) ? null : f.item; - } - - public boolean isEmpty() { - return size() == 0; - } - - /** - * Retrieves, but does not remove, the last element of this list, - * or returns {@code null} if this list is empty. - * - * @return the last element of this list, or {@code null} - * if this list is empty - * @since 1.6 - */ - public char peekLast() { - final Node l = last; - return (l == null) ? null : l.item; - } - - /** - * Retrieves and removes the first element of this list, - * or returns {@code null} if this list is empty. - * - * @return the first element of this list, or {@code null} if - * this list is empty - * @since 1.6 - */ - public char pollFirst() { - final Node f = first; - return (f == null) ? null : unlinkFirst(f); - } - - /** - * Retrieves and removes the last element of this list, - * or returns {@code null} if this list is empty. - * - * @return the last element of this list, or {@code null} if - * this list is empty - * @since 1.6 - */ - public char pollLast() { - final Node l = last; - return (l == null) ? null : unlinkLast(l); - } - - /** - * Pushes an element onto the stack represented by this list. In other - * words, inserts the element at the front of this list. - * - *
This method is equivalent to {@link #addFirst}. - * - * @param e the element to push - * @since 1.6 - */ - public void push(char e) { - addFirst(e); - } - - /** - * Pops an element from the stack represented by this list. In other - * words, removes and returns the first element of this list. - * - *
This method is equivalent to {@link #removeFirst()}. - * - * @return the element at the front of this list (which is the top - * of the stack represented by this list) - * @throws NoSuchElementException if this list is empty - * @since 1.6 - */ - public char pop() { - return removeFirst(); - } - - private static class Node { - char item; - Node next; - Node prev; - - Node(Node prev, char element, Node next) { - this.item = element; - this.next = next; - this.prev = prev; - } - } - - - - /** - * Returns an array containing all of the elements in this list - * in proper sequence (from first to last element). - * - *
The returned array will be "safe" in that no references to it are - * maintained by this list. (In other words, this method must allocate - * a new array). The caller is thus free to modify the returned array. - * - *
This method acts as bridge between array-based and collection-based
- * APIs.
- *
- * @return an array containing all of the elements in this list
- * in proper sequence
- */
- public char[] toArray() {
- char[] result = new char[size];
- int i = 0;
- for (Node x = first; x != null; x = x.next)
- result[i++] = x.item;
- return result;
- }
-
- public char[] subArray(int start,int end){
- if (start < 0)
- throw new ArrayIndexOutOfBoundsException(start);
- if (end > size)
- throw new StringIndexOutOfBoundsException(end);
- if (start > end)
- throw new ArrayIndexOutOfBoundsException(end - start);
- int size = end-start;
- char[] result = new char[size];
- int iStart = 0;
- for (Node x = first; x != null && iStart < end; x = x.next){
- if(iStart >= start){
- result[iStart - start] = x.item;
- }
- iStart++;
- }
- return result;
- }
-
-
-
- @Override
- public String toString() {
- StringBuffer sb = new StringBuffer();
- for (Node x = first; x != null; x = x.next)
- sb.append(x.item+",");
- return "["+sb.toString()+"]";
- }
-
- /**
- * 是否是文本
- * @return
- */
- public boolean isText() {
- boolean isNull = true;
- for(char c : this.toArray()) {
- if(c != SymbolSet.SYMBOL_NULL) {
- isNull = false;
- break;
- }
- }
- return this.size() > 0 && !isNull;
- }
-
-
- private static final long serialVersionUID = 876323262645176354L;
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/FileSystemUtil.java b/luqj-common/src/main/java/com/luqj/util/FileSystemUtil.java
deleted file mode 100644
index e27d14e..0000000
--- a/luqj-common/src/main/java/com/luqj/util/FileSystemUtil.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package com.luqj.util;
-
-
-import com.luqj.util.assertion.Assert;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class FileSystemUtil {
-
- private static final char SYSTEM_SEPARATOR = File.separatorChar;
-
- private static final char WINDOWS_SEPARATOR = '\\';
-
- /**
- * 递归获取指定目录下的所有文件
- * @param dir
- * @param filterDir 子目录是否返回在集合中
- * @return
- */
- public static final List This Map implementation is generally not thread-safe. It is primarily designed
- * for data structures exposed from request objects, for use in a single thread only.
- *
- * @author Arjen Poutsma
- * @author Juergen Hoeller
- * @since 3.0
- */
-public class LinkedMultiValueMap 指定的字符串如果是可以是负数表示或者十六进制,八进制表示
- * 负数表示前面加-,十六进制表示前面加0x 0X #,八进制表示前面加0
- * @param value 要转换的字符串
- * @return 返回> values() {
- return this.targetMap.values();
- }
-
- public Set
null
- */
- V getFirst(K key);
-
- /**
- * Add the given single value to the current list of values for the given key.
- * @param key the key
- * @param value the value to be added
- */
- void add(K key, V value);
-
- /**
- * Set the given single value under the given key.
- * @param key the key
- * @param value the value to set
- */
- void set(K key, V value);
-
- /**
- * Set the given values under.
- * @param values the values.
- */
- void setAll(MapNumber对象转换为指定的类型对象
- *
- * @param number the number to convert
- * @return 目标类型的对象
- */
- public static Number convertNumber(Number number, Class targetClass)
- throws IllegalArgumentException {
- Assert.notNull(number, "Number对象不可以为null");
- Assert.notNull(targetClass, "Number目标类对象参数不可以为null");
- if (targetClass.isInstance(number)) {
- return number;
- }else if (targetClass.equals(Byte.class)) {
- long value = number.longValue();
- if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
- raiseOverflowException(number, targetClass);
- }
- return new Byte(number.byteValue());
- }else if (targetClass.equals(Short.class)) {
- long value = number.longValue();
- if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
- raiseOverflowException(number, targetClass);
- }
- return new Short(number.shortValue());
- }else if (targetClass.equals(Integer.class)) {
- long value = number.longValue();
- if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
- raiseOverflowException(number, targetClass);
- }
- return new Integer(number.intValue());
- }else if (targetClass.equals(Long.class)) {
- return new Long(number.longValue());
- }else if (targetClass.equals(Float.class)) {
- return new Float(number.floatValue());
- }else if (targetClass.equals(Double.class)) {
- return new Double(number.doubleValue());
- }else if (targetClass.equals(BigInteger.class)) {
- return BigInteger.valueOf(number.longValue());
- }else if (targetClass.equals(BigDecimal.class)) {
- // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
- // (see BigDecimal javadoc for details)
- return new BigDecimal(number.toString());
- }else {
- throw new IllegalArgumentException("无法将值为 [" + number + "] 类型为 [" +
- number.getClass().getName() + "] 的对象转换为 [" + targetClass.getName() + "]");
- }
- }
-
- /**
- * 如果指定的值超过了指定的类型的值所能容纳的最大或最小值将抛该异常
- * @param number 需要转换的值
- * @param targetClass 目标对象的类型
- */
- private static void raiseOverflowException(Number number, Class targetClass) {
- throw new IllegalArgumentException("无法将值为 [" + number + "] 类型为 [" +
- number.getClass().getName() + "] 的对象转换为 [" + targetClass.getName() + "]: 值超过了目标对象的值得范围");
- }
-
- /**
- * 将字符串格式转换为指定的目标类的Number对象
- * @param text 需要转换的字符串
- * @param targetClass 目标类型
- * @return 目标类型的对象
- * @throws IllegalArgumentException 如果不支持指定的目标类型的话将抛该异常
- */
- public static Number parseNumber(String text,Class targetClass) {
- Assert.notNull(text, "字符串参数不可以为null");
- Assert.notNull(targetClass, "Number目标类对象参数不可以为null");
- String trimmed = text.trim();
- if (targetClass.equals(Byte.class)) {
- return Byte.decode(trimmed);
- }
- else if (targetClass.equals(Short.class)) {
- return Short.decode(trimmed);
- }
- else if (targetClass.equals(Integer.class)) {
- return Integer.decode(trimmed);
- }
- else if (targetClass.equals(Long.class)) {
- return Long.decode(trimmed);
- }
- else if (targetClass.equals(Float.class)) {
- return Float.valueOf(trimmed);
- }
- else if (targetClass.equals(Double.class)) {
- return Double.valueOf(trimmed);
- }
- else if (targetClass.equals(BigInteger.class)) {
- return decodeBigInteger(trimmed);
- }
- else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
- return new BigDecimal(trimmed);
- }
- else {
- throw new IllegalArgumentException(
- "转换失败! String [" + text + "] to target class [" + targetClass.getName() + "]");
- }
- }
-
- /**
- * 将字符串转换为BigInteger
- *
- * BigInteger对象
- * @see BigInteger#BigInteger(String, int)
- */
- private static BigInteger decodeBigInteger(String value) {
- int radix = 10;//基数
- int index = 0;//串索引
- boolean negative = false;//判断是否为负数
- if (value.startsWith("-")) {
- negative = true;
- index++;
- }
- if (value.startsWith("0x", index) || value.startsWith("0X", index)) {
- index += 2;
- radix = 16;
- }
- else if (value.startsWith("#", index)) {
- index++;
- radix = 16;
- }
- else if (value.startsWith("0", index) && value.length() > 1 + index) {
- index++;
- radix = 8;
- }
- BigInteger result = new BigInteger(value.substring(index), radix);
- return (negative ? result.negate() : result);
- }
-
-
- /**
- *
- * @param number
- * @return
- */
- public static String setString(double number){
- return number==0?" ":String.valueOf(number);
- }
-
- /**
- * 两个Double类型相加后返回Double类型(如果其中一个为NULL则视为0)
- * @param value1
- * @param value2
- * @return
- */
- public static Double addValue(Double value1,Double value2){
- return $Double(value1)+$Double(value2);
- }
-
- /**
- * 两个Long类型相加后返回Long类型(如果其中一个为NULL则视为0)
- * @param value1
- * @param value2
- * @return
- */
- public static Long addValue(Long value1,Long value2){
- return $Long(value1)+$Long(value2);
- }
-
- /**
- * 将double类型的数据改为非科学记数法表示
- * @param unFormatedNumber
- * @return
- */
- public static String formateNonScience(double unFormatedNumber){
- DecimalFormat format = new DecimalFormat("#0.000");
- return format.format(unFormatedNumber);
- }
-
-
-
-
-
- public static Number parseNum(Class targetClass,Number v){
-
- if(targetClass.equals(Byte.class)){
- return Byte.valueOf(v.byteValue());
- }
- else if (targetClass.equals(Short.class)) {
- return Short.valueOf(v.shortValue());
- }
- else if (targetClass.equals(Integer.class)) {
- return Integer.valueOf(v.intValue());
- }
- else if (targetClass.equals(Long.class)) {
- return Long.valueOf(v.longValue());
- }
- else if (targetClass.equals(Float.class)) {
- return Float.valueOf(0);
- }
- else if (targetClass.equals(Double.class)) {
- return Double.valueOf(v.doubleValue());
- }
- else if (targetClass.equals(BigInteger.class)) {
- return new BigInteger(String.valueOf(v.longValue()));
- }
- else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
- return new BigDecimal(v.doubleValue());
- }
- else {
- throw new IllegalArgumentException(
- "类型[" + targetClass.getName() + "],无法初始化0值");
- }
- }
-
-
-
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/RequestHelper.java b/luqj-common/src/main/java/com/luqj/util/RequestHelper.java
deleted file mode 100644
index 969dd64..0000000
--- a/luqj-common/src/main/java/com/luqj/util/RequestHelper.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package com.luqj.util;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Modifier;
-import java.net.URLEncoder;
-import java.nio.file.Files;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class RequestHelper {
- private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
- public static Map
- * 字符串处理工具类.
- * <blockquote>
- * <b>数字格式化样式</b>
- * <table border=0 cellspacing=3 cellpadding=0 width="90%">
- *
- *
- *
- *
- *
- * Symbol
- *
- *
- * Location
- *
- *
- * Localized
- *
- *
- * Meaning
- *
- *
- *
- *
- *
- * 0
- * Number
- *
- *
- * Yes
- *
- *
- * Digit
- *
- *
- *
- *
- *
- * #
- *
- * Number
- *
- *
- * Yes
- *
- *
- * Digit, zero shows as absent
- *
- *
- *
- *
- *
- * .
- *
- * Number
- *
- *
- * Yes
- *
- *
- * Decimal separator or monetary decimal separator
- *
- *
- *
- *
- *
- * -
- *
- * Number
- *
- *
- * Yes
- *
- *
- * Minus sign
- *
- *
- *
- *
- *
- * ,
- *
- * Number
- *
- *
- * Yes
- *
- *
- * Grouping separator
- *
- *
- *
- *
- *
- * E
- * Number
- *
- *
- * Yes
- *
- *
- * Separates mantissa and exponent in scientific notation.
- *
- * Need not be quoted in prefix or suffix.
- *
- *
- *
- *
- *
- * ;
- *
- * Subpattern boundary
- *
- *
- * Yes
- *
- *
- * Separates positive and negative subpatterns
- *
- *
- *
- *
- *
- * %
- *
- * Prefix or suffix
- *
- *
- * Yes
- *
- *
- * Multiply by 100 and show as percentage
- *
- *
- *
- *
- *
- * \u2030
- *
- * Prefix or suffix
- *
- *
- * Yes
- *
- *
- * Multiply by 1000 and show as per mille
- *
- *
- *
- *
- *
- * ¤
- * (
- *
- * \u00A4
- *
- * )
- *
- * Prefix or suffix
- *
- *
- * No
- *
- *
- * Currency sign, replaced by currency symbol. If
- * doubled, replaced by international currency symbol.
- * If present in a pattern, the monetary decimal separator
- * is used instead of the decimal separator.
- *
- *
- *
- * </table>
- *
- * <b>符号(Symbol)通常是组合在一起使用的,例如下表</b>
- * <table border=0 cellspacing=3 cellpadding=0 width="90%">
- *
- *
- * '
- *
- * Prefix or suffix
- *
- *
- * No
- *
- *
- * Used to quote special characters in a prefix or suffix,
- * for example,
- *
- *
- * "'#'#"
- *
- * formats 123 to
- *
- * "#123"
- *
- * . To create a single quote
- * itself, use two in a row:
- *
- * "# o''clock"
- *
- * .
- *
- *
- *
- * 输入
- *
- *
- * 格式
- *
- *
- * 输出
- *
- *
- *
- *
- * 1234.123456
- *
- *
- *
- * 0
- * 1234
- *
- *
- *
- *
- *
- * 0.00
- *
- * 1234.12
- *
- *
- *
- *
- *
- * 0.###
- *
- * 1234.123
- *
- *
- *
- *
- *
- * 0.0000
- *
- * 1234.1235
- *
- *
- *
- *
- *
- * 00000000.00
- *
- * 00001234.12
- *
- *
- *
- *
- *
- * ,000.00
- *
- * 1,234.12
- *
- *
- *
- *
- *
- * ,00.00000000
- *
- * 12,34.12345600
- *
- *
- *
- *
- *
- * 0.00%
- *
- * 123412.35%
- *
- *
- *
- *
- * 1234.100056
- *
- *
- *
- * 0
- * 1234
- *
- *
- *
- *
- *
- * 0.00
- *
- * 1234.10
- *
- *
- *
- *
- *
- * 0.##
- *
- * 1234.1
- *
- *
- *
- *
- *
- * (人民币),000.00
- *
- * (人民币)1,234.10
- *
- *
- *
- * </table>
- *
- *
- * ,000.########
- *
- * 1,234.100056
- *
- *
- * 注:0与#功能类似,区别在于用0表示位数时,格式化后的首尾的0会显示,而用#表示位数时,首尾的0不显示
- * </blockquote>
- *
- *
- *
- *
- * @author 涂传滨,伊新煦,陈雄华,谢计生
- * @version 1.0
- * @since 1.0
- * @see DecimalFormat
- */
-public final class StringUtils {
-
- /** 字符长度 */
- public static final int CHAR_LEN = 1;
-
- /** 字节长度 */
- public static final int BYTE_LEN = 2;
-
- final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");;
-
- public static boolean notBlank(String str) {
- return !isBlank(str);
- }
-
- public static boolean notBlank(String... strings) {
- if (strings == null || strings.length == 0) {
- return false;
- }
- for (String str : strings) {
- if (isBlank(str)) {
- return false;
- }
- }
- return true;
- }
-
- public static boolean hasText(String text) {
- if (text == null)
- return false;
- for (int i = 0; i < text.length(); i++) {
- if (!Character.isWhitespace(text.charAt(i)))
- return true;
- }
- return false;
- }
-
- public static String parseDateToString(Object obj){
-
- String dateStr = null;
-
- if(obj == null){
- return null;
- }
-
- if(obj.getClass().getName().equals("java.sql.Date")){
- Date date = (Date) obj;
- return String.valueOf(date.getTime());
- }else if(obj.getClass().getName().equals("java.sql.Timestamp")){
- Timestamp date = (Timestamp) obj;
- return String.valueOf(date.getTime());
- }else if(obj.getClass().getName().equals("java.sql.Time")){
- Time date = (Time) obj;
- return String.valueOf(date.getTime());
- }else{
- return String.valueOf(obj);
- }
-
- /*if(obj.getClass().getName().equals("java.sql.Date")||
- obj.getClass().getName().equals("java.sql.Timestamp")||
- obj.getClass().getName().equals("java.sql.Time")){
- try {
- Date date = (Date) obj;
- date.getTime();
- dateStr = DATE_FORMAT.format(obj);
- } catch (ArrayIndexOutOfBoundsException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- logger.error("出现异常的数据"+obj);
- throw new ArrayIndexOutOfBoundsException("数组越界"+obj);
- }
- }else{
- return (String)obj;
- }
- */
- //return dateStr;
-
- }
-
-
- public static String uuid(){
- return UUID.randomUUID().toString().replaceAll("-", "");
- }
-
-
- public static String lowerFirst(String v){
- return v.replaceFirst(v.substring(0,1), v.substring(0,1).toLowerCase());
- }
-
- public static String upFirst(String v){
- return v.replaceFirst(v.substring(0,1), v.substring(0,1).toUpperCase());
- }
-
- /**
- * 数字字符串转化为整数
- *
- * @param intStr
- * String 待转化的数字字符串
- * @param intDef
- * int 当intStr为空或空字符串时返回的缺省值
- * @return int 返回由数字字符串转化成的数字,当intStr为空或空字符串时,返回缺省值intDef
- */
- public static int getInt(String intStr, int intDef) {
- if (null == intStr || "".equals(intStr.trim())) {
- return intDef;
- }
-
- int intRetu = intDef;
-
- Double db = new Double(intStr);
- intRetu = db.intValue();
- return intRetu;
- }
-
- /**
- * 数字字符串转化为整数,在转化时发生异常,则返回0
- *
- * @param intStr
- * String 待转化的数字字符串
- * @return int 返回由数字字符串转化成的整数,当intStr为空或空字符串时,返回0
- */
- public static int getInt(String intStr) {
- return getInt(intStr, 0);
- }
-
- /**
- * 数字字符串转化为双精数字
- *
- * @param dbstr
- * String 待转化的数字字符串
- * @param dbDef
- * double 当dbstr为空或空字符串时返回的缺省值
- * @return double 返回由数字字符串转化成的数字,当dbstr为空或空字符串时,则返回缺省值dbDef
- */
- public static double getDouble(String dbstr, double dbDef) {
-
- if (null == dbstr || "".equals(dbstr.trim())) {
- return dbDef;
- }
- double dbRetu = dbDef;
- Double db = new Double(dbstr);
- dbRetu = db.doubleValue();
- return dbRetu;
- }
-
- /**
- * 数字字符串转化为双精数字,在转化时发生异常,则返回0
- *
- * @param dbstr
- * String 待转化的数字字符串
- * @return double 返回由数字字符串转化成的数字,当dbstr为空或空字符串时,则返回0。
- */
- public static double getDouble(String dbstr) {
- return getDouble(dbstr, 0);
- }
-
- /**
- * 数字字符串转化为长整型
- *
- * @param longstr
- * String 待转化的数字字符串
- * @param longDef
- * long 当longstr为空或空字符串时返回的缺省值
- * @return long 返回由数字字符串转化成的数字,当longstr为空或空字符串时,则返回缺省值longDef
- */
- public static long getLong(String longstr, long longDef) {
- if (null == longstr || "".equals(longstr.trim())) {
- return longDef;
- }
- long longRetu = longDef;
-
- Double db = new Double(longstr);
- longRetu = db.longValue();
-
- return longRetu;
- }
-
- /**
- * 数字字符串转化为长整型,在转化时发生异常,则返回0
- *
- * @param longstr
- * String 待转化的数字字符串
- * @return long 返回由数字字符串转化成的数字,当longstr为空或空字符串时,则返回0。
- */
- public static long getLong(String longstr) {
- return getLong(longstr, 0);
- }
-
- /**
- * 字符串转化为布尔型
- *
- * @param booleanstr
- * String 待转化的字符串
- * @param booleanDef
- * boolean 当字符串为空或为null时返回的值
- * @return boolean 返回转化化的布尔值,只有当booleanstr为字符串“true”(忽略大小写)时才返回true,
- *
- * 如果在转化时发生异常(只有为null时),则返回缺省值booleanDef
- */
- public static boolean getBoolean(String booleanstr, boolean booleanDef) {
- if (null == booleanstr) {
- return booleanDef;
- }
- boolean booleanRetu = booleanDef;
- if ("true".equalsIgnoreCase(booleanstr.trim())) {
- booleanRetu = true;
- }
-
- return booleanRetu;
- }
-
- /**
- * 字符串转化为布尔型.
- * 只有当booleanstr为字符串“true”(忽略大小写)时才返回true,其它都返回false, 包括booleanstr为null
- *
- * @param booleanstr
- * String 待转化的字符串
- * @return boolean 返回转化化的布尔值,
- */
- public static boolean getBoolean(String booleanstr) {
- return getBoolean(booleanstr, false);
- }
-
- /**
- * 双精数字格式化,返回字符串
- *
- * @param db
- * double 待格式化的双精数字
- * @param fmt
- * String 格式化样式,参见类说明,
- * fmt非法时,db将按原样转化为字符串后返回。
- * @return String 格式化后的数字,以字符串方式返回
- */
- public static String getNumFormat(double db, String fmt) {
- String retu = "";
- if (null == fmt || "".equals(fmt.trim())) {
- return Double.toString(db);
- }
-
- try {
- DecimalFormat decimalformat = new DecimalFormat(fmt);
- retu = decimalformat.format(db);
- decimalformat = null;
- } catch (IllegalArgumentException iaex) {
- // ialog.error(ex.getMessage());
- retu = Double.toString(db);
- }
- return retu;
- }
-
- /**
- * 双精数字格式化,把入参中的双精数格式化为带两位小数的数字字符串
- *
- * @param db
- * double 待格式化的双精数字
- * @return String 格式化为两位小数的数字字符串
- */
- public static String getNumFormat(double db) {
- return getNumFormat(db, "0.00");
- }
-
- /**
- * 数字字符串格式化,返回字符串
- *
- * @param numStr
- * String 待格式化的数字字符串,
- * 如果numStr参数不是的数字则不进行格式化,按原样返回
- * @param fmt
- * String 格式化样式,参见类说明
- * fmt非法时,将把numStr按原样返回。
- * @return String 格式化后的字符串
- */
- public static String getNumFormat(String numStr, String fmt) {
- double db = getDouble(numStr, 0);
- return getNumFormat(db, fmt);
- }
-
- /**
- * 数字字符串格式化,把入参中的数字字符串格式化为带两位小数的数字字符串
- *
- * @param numStr
- * String 待格式化的数字字符串,
- * 如果numStr参数不是的数字则不进行格式化,按原样返回
- * @return String 格式化为两位小数的数字字符串
- */
- public static String getNumFormat(String numStr) {
- return getNumFormat(numStr, "0.00");
- }
-
- /**
- * 普通字符串转化为网页中可显示的,如回车转化为<br>.
- *
- * @param str
- * String 待转化的字符串
- * @return String 转化后的字符串
- */
- public static String htmlEncode(String str) {
- String retu = null;
- if (null == str || "".equals(str.trim())) {
- retu = str;
- } else {
- String html = str;
- //StringUtils tool = new StringUtils();
- html = replaceString(html, "&", "&");
- html = replaceString(html, "<", "<");
- html = replaceString(html, ">", ">");
- html = replaceString(html, "\r\n", "\n");
- html = replaceString(html, "\n", "
");
- html = replaceString(html, "\t", " ");
- html = replaceString(html, " ", " ");
- html = replaceString(html, "\"", """);
- retu = html;
- html = null;
- }
- return retu;
- }
-
- /**
- * 字符串替换,把str字符串中的所有oldStr子串替换为newStr字串
- *
- * @param sourceStr
- * String 将被替换的字符串,为null时不执行任何替换操作
- * @param oldStr
- * String 将被替换的子串,为null或为空字符串时不执行替换操作
- * @param newStr
- * String 将被替换成的子串,为null时不执行替换操作
- * @param isIgnoreCase
- * boolean 是否忽略大小写,true表忽略大小写,false表大小写敏感。
- * @return String 替换后的字符串
- */
- public static String replaceString(String sourceStr, String oldStr, String newStr, boolean isIgnoreCase) {
- if (sourceStr == null || oldStr == null || oldStr.equals("")) {
- return null;
- }
- String strRetStr = sourceStr;
- int pos = strRetStr.indexOf(oldStr);
- while (pos != -1) {
- strRetStr = strRetStr.substring(0, pos) + newStr + strRetStr.substring(pos + oldStr.length());
- pos = strRetStr.indexOf(oldStr, pos + newStr.length());
- }
- return strRetStr;
- }
-
- /**
- * 字符串替换,把str字符串中的所有oldStr子串替换为newStr字串(大小写敏感)
- *
- * @param sourceStr
- * String 将被替换的字符串,为null时不执行任何替换操作
- * @param oldStr
- * String 将被替换的子串,为null或为空字符串时不执行替换操作
- * @param newStr
- * String 将被替换成的子串,为null时不执行替换操作
- * @return String 替换后的字符串
- */
- public static String replaceString(String sourceStr, String oldStr, String newStr) {
- return replaceString(sourceStr, oldStr, newStr, false);
- }
-
- /**
- * 字符串按指定分隔符分解为一个数组(大小写敏感).
- * 例子:
- * String[] array = StringUtils.splictString("AA/BBB/CCC//DDDD//" , "/" );
- *
- * 结果:
- * array[0]="AA" array[1]="BBB" array[2]="CCC" array[3]="DDDD"
- *
- * @param sourceStr
- * String 源字符串
- * @param splitStr
- * String 分隔符
- * @param isTrim
- * boolean
- * @return String[] 字符串数组,
- * 源字符串为null或为空字符串时,返回长度为1的数组,元素值为空字符串
- * 分隔符为null或为空字符串时,返回长度为1的数组,元素值为源字符串
- */
- public static String[] splitString(String sourceStr, String splitStr, boolean isTrim) {
- String newSourceStr = sourceStr;
- String newSplitStr = splitStr;
-
- if (newSourceStr == null || newSplitStr == null) {
- return null;
- }
-
- if (isTrim) // 去掉开始和结束的分隔符
- {
- // 开头的间隔符去掉
- while (newSourceStr.indexOf(newSplitStr) == 0) {
- newSourceStr = newSourceStr.substring(newSplitStr.length());
- }
-
- // 尾部的间隔符去掉
- while (newSourceStr.indexOf(newSplitStr, newSourceStr.length() - newSplitStr.length()) > -1) {
- newSourceStr = newSourceStr.substring(0, sourceStr.length() - newSplitStr.length());
- }
- }
- if (newSourceStr.equals("") || newSplitStr.equals("")) {
- return null;
- }
- return splitString(newSourceStr, newSplitStr);
- }
-
- /**
- * 功能简述 :把字符串放入一个数组
- *
- * @param sourceStr
- * 要被放入的字符串
- * @param splitStr
- * 间隔符
- * @return 转换后的数组,sourceStr或splitStr = null 或 "" 返回null
- */
- public static String[] splitString(String sourceStr, String splitStr) {
- String newSourceStr = sourceStr;
- String newSplitStr = splitStr;
-
- if (newSourceStr == null || newSplitStr == null) {
- return null;
- }
- if (newSourceStr.equals("") || newSplitStr.equals("")) {
- return null;
- }
- int intArraySize = subStringCount(newSourceStr, newSplitStr);
- // 如果为-1则返回
- if (intArraySize == -1) {
- return null;
- }
-
- newSourceStr += newSplitStr;
-
- String[] strRetArr = new String[intArraySize + 1];
- int intpos = newSourceStr.indexOf(newSplitStr);
- int intArrayPos = 0;
- while (intpos != -1) {
- strRetArr[intArrayPos++] = newSourceStr.substring(0, intpos);
- newSourceStr = newSourceStr.substring(intpos + newSplitStr.length());
- intpos = newSourceStr.indexOf(newSplitStr);
- }
-
- return strRetArr;
- }
-
- /**
- * 功能简述 :把字符串放入一个数组
- * @param sourceStr
- * 要被放入的字符串
- * @param splitStr
- * 间隔符
- * @return 转换后的List,sourceStr或splitStr = null 或 "" 返回元素个数为0的List
- */
- public static List splitString2List(String sourceStr, String splitStr) {
- String[] tempArr = splitString(sourceStr, splitStr);
- List resultList = new ArrayList();
- if (tempArr != null) {
- for (int i = 0; i < tempArr.length; i++) {
- resultList.add(tempArr[i]);
- }
- }
- return resultList;
- }
-
- /**
- * 功能简述 :把字符串放入一个数组
- *
- * @param sourceStr
- * 要被放入的字符串
- * @param splitStr
- * 间隔符
- * @param isTrim
- * boolean
- * @return 转换后的List,sourceStr或splitStr = null 或 "" 返回元素个数为0的List
- */
- public static List splitString2List(String sourceStr, String splitStr, boolean isTrim) {
- String[] tempArr = splitString(sourceStr, splitStr, isTrim);
- List resultList = new ArrayList();
- if (tempArr != null) {
- for (int i = 0; i < tempArr.length; i++) {
- resultList.add(tempArr[i]);
- }
- }
- return resultList;
- }
-
- /**
- * 功能简述 :在一个字符串中查找字符串个数(不区分大小写)
- *
- * @param sourceStr
- * 要被查询的字符串
- * @param subStr
- * 要查找的字符串
- * @return 找到的个数
- */
- public static int subStringCount(String sourceStr, String subStr) {
- // 如果是空指针则返回-1
- if (sourceStr == null || subStr == null) {
- return -1;
- }
- if (sourceStr.equals("") || subStr.equals("")) {
- return -1;
- }
- int result = 0;
- int intPos = sourceStr.toUpperCase().indexOf(subStr.toUpperCase());
- while (intPos != -1) {
- result++;
- intPos = sourceStr.toUpperCase().indexOf(subStr.toUpperCase(), intPos + subStr.length());
- }
-
- return result;
- }
-
- /**
- * 用指定的分隔符把字符串数组合并成一个字符串. 数组为null或长度为0时返回空字符串
- * 例子:
- * String[] array = {"1",null,"","3"};
- * StringUtils.arrayToString(array,"|");
- * 返回结果:1|||3
- *
- * @param array
- * String[] 待合并的数组
- * @param splitStr
- * String 数组各元素合并后,它们之间的分隔符,为null时用空字符串代替
- * @return String 合并后的字符串
- */
- public static String arrayToString(String[] array, String splitStr) {
- if (null == array || 0 == array.length) {
- return "";
- }
- String newSplitStr = splitStr;
- if (null == newSplitStr) {
- newSplitStr = "";
- }
- StringBuffer strBuf = new StringBuffer("");
- int len = array.length;
- for (int i = 0; i < len - 1; i++) {
- strBuf.append((null == array[i]) ? "" : array[i]).append(newSplitStr);
- }
- strBuf.append((null == array[len - 1]) ? "" : array[len - 1]);
-
- return strBuf.toString();
- }
-
- /**
- * 用默认分隔符 | 把字符串数组合并成一个字符串. 数组为null或长度为0时返回空字符串
- *
- * @param array
- * String[] 待合并的数组
- * @return String 合并后的字符串
- */
- public static String arrayToString(String[] array) {
- return arrayToString(array, "|");
- }
-
- /**
- * 判断字符串是否为null或为空字符串(包括只含空格的字符串)
- *
- * @param str
- * String 待检查的字符串
- * @return boolean 如果为null或空字符串(包括只含空格的字符串)则返回true,否则返回false
- */
- public static boolean isNullBlank(String str) {
- return (null == str || "".equals(str.trim())) ? true : false;
- }
-
- /**
- * 从字符串中得到指定位置的子串(按分隔符分隔,大小写敏感).
- * 例子:
- * StringUtils.decomposeString("a||b|c|d","|",1);
- * StringUtils.decomposeString("a||b|c|d","|",2);
- * StringUtils.decomposeString("a||b|c|d","|",3);
- * StringUtils.decomposeString("a||b|c|d","|",4);
- * StringUtils.decomposeString("a||b|c|d","|",5);
- * 返回结果:
- * a,空字符串,b,c,d
- *
- * @param sourceStr
- * String 源字符串
- * @param splitStr
- * String 分隔符
- * @param pos
- * int 位置,从1开始
- * @return String 返回指定位置的子串。
- * 当分隔符为null或为空字符串时返回源字符串;
- * 当源字符串为null或为空字符串时返回空字符串;
- * 当指定位置小于1或大于分隔符个数-1时返回空字符串。
- */
- public static String decomposeString(String sourceStr, String splitStr, int pos) {
- String retu = "";
- String newSourceStr = sourceStr;
- if (null == newSourceStr || "".equals(newSourceStr.trim())) {
- return "";
- }
-
- if (pos <= 0) {
- return "";
- }
-
- if (null == splitStr || "".equals(splitStr)) {
- return sourceStr;
- }
-
- newSourceStr = newSourceStr + splitStr;
- String tmpStr = newSourceStr;
-
- int splitLen = splitStr.length();
- int tmpLen = tmpStr.length();
-
- for (int i = 0; i < pos - 1; i++) {
- int tmpPosi = tmpStr.indexOf(splitStr);
- if (tmpPosi < 0 || tmpPosi + splitLen >= tmpLen) {
- tmpStr = splitStr;
- break;
- } else {
- tmpStr = tmpStr.substring(tmpPosi + splitLen);
- }
- }
- retu = tmpStr.substring(0, tmpStr.indexOf(splitStr));
- return retu;
- }
-
- /**
- * 从字符串中得到指定位置的子串(按分隔符 | 分隔).
- *
- * @param sourceStr
- * String 源字符串
- * @param pos
- * int 位置,从1开始
- * @return String 返回指定位置的子串。
- * 当分隔符为null或为空字符串时返回源字符串;
- * 当源字符串为null或为空字符串时返回空字符串;
- * 当指定位置小于1或大于分隔符个数-1时返回空字符串。
- */
- public static String decomposeString(String sourceStr, int pos) {
- return decomposeString(sourceStr, "|", pos);
- }
-
- /**
- * 删除指定的前导、后导子串(大小写敏感).
- * 例子:
- * StringUtils.trim("and and username = '123' and password = 'abc' and
- * ","and ");
- * 结果:username = '123' and password = 'abc'
- *
- * @param sourceStr
- * String 待删除的字符串
- * @param removeChar
- * char 子串
- * @return String 处理后的字符串
- */
- public static String trim(String sourceStr, char removeChar) {
- if (sourceStr == null) {
- return null;
- }
- String newSourceStr = sourceStr;
-
- newSourceStr = newSourceStr.trim();
- int loIntBegin = 0;
- int loIntEnd = 0;
- int loIntLen = newSourceStr.length();
- for (int i = 0; i < loIntLen; i++) {
- if (newSourceStr.charAt(i) == removeChar) {
- loIntBegin++;
- } else {
- break;
- }
- }
- for (int i = 0; i < loIntLen; i++) {
- if (newSourceStr.charAt(loIntLen - 1 - i) == removeChar) {
- loIntEnd++;
- } else {
- break;
- }
- }
- return newSourceStr.substring(loIntBegin, loIntLen - loIntEnd);
- }
-
- /**
- * 删除指定的前导、后导子串(大小写敏感).
- * 例子:
- * StringUtils.trim("and and username = '123' and password = 'abc' and
- * ","and ");
- * 结果:username = '123' and password = 'abc'
- *
- * @param sourceStr
- * String 待删除的字符串
- * @param removeChar
- * char 子串
- * @param end
- * true 只trim末尾,false 只trim头部
- * @return String 处理后的字符串
- */
- public static String trim(String sourceStr, char removeChar, boolean end) {
- if (sourceStr == null) {
- return null;
- }
- String newSourceStr = sourceStr;
-
- newSourceStr = newSourceStr.trim();
- int loIntBegin = 0;
- int loIntEnd = 0;
- int loIntLen = newSourceStr.length();
- for (int i = 0; i < loIntLen; i++) {
- if (newSourceStr.charAt(i) == removeChar) {
- loIntBegin++;
- } else {
- break;
- }
- }
- for (int i = 0; i < loIntLen; i++) {
- if (newSourceStr.charAt(loIntLen - 1 - i) == removeChar) {
- loIntEnd++;
- } else {
- break;
- }
- }
- if (end) {
- return newSourceStr.substring(0, loIntLen - loIntEnd);
- } else {
- return newSourceStr.substring(loIntBegin);
- }
- }
-
- /**
- *
- * 将字符串截短到特定的长度,一个中文是两个字节的长度,但是是1个字符的长度,例:
- * 1)truncate("巨龙软件公司",2,CHAR_LEN) = "巨龙"
- * 2)truncate("巨龙软件公司",2,BYTE_LEN) = "巨"
- * 3)truncate("dragonsoft",2,CHAR_LEN) = "dr"
- * 4)truncate("dragonsoft",2,BYTE_LEN) = "dr"
- *
- *
- * @param str
- * String 需要截的字符串
- * @param len
- * int 截到的目标长度
- * @param lenType
- * int 长度类型,字符长度{@link CHAR_LEN},字符长度{@link BYTE_LEN}
- * @return String
- */
- public static String truncate(String str, int len, int lenType) {
- if (str == null) {
- return str;
- }
- // 字符长度
- if (lenType == CHAR_LEN) {
- if (str.length() <= len) {
- return str;
- } else {
- return str.substring(0, len);
- }
- } else // 字节长度
- {
- StringBuffer sb = new StringBuffer();
- int temp = 0;
-
- for (int i = 0; i < str.length(); i++) {
- if (i < len) // 是否到指定的长度
- {
- temp = ("" + str.charAt(i)).getBytes().length;
- if (i + temp <= len) {
- sb.append(str.charAt(i));
- } else {
- break;
- }
- } else {
- break;
- }
- }
- return sb.toString();
- }
- }
-
- /**
- * 从源字符串中从第一个字符开始取出给定长度的字串.
- * 源字符串长度大于len时,尾巴追加一个appendStr串
- *
- * @param sourceStr
- * String 源字符串
- * @param len
- * int 取出的长度
- * @param appendStr
- * String 追加的字符串(常用的appendStr为...)
- * @return String 取出的子串
- */
- public static String substring(String sourceStr, int len, String appendStr) {
- if (null == sourceStr || "".equals(sourceStr)) {
- return sourceStr;
- }
- if (len <= 0) {
- return "";
- }
-
- String newappendStr = appendStr;
- if (null == newappendStr) {
- newappendStr = "";
- }
-
- int sourceLen = sourceStr.length();
- if (len >= sourceLen) {
- return sourceStr;
- } else {
- return sourceStr.substring(0, len) + newappendStr;
- }
- }
-
- /**
- * 产生指定长度随机字符串(包括字母及数字).
- *
- * @param length
- * int 随机字符串长度
- * @return String 随机字符串
- */
- public static String random(int length) {
- String retu = "";
- int d1;
- int d2;
- char[] letters = initLetters();
- //int[] numbers = initNumbers();
-
- for (int i = 0; i < length; i++) {
- // d1 = ((int) (Math.random() * 10) % 2);
- d1 = (int) (Math.random() * 10) % 2;
-
- if (d1 == 0) { // use a letter
- // d2 = ((int) (Math.random() * 100) % 52);
- d2 = (int) (Math.random() * 100) % 52;
- retu += letters[d2];
- } else if (d1 == 1) { // use a number
- retu += (int) (Math.random() * 10);
- }
- }
- return retu;
- }
-
- /**
- * 产生纯字母的随机字符串
- *
- * @param length
- * int 随机字符串长度
- * @return String 随机字符串
- */
- public static String randomString(int length) {
- String retu = "";
- int d2;
- char[] letters = initLetters();
-
- for (int i = 0; i < length; i++) {
- // d2 = ((int) (Math.random() * 100) % 52);
- d2 = (int) (Math.random() * 100) % 52;
- retu += letters[d2];
- }
- return retu;
- }
-
- /**
- * 产生纯数字随机字符串
- *
- * @param length
- * int 随机字符串长度
- * @return String 随机字符串
- */
- public static String randomNumber(int length) {
- String retu = "";
- //int[] numbers = initNumbers();
-
- for (int i = 0; i < length; i++) {
- retu += (int) (Math.random() * 10);
- }
- return retu;
- }
-
- /**
- * 内部方法,产生字母数组
- *
- * @return char[]
- */
- private static char[] initLetters() {
- char[] ca = new char[52];
- for (int i = 0; i < 26; i++) {
- ca[i] = (char) (65 + i);
- }
- for (int i = 26; i < 52; i++) {
- ca[i] = (char) (71 + i);
- }
- return ca;
- }
-
- /**
- * 内部方法,产生数字数组
- *
- * @return int[]
- */
- /*private static int[] initNumbers() {
- int[] na = new int[10];
- for (int i = 0; i < 10; i++) {
- na[i] = i;
- }
- return na;
- }*/
-
- /**
- * 对字符串进行加减密处理.
- *
- * @param source
- * String 待加减密处理的字符串
- * @param flag
- * boolean true表进行加密,false表进行减密
- * @return String 处理后的字符串.
- * source为空则返回原字符串source,
- * 如果source中含有中文字符则对这一中文字符不处理.
- */
- public static String encrypt(String source, boolean flag) {
- if (null == source || "".equals(source.trim())) {
- return source;
- }
- String lsKEY1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz~!@#$%^&*(),.;[]{}";
- String lsKEY2 = "&*()AD;[BFLCGH]{PQ}EI!JKRYZ1MSTXNO23UV,.Wcd45ef6lm7g@h0a#$nij8ob%^ptvz9ku~qrswxy";
-
- char[] chSource = source.toCharArray();
-
- StringBuffer strBuf = new StringBuffer(chSource.length);
-
- int pos;
- int len = chSource.length;
- for (int i = 0; i < len; i++) {
- if (flag) { // 加密
- pos = lsKEY1.indexOf(chSource[i]);
- if (pos >= 0) {
- strBuf.append(lsKEY2.substring(pos, pos + 1));
- } else {
- strBuf.append(chSource[i]);
- }
- } else { // 减密
- pos = lsKEY2.indexOf(chSource[i]);
- if (pos >= 0) {
- strBuf.append(lsKEY1.substring(pos, pos + 1));
- } else {
- strBuf.append(chSource[i]);
- }
- }
- }
-
- return strBuf.toString();
-
- }
-
- /**
- * 将null字符串转换为空串,方便HTML的显示
- *
- * @param sourceStr
- * 待处理的字符串
- * @return String 处理的的字符串
- */
- public static String toVisualString(String sourceStr) {
- if (sourceStr == null || sourceStr.equals("")) {
- return "";
- } else {
- return sourceStr;
- }
- }
-
- /**
- * 将字段填充到指定的长度
- *
- * @param sourceStr
- * String 操作字符串
- * @param length
- * int 指定长度
- * @param withChar
- * char 填充的字符
- * @param isPadToEnd
- * boolean 是否填充在字符的尾部 true :是 ,false:填充在头部
- * @return String
- */
- public static String pad(String sourceStr, int length, char withChar, boolean isPadToEnd) {
- if (sourceStr == null) {
- return null;
- }
- if (sourceStr.length() >= length) {
- return sourceStr;
- }
-
- StringBuffer sb = new StringBuffer(sourceStr);
- for (int i = 0; i < length - sourceStr.length(); i++) {
- if (isPadToEnd) {
- sb.append(withChar);
- } else {
- sb.insert(0, withChar);
- }
- }
- return sb.toString();
-
- }
-
- /**
- * 首字母大写
- * @return
- */
- public static String capToUpper(String str){
- if (str == null) {
- return null;
- }
- if(str.length()<0){
- return "";
- }
- return str.substring(0,1).toUpperCase()+str.substring(1);
- }
- /**
- * main
- *
- * @param args
- * String[]
- * @author:Administrator
- */
-
-
- /**
- * 将身份证号码转换为18位
- *
- * @param xIdCode
- * String
- * @return String
- */
- public static String idTo18(String xIdCode) {
- return IdentificationNumberUtils.id15ToId18(xIdCode);
- }
-
- /**
- * 将身份证号转换为15位
- *
- * @param xIdCode
- * String
- * @return String
- */
- public static String idTo15(String xIdCode) {
- return IdentificationNumberUtils.id18ToId15(xIdCode);
- }
-
- /**
- * getIdCheckBit
- *
- * @param xId
- * id
- * @return String
- * @author:Administrator
- */
- private static String getIdCheckBit(String xId) {
- return IdentificationNumberUtils.getIdCheckBit(xId);
- }
-
- /**
- * MD5加密算法
- *
- * @更新时间:Apr 22, 2008
- * @更新作者:Ryan Wong
- * @param s
- * String
- * @return String
- */
- public static String md5(String s) {
- char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
- try {
- byte[] strTemp = s.getBytes();
- MessageDigest mdTemp = MessageDigest.getInstance("MD5");
- mdTemp.update(strTemp);
- byte[] md = mdTemp.digest();
- int j = md.length;
- char[] str = new char[j * 2];
- int k = 0;
- for (int i = 0; i < j; i++) {
- byte byte0 = md[i];
- str[k++] = hexDigits[byte0 >>> 4 & 0xf];
- str[k++] = hexDigits[byte0 & 0xf];
- }
- return new String(str);
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * 取得字符串中间的几位
- *
- * @更新时间:Apr 22, 2008
- * @更新作者:Ryan Wong
- * @param strsource
- * str_source
- * @param midlength
- * midlength
- * @return String
- */
- public static String getMidString(String strsource, int midlength) {
- String strMid = "";
- int length = strsource.length();
- if (midlength > length) {
- return null;
- }
- if (length % 2 == 0) {
- if (midlength % 2 != 0) {
- return null;
- }
- strMid = strsource.substring(length / 2 - midlength / 2, length / 2 + midlength / 2);
-
- } else {
- if (midlength % 2 == 0) {
- return null;
- }
- strMid = strsource.substring((length - 1) / 2 - (midlength - 1) / 2, (length - 1) / 2
- + (midlength - 1) / 2 + 1);
-
- }
- return strMid;
- }
-
- public static boolean isNotBlank(String value){
- return (value!=null) && !value.equals("");
- }
-
- public static boolean isBlank(String value){
- return (value==null) || value.equals("");
- }
- /**
- * getStringToInt
- * @param value String
- * @param defaultInt int
- * @return int
- * @author:Administrator
- */
- public static int getStringToInt(String value, int defaultInt) {
- int i = defaultInt;
- if (isNotBlank(value) ) {
- Integer intObject = getStringByInt(value);
- if(intObject!=null){
- return intObject.intValue();
- }
- }
- return i;
- }
-
- /**
- * 字符串替换
- * @param value String
- * @param replaceChar String
- * @return String
- * @author:Administrator
- */
- public static String replaceStr(String value, String replaceChar) {
- String returnValue = "";
- if (isNotBlank(value)) {
- returnValue = value.replaceAll("[" + replaceChar + "]", "");
- }
- return returnValue;
- }
-
- /**
- * getNullByString
- * @param value String
- * @return String
- * @author:Administrator
- */
- public static String getNullByString(String value) {
- String values = "";
- if (isNotBlank(value)) {
- values = value.trim();
- }
- return values;
- }
-
- /**
- * getNullByString
- * @param value String
- * @param defaultValue String
- * @return String
- * @author:Administrator
- */
- public static String getNullByString(String value, String defaultValue) {
- String values = "";
- if (isNotBlank(value)) {
- values = value;
- } else {
- values = defaultValue;
- }
- return values;
- }
-
- /**
- * getStringByInt
- * @param value String
- * @return Integer
- * @author:Administrator
- */
- public static Integer getStringByInt(String value) {
- Integer intValue = null;
- if (isNotBlank(value) ) {
- try{
- intValue = Integer.valueOf(value);
- } catch(NumberFormatException ex){
-
- }
- }
- return intValue;
- }
-
- /**
- * getStringByMaxLen
- * @param value String
- * @param maxLen int
- * @return String
- * @author:Administrator
- */
- public static String getStringByMaxLen(String value, int maxLen) {
- String returnValue = "";
- if (isNotBlank(value)) {
- returnValue = value.length() > maxLen ? value.substring(0, maxLen) : value;
- }
- return returnValue;
- }
-
- /**
- * getCheckBoxValueByStr
- * @param value String
- * @return String
- * @author:Administrator
- */
- public static String getCheckBoxValueByStr(String value) {
- String returnValue = "";
- if (isNotBlank(value)) {
- if (value.equals("on")) {
- returnValue = "1";
- } else {
- returnValue = "0";
- }
- }
- return returnValue;
- }
-
- /**
- * 删除字符两端的空字符串
- *
- * @author cailj
- * @param str
- * @return
- */
- public static String trim(String str) {
- return str != null ? str.trim() : null;
- }
-
- /**
- * 进行字符规格化(全角转半角,大写转小写处理)
- * @param input
- * @return char
- */
- public static char[] regularize(char[] input){
-
- for(int i = 0; i < input.length; i ++){
- input[i] = regularize(input[i]);
- }
- return input;
- }
-
- /**
- * 进行字符规格化(全角转半角,大写转小写处理)
- * @param input
- * @return char
- */
- public static char regularize(char input){
- if (input == 12288) {
- input = (char) 32;
-
- }else if (input > 65280 && input < 65375) {
- input = (char) (input - 65248);
-
- }else if (input >= 'A' && input <= 'Z') {
- input |= 32;
- }
- return input;
- }
-
- /**
- * 进行字符规格化(全角转半角,大写转小写处理)
- * @param input
- * @return char
- */
- public static String regularize(String input){
- if(StringUtils.isBlank(input)) return "";
-
- char[] inputChars = input.toCharArray();
- for(int i = 0; i < inputChars.length; i ++){
- inputChars[i] = regularize(inputChars[i]);
- }
- return new String(inputChars);
- }
-
- /**
- * 字符反转
- * eg: reverse(abc) = cba
- * @param str
- * @return
- */
- public static String reverse(String str) {
- char[] chrs = str.toCharArray();
- int n = chrs.length - 1;
- for (int j = (n-1) >> 1; j >= 0; --j) {
- char temp = chrs[j];
- char temp2 = chrs[n - j];
- chrs[j] = temp2;
- chrs[n - j] = temp;
- }
- return new String(chrs, 0, chrs.length);
- }
- /**
- * 字符串是否是 数字类型
- * @param str
- * @return
- */
- public static boolean isNumber(String str){
-
- if(isInteger(str)||isFloat(str)){
- return true;
- }else{
- return false;
- }
-
- }
-
- /**
- * 判断字符串是否为浮点型
- * @param str
- * @return
- */
- public static boolean isFloat(String str){
-
- if(StringUtils.isNullBlank(str))return false;
-
- Pattern pattern= Pattern.compile("^[-\\+]?\\d+\\.{0,1}[\\d]+$");
- return pattern.matcher(str).matches();
- }
-
- /**
- * 判断字符串是否是整数
- * @param str
- * @return
- */
- public static boolean isInteger(String str){
-
- if(StringUtils.isNullBlank(str))return false;
-
- Pattern pattern = Pattern.compile("^[-\\+]?[\\d]+$");
- return pattern.matcher(str).matches();
- }
-
- /**
- * 忽略正则关键字
- * @param keyword 正在表达式关键字 例如"\t","\d","*"等
- * @return 返回正则表达式
- */
- public static String ignoreRegexKeyword(String keyword){
- return "\\Q"+keyword+"\\E";
- }
-
- /**
- *
- * @param str
- * @param character
- * @return
- */
- public static String removeLastCharacter(String str, String character){
- if(str==null||str.length()==0){
- return str;
- }
- int en=-1;
- if((en=str.lastIndexOf(character))>=0&&(en+character.length()==str.length())){
- return str.substring(0,en);
- }else{
- return str;
- }
- }
- public static String ignoreKeyword(String txt){
- if(txt==null){
- return null;
- }
- String str=ignoreKeyword(txt,"n");
- str=ignoreKeyword(str,"t");
- return str;
- }
- public static String ignoreKeyword(Object object){
- return ignoreKeyword(String.valueOf(object));
- }
- public static String ignoreKeyword(String txt, String keyWord){
- if(txt==null){
- return null;
- }
-
- if(txt.length()==0||isBlank(keyWord)){
- return txt;
- }
- return txt.replaceAll("\\"+keyWord,"\\\\"+keyWord);
- }
-
-
-
-
- /**
- * 下划线转驼峰法
- * @param line 源字符串
- * @param smallCamel 大小驼峰,是否为小驼峰
- * @return 转换后的字符串
- */
- public static String underline2Camel(String line, boolean smallCamel){
- if(line==null||"".equals(line)){
- return "";
- }
- StringBuffer sb=new StringBuffer();
- Pattern pattern= Pattern.compile("([A-Za-z\\d]+)(_)?");
- Matcher matcher=pattern.matcher(line);
- while(matcher.find()){
- String word=matcher.group();
- sb.append(smallCamel&&matcher.start()==0? Character.toLowerCase(word.charAt(0)): Character.toUpperCase(word.charAt(0)));
- int index=word.lastIndexOf('_');
- if(index>0){
- sb.append(word.substring(1, index).toLowerCase());
- }else{
- sb.append(word.substring(1).toLowerCase());
- }
- }
- return sb.toString();
- }
- /**
- * 驼峰法转下划线
- * @param line 源字符串
- * @return 转换后的字符串
- */
- public static String camel2Underline(String line){
- if(line==null||"".equals(line)){
- return "";
- }
- line= String.valueOf(line.charAt(0)).toUpperCase().concat(line.substring(1));
- StringBuffer sb=new StringBuffer();
- Pattern pattern= Pattern.compile("[A-Z]([a-z\\d]+)?");
- Matcher matcher=pattern.matcher(line);
- while(matcher.find()){
- String word=matcher.group();
- sb.append(word.toUpperCase());
- sb.append(matcher.end()==line.length()?"":"_");
- }
- return sb.toString();
- }
-
-
- //IOS端version比较大小 param1>param2 返回 1 =返回0 <返回-1
- public static int compareVersion(String versionClient,String versionServe){
- //版本长度
- String[] cArr = versionClient.split("\\.");
- String[] sArr = versionServe.split("\\.");
- int diff = cArr.length-sArr.length;
- int result = 0;
-
- //补齐长度
- if(diff>0){
- sArr = align(sArr,cArr,diff);
- }else{
- cArr = align(cArr,sArr,-diff);
- }
-
- for(int i=0;i --描述说明--
- *
- *
- * --样例--
- * Assert obj = new Assert();
- * obj.method();
- *
- * JDK版本:JDK1.4
- * @author 李炜
- */
-public abstract class Validator {
- /**
- * 判断表达式是否为true
- * @param expression 要判断的表达式
- */
- public static boolean isTrue(boolean expression) {
- return expression;
- }
-
-
- /**
- * 判断表达式是否为0
- * @param expression 要判断的表达式
- */
- public static boolean isZero(int num) {
- return num == 0;
- }
-
-
- /**
- * 判断表达式是否为非空
- * @param expression 要判断的表达式
- */
- public static boolean notZero(int num, String message) {
- return num == 0;
- }
-
-
-
- /**
- * 判断表达式是否为空
- * @param expression 要判断的表达式
- */
- public static boolean isNull(Object object) {
- return object == null;
- }
-
-
-
- /**
- * 判断表达式是否为非空
- * @param expression 要判断的表达式
- */
- public static boolean notNull(Object object) {
- return object != null;
- }
-
- /**
- * 判断字符串长度是否大于指定长度
- * @param text 字符串
- * @param size 指定长度
- */
- public static boolean gtLength(String text,int size){
- return notNull(text) && text.length() > size;
- }
-
-
- public static boolean gtLength(Collection collection,int size){
- return notNull(collection) && collection.size() > size;
- }
-
- public static boolean gtLength(Map collection,int size){
- return notNull(collection) && collection.size() > size;
- }
-
-
- /**
- * 判断字符串长度是否小于指定长度
- * @param text 字符串
- * @param size 指定长度
- */
- public static boolean ltLength(String text,int size){
- return notNull(text) && text.length() < size;
- }
-
- public static boolean ltLength(Collection collection,int size){
- return notNull(collection) && collection.size()< size;
- }
-
- public static boolean ltLength(Map collection,int size){
- return notNull(collection) && collection.size()< size;
- }
-
- /**
- * 判断text是否为有内容字符串
- * @param text 要判断的字符串
- */
- public static boolean hasLength(String text) {
- return notNull(text) && gtLength(text, 0);
- }
-
- public static boolean hasLength(Object[] arrays){
- return notNull(arrays) && arrays.length > 0;
- }
-
- /**
- * 判断text是否为有内容字符串
- * @param text 要判断的字符串
- */
- public static boolean hasLength(StringBuffer text) {
- return notNull(text) && gtLength(text.toString(), 0);
- }
-
-
- /**
- * 判断text是否为有内容,如果都是空白字符也将抛异常
- * @param text 要判断的字符串
- */
- public static boolean hasText(String text) {
- return notNull(text) && gtLength(text.trim(), 0);
- }
-
- public static boolean hasText(StringBuffer sb){
- return notNull(sb) && gtLength(sb.toString().trim(), 0);
- }
-
- /**
- * 判断数组是否大于指定长度
- * @param array 数组
- * @param size 长度
- */
- public static boolean gtSize(Object[] array,int size){
- return notNull(array) && array.length > size;
- }
-
- /**
- * 判断数组是否小于指定长度
- * @param array 数组
- * @param size 长度
- */
- public static boolean ltSize(Object[] array,int size){
- return notNull(array) && array.length < size;
- }
-
-
- /**
- * 判断数组是否为空数组
- * @param array 要判断的数租
- */
- public static boolean notEmpty(Object[] array) {
- return notNull(array) && gtSize(array, 0);
- }
-
-
- /**
- * 判断集合是否为空集合对象
- * @param array 要判断的集合对象
- */
- public static boolean notEmpty(Collection collection) {
- return notNull(collection) && !collection.isEmpty();
- }
-
-
-
-
- /**
- * 判断Map是否为空对象,有默认消息
- * @param array 要判断的Map
- * @throws IllegalArgumentException 如果是空集合对象或者null
- */
- public static boolean notEmpty(Map map) {
- return notNull(map) && !map.isEmpty();
- }
-
-
- /**
- *判断指定的 Object 是否与此 type 所表示的对象赋值兼容
- * @param 用于检查的Class对象
- * @param obj 用于检查的对象
- */
- public static boolean isInstanceOf(Class type, Object obj, String message) {
- return notNull(type) && type.isInstance(obj);
- }
-
-
- /**
- * 判断两个类型是否相同
- * @param type1
- * @param type2
- */
- public static boolean isSameType(Class type1,Class type2,String message){
- return notNull(type1) && notNull(type2) && type1.equals(type2);
- }
-
-
- /**
- * 判断一个class对象调用newInstance,是否成功
- * @param type
- */
- public static boolean isNewInstanceOf(Class type){
- if(notNull(type)){
- try {
- type.newInstance();
- return true;
- } catch (Exception e) {
- return false;
- }
- }else{
- return false;
- }
- }
-
-
- /**
- * 判断superType.isAssignableFrom(subType)是否为true
- * @param superType 超类
- * @param subType 子类
- */
- public static boolean isAssignable(Class superType, Class subType) {
- return notNull(superType) && notNull(subType) && superType.isAssignableFrom(subType);
- }
-
-
-
-
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/assertion/Assert.java b/luqj-common/src/main/java/com/luqj/util/assertion/Assert.java
deleted file mode 100644
index b4ccd9a..0000000
--- a/luqj-common/src/main/java/com/luqj/util/assertion/Assert.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/**
-* 版权所有:厦门市巨龙软件工程有限公司
-* Copyright 2010 Xiamen Dragon Software Eng. Co. Ltd.
-* All right reserved.
-*====================================================
-* 文件名称: Assert.java
-* 修订记录:
-* No 日期 作者(操作:具体内容)
-* 1. 2010-8-6 李炜(创建:创建文件)
-*====================================================
-* 类描述:(说明未实现或其它不应生成javadoc的内容)
-*
-*/
-package com.luqj.util.assertion;
-
-
-import com.luqj.util.log.LogUtil;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- *Assert
- *
- * --描述说明--
- *
- *
- * --样例--
- * Assert obj = new Assert();
- * obj.method();
- *
- * JDK版本:JDK1.4
- * @author 李炜
- */
-public abstract class Assert {
- /**
- * 断言表达式是否为true
- * @param expression 要断言的表达式
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不是true
- */
- public static void isTrue(boolean expression, String message) {
-
- if (!expression) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言表达式是否为true,有默认消息
- * @param expression 要断言的表达式
- * @throws IllegalArgumentException 如果不是true
- */
- public static void isTrue(boolean expression) {
- isTrue(expression, "[断言失败] - 参数必须是 true");
- }
-
- /**
- * 断言表达式是否为0
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不是空
- */
- public static void isZero(long num, String message) {
- if (num != 0) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言表达式是否为空,有默认消息
- * @throws IllegalArgumentException 如果不是空
- */
- public static void isZero(long num) {
- isZero(num, "[断言失败] - 参数值必须是0");
- }
-
- /**
- * 断言表达式是否为非空
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不是非空
- */
- public static void notZero(long num, String message) {
- if (num == 0) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言表达式是否为非空,有默认消息
- * @throws IllegalArgumentException 如果不是非空
- */
- public static void notZero(long num) {
- notZero(num, "[断言失败] - 参数必须非0");
- }
-
-
- /**
- * 断言表达式是否为空
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不是空
- */
- public static void isNull(Object object, String message) {
- if (object != null) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言表达式是否为空,有默认消息
- * @throws IllegalArgumentException 如果不是空
- */
- public static void isNull(Object object) {
- isNull(object, "[断言失败] - 参数必须是 null");
- }
-
-
-
- /**
- * 断言表达式是否为非空
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不是非空
- */
- public static void notNull(Object object, String message) {
- if (object == null) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言表达式是否为非空,有默认消息
- * @throws IllegalArgumentException 如果不是非空
- */
- public static void notNull(Object object) {
- notNull(object, "[断言失败] - 参数必须是非空对象");
- }
-
-
-
- /**
- * 断言表达式是否为非空,有默认消息
- * @throws IllegalArgumentException 如果不是非空
- */
- public static void notNull(Object... objects) {
- for (int i = 0; i < objects.length; i++) {
- notNull(objects[i], "[断言失败] - 参数["+i+"]必须是非空对象");
- }
- }
-
- /**
- * 断言text是否为有内容字符串
- * @param text 要断言的字符串
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果是空串或null对象
- */
- public static void hasLength(String text, String message) {
- if (text == null || text.length() == 0) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言text是否为有内容字符串,有默认消息
- * @param text 要断言的字符串
- * @throws IllegalArgumentException 如果是空串或null对象
- */
- public static void hasLength(String text) {
- hasLength(text,
- "[断言失败] - 参数必须是非空字符串");
- }
-
- /**
- * 断言text是否为有内容,如果都是空白字符也将抛异常
- * @param text 要断言的字符串
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果是空串或null对象,或所有内容为空白字符
- */
- public static void hasText(String text, String message) {
- if (text == null || text.trim().length() == 0) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言text是否为有内容,如果都是空白字符也将抛异常,有默认消息
- * @param text 要断言的字符串
- * @throws IllegalArgumentException 如果是空串或null对象,或所有内容为空白字符
- */
- public static void hasText(String text) {
- hasText(text,
- "[断言失败] - text必须是有内容的,有内容指不是全部为空白字符的字符串");
- }
-
-
- /**
- * 断言数组是否为空数组
- * @param array 要断言的数租
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果是空数组或者null
- */
- public static void notEmpty(Object[] array, String message) {
- if (array == null || array.length == 0) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言数组是否为空数组,有默认消息
- * @param array 要断言的数租
- * @throws IllegalArgumentException 如果是空数组或者null
- */
- public static void notEmpty(Object[] array) {
- notEmpty(array, "[断言失败] - 参数数组必须是非空数组");
- }
-
- /**
- * 断言集合是否为空集合对象
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果是空集合对象或者null
- */
- public static void notEmpty(Collection collection, String message) {
- if (collection == null || collection.isEmpty()) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言集合是否为空集合对象,有默认消息
- * @throws IllegalArgumentException 如果是空集合对象或者null
- */
- public static void notEmpty(Collection collection) {
- notEmpty(collection,
- "[断言失败] - 集合参数必须是有内容的");
- }
-
- /**
- * 断言Map是否为空对象
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果是空集合对象或者null
- */
- public static void notEmpty(Map map, String message) {
- if (map == null || map.isEmpty()) {
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言Map是否为空对象,有默认消息
- * @throws IllegalArgumentException 如果是空集合对象或者null
- */
- public static void notEmpty(Map map) {
- notEmpty(map, "[断言失败] - Map参数必须是有内容的");
- }
-
-
- /**
- *断言指定的 Object 是否与此 type 所表示的对象赋值兼容
- * @param obj 用于检查的对象
- * @throws IllegalArgumentException 如果不兼容
- */
- public static void isInstanceOf(Class clazz, Object obj) {
- isInstanceOf(clazz, obj, "");
- }
-
- /**
- *断言指定的 Object 是否与此 type 所表示的对象赋值兼容
- * @param obj 用于检查的对象
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不兼容
- */
- public static void isInstanceOf(Class type, Object obj, String message) {
- notNull(type, "类型对象不可为空");
- if (!type.isInstance(obj)) {
- throw new IllegalArgumentException(message +
- "Object of class [" + (obj != null ? obj.getClass().getName() : "null") +
- "] must be an instance of " + type);
- }
- }
-
-
- /**
- * 断言一个class对象调用newInstance,是否成功
- * @param type
- * @throws IllegalArgumentException 如果不成功
- */
- public static void isNewInstanceOf(Class type){
- isNewInstanceOf(type,"");
- }
-
- /**
- * 断言两个类型是否相同
- * @param type1
- * @param type2
- */
- public static void isSameType(Class type1,Class type2,String message){
- notNull(type1,"类型对象不可为空");
- notNull(type2,"类型对象不可为空");
- if(!type1.equals(type2)){
- throw new IllegalArgumentException(message);
- }
- }
-
- /**
- * 断言两个类型是否相同
- * @param type1
- * @param type2
- */
- public static void isSameType(Class type1,Class type2){
- isSameType(type1, type2, "必须是相同类型");
- }
-
- /**
- * 断言一个class对象调用newInstance,是否成功
- * @param type
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果不成功
- */
- public static void isNewInstanceOf(Class type,String message){
- notNull(type,"类型对象不可为空");
- try {
- type.newInstance();
- } catch (InstantiationException e) {
-
- throw new IllegalArgumentException(message +
- "Class [" + type +"] must be can new instance ");
- } catch (IllegalAccessException e) {
-
- throw new IllegalArgumentException(message +
- "Class [" + type +"] must be can new instance ");
- }
- }
-
- /**
- * 断言superType.isAssignableFrom(subType)是否为true
- * @param superType 超类
- * @param subType 子类
- * @throws IllegalArgumentException 如果调用该方法为false
- */
- public static void isAssignable(Class superType, Class subType) {
- isAssignable(superType, subType, "");
- }
-
- /**
- * 断言superType.isAssignableFrom(subType)是否为true
- * @param superType 超类
- * @param subType 子类
- * @param message 抛异常以后的消息
- * @throws IllegalArgumentException 如果调用该方法为false
- */
- public static void isAssignable(Class superType, Class subType, String message) {
- notNull(superType, "超类的类对象必须为非空");
- if (subType == null || !superType.isAssignableFrom(subType)) {
- throw new IllegalArgumentException(message + subType + " is not assignable to " + superType);
- }
- }
-
-
- /**
- * 断言一个对象所属状态值是否为true
- * @param expression 要断言的状态表达式
- * @param message 抛异常以后的消息
- * @throws IllegalStateException 如果表达式为false
- */
- public static void state(boolean expression, String message) {
- if (!expression) {
- throw new IllegalStateException(message);
- }
- }
-
-
- /**
- * 断言一个对象所属状态值是否为true,有默认消息
- * @param expression 要断言的状态表达式
- * @throws IllegalStateException 如果表达式为false
- */
- public static void state(boolean expression) {
- state(expression, "[断言失败] - 状态表达式必须式true");
- }
-
- public static void logic(boolean expression,String message){
- if (!expression) {
- throw new IllegalLogicException(message);
- }
- }
-
- public static void logic(boolean expression){
- logic(expression, "[断言失败] - 逻辑表达式必须是true");
- }
-
- public static void fail(String message){
- throw new IllegalLogicException(message);
- }
-
- public static void fail(String message,Throwable e){
- throw new IllegalLogicException(LogUtil.exceptionMsg(message,e),e);
- }
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/assertion/IllegalLogicException.java b/luqj-common/src/main/java/com/luqj/util/assertion/IllegalLogicException.java
deleted file mode 100644
index a1c5f36..0000000
--- a/luqj-common/src/main/java/com/luqj/util/assertion/IllegalLogicException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.luqj.util.assertion;
-
-public class IllegalLogicException extends RuntimeException {
-
- public IllegalLogicException() {
- super();
- }
-
- public IllegalLogicException(String arg0, Throwable arg1) {
- super(arg0, arg1);
- }
-
- public IllegalLogicException(String arg0) {
- super(arg0);
- }
-
- public IllegalLogicException(Throwable arg0) {
- super(arg0);
- }
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/date/DateUtils.java b/luqj-common/src/main/java/com/luqj/util/date/DateUtils.java
deleted file mode 100644
index c7546ce..0000000
--- a/luqj-common/src/main/java/com/luqj/util/date/DateUtils.java
+++ /dev/null
@@ -1,1331 +0,0 @@
-/**
- * 版权所有:厦门市巨龙软件工程有限公司
- * Copyright 2009 Xiamen Dragon Software Eng. Co. Ltd.
- * All right reserved.
- *====================================================
- * 文件名称: DateUtils.java
- * 修订记录:
- * No 日期 作者(操作:具体内容)
- * 1. Mar 3, 2009 何志昭(创建:创建文件)
- * 2. Mar 3, 2009 根据dragonsoft_checks.xml规范进行调整
- *====================================================
- * 类描述:
- *
- */
-package com.luqj.util.date;
-
-
-import com.luqj.util.StringUtils;
-import com.luqj.util.Validator;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-/**
- *
- *
- *
- *
- *
- *
- *
- * @author 陈雄华,姚建斌,谢计生
- * @version 1.0
- * @see Java
- * simpleDateFormat Tutorial
- * @see Date
- * @see Calendar
- * @see SimpleDateFormat
- * @since 1.0
- */
-public class DateUtils {
-
- /**一分钟的秒数*/
- public static final int SECONDS_ONE_MINUTE = 60;
-
- /**一秒的毫秒数*/
- public static final int MILLISECONDS_ONE_SECOND = 1000;
-
- /**一小时的秒数*/
- public static final int SECONDS_ONE_HOUR = 60 * SECONDS_ONE_MINUTE;
-
- /**一天的秒数*/
- public static final int SECONDS_ONE_DAY = 24 * SECONDS_ONE_HOUR;
-
- /** 数据库存储的时间格式串,如yyyymmdd 或yyyymmddHHMiSS */
- public static final int DB_STORE_DATE = 1;
-
- /** 用连字符-分隔的时间时间格式串,如yyyy-mm-dd 或yyyy-mm-dd HH:Mi:SS */
- public static final int HYPHEN_DISPLAY_DATE = 2;
-
- /** 用连字符.分隔的时间时间格式串,如yyyy.mm.dd 或yyyy.mm.dd HH:Mi:SS */
- public static final int DOT_DISPLAY_DATE = 3;
-
- /** 用中文字符分隔的时间格式串,如yyyy年mm月dd 或yyyy年mm月dd HH:Mi:SS */
- public static final int CN_DISPLAY_DATE = 4;
- /** 日期的开始时间戳*/
- public static final String DB_STORE_DATE_BEGIN = "000000";
- /** 日期的结束时间戳*/
- public static final String DB_STORE_DATE_END = "235959";
-
-
- /**
- * 获取当前月份的第一天
- * @return 第一天的日期对象
- * @author:李炜
- */
- public static Date getCurMonthFirstDate(){
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
- return calendar.getTime();
- }
-
- /**
- * 获取当前月份的最后一天
- * @return 最后一天的日期对象
- * @author:李炜
- */
- public static Date getCurMonthLastDay() {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
- return calendar.getTime();
- }
-
-
- /**
- * 获取日期的开始时间戳
- * @param storeDate 数据库存储日期,格式yyyyMMddHHmmss
- * @return storeDate
- * @author:李炜
- */
- public static String getStoreDateBegin(String storeDate){
- if(storeDate.length() >= 8){
- return storeDate.substring(0,8)+DB_STORE_DATE_BEGIN;
- }else{
- return storeDate;
- }
- }
-
- /**
- * 获取日期的结束时间戳
- * @param storeDate 数据库存储日期,格式yyyyMMddHHmmss
- * @return storeDate
- * @author:李炜
- */
- public static String getStoreDateEnd(String storeDate){
- if(storeDate.length() >= 8){
- return storeDate.substring(0,8)+DB_STORE_DATE_END;
- }else{
- return storeDate;
- }
- }
-
-
- /**
- * 得到精确到秒的格式化当前时间串
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return 当前时间格式化时间串
- */
- public static String getCurrTimeStr(int formatType) {
- return getTimeStr(new Date(), formatType);
- }
-
- /**
- * 得到精确到秒的格式化时间串
- *
- * @param date
- * 指定时间
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #HYPHEN_DISPLAY_DATE},{@link #DOT_DISPLAY_DATE}
- * @return 指定时间的格式化时间串
- */
- public static String getTimeStr(Date date, int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMMddHHmmss";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy'-'MM'-'dd HH:mm:ss";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM.dd HH:mm:ss";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月'dd HH:mm:ss";
- break;
- default:
- formatStr = "yyyyMMddHHmmss";
- break;
- }
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(date);
- }
- }
-
- /**
- * 得到精确到天的当前格式化日期串
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return String
- */
- public static String getCurrDateStr(int formatType) {
- return getDateStr(new Date(), formatType);
- }
-
- /**
- * 得到精确到天的指定时间格式化日期串
- *
- * @param date
- * 指定时间
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return 指定时间格式化日期串
- */
- public static String getDateStr(Date date, int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMMdd";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM-dd";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM.dd";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月'dd";
- break;
- default:
- formatStr = "yyyyMMdd";
- break;
- }
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(date);
- }
- }
-
- /**
- * 得到精确到月的当前时间格式化年月串
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return 精确到月当前时间格式化年月串
- */
- public static String getYearMonthStr(int formatType) {
- return getYearMonthStr(new Date(), formatType);
- }
-
- /**
- * 得到精确到月的指定时间格式化年月串
- *
- * @param date
- * 指定的时间
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return 精确到月当前时间格式化年月串
- */
- public static String getYearMonthStr(Date date, int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMM";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月'";
- break;
- default:
- formatStr = "yyyyMM";
- break;
- }
-
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(date);
- }
- }
-
- /**
- * 将数据库存储的日期格式串转换为各种显示的格式
- *
- * @param dateStr
- * 最小6位,最大14位的数据库存储格式时间串如:20041212
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @return 格式化的时间串
- */
- public static String toDisplayStr(String dateStr, int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- }
- if (dateStr == null || dateStr.length() < 6 || dateStr.length() > 14 || formatType == DB_STORE_DATE) {
- return StringUtils.toVisualString(dateStr);
- } else {
- char[] charArr = null;
- switch (formatType) {
- case HYPHEN_DISPLAY_DATE:
- charArr = new char[] { '-', '-', ' ', ':', ':' };
- break;
- case DOT_DISPLAY_DATE:
- charArr = new char[] { '.', '.', ' ', ':', ':' };
- break;
- case CN_DISPLAY_DATE:
- charArr = new char[] { '年', '月', ' ', ':', ':' };
- break;
- default:
- charArr = new char[] { '-', '-', ' ', ':', ':' };
- }
- try {
- SimpleDateFormat sdf1 = null;
- SimpleDateFormat sdf2 = null;
- switch (dateStr.length()) {
- case 6:
- sdf1 = new SimpleDateFormat("yyyyMM");
- sdf2 = new SimpleDateFormat("yyyy'" + charArr[0] + "'MM");
- break;
- case 8:
- sdf1 = new SimpleDateFormat("yyyyMMdd");
- sdf2 = new SimpleDateFormat("yyyy'" + charArr[0] + "'MM'" + charArr[1] + "'dd");
- break;
- case 10:
- sdf1 = new SimpleDateFormat("yyyyMMddHH");
- sdf2 = new SimpleDateFormat("yyyy'" + charArr[0] + "'MM'" + charArr[1] + "'dd'"
- + "+charArr[2]" + "'HH");
- break;
- case 12:
- sdf1 = new SimpleDateFormat("yyyyMMddHHmm");
- sdf2 = new SimpleDateFormat("yyyy'" + charArr[0] + "'MM'" + charArr[1] + "'dd'" + charArr[2]
- + "'HH'" + charArr[3] + "'mm");
- break;
- case 14:
- sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
- sdf2 = new SimpleDateFormat("yyyy'" + charArr[0] + "'MM'" + charArr[1] + "'dd'" + charArr[2]
- + "'HH'" + charArr[3] + "'mm'" + charArr[4] + "'ss");
- break;
- default:
- return dateStr;
- }
- return sdf2.format(sdf1.parse(dateStr));
- } catch (ParseException ex) {
- return dateStr;
- }
- }
- }
-
- /**
- * 将显示格式的时间字符串转换为数据库存储的类型
- *
- * @param dateStr
- * 最小4位,最大19位。显示的时间格式时间串如:2004-12-12
- * @return 数据库存储的时间字符串
- */
- public static String toStoreStr(String dateStr) {
- if (dateStr == null || dateStr.trim().equals("")) {
- return "";
- }
- StringBuffer strBuf = new StringBuffer();
- for (int i = 0; i < dateStr.length(); i++) {
- if (dateStr.charAt(i) >= '0' && dateStr.charAt(i) <= '9') {
- strBuf.append(dateStr.charAt(i));
- }
- }
- return strBuf.toString();
- }
-
- /**
- * 将生日存储的时间格式转化为年龄(周岁,小数点后不计)
- *
- * @param birthdayStr
- * 生日字段 "yyyymmdd"
- * @return 年龄
- */
- public static String birthdayToAge(String birthdayStr) {
- if (birthdayStr == null || birthdayStr.length() < 6) {
- return "";
- } else {
- int birthYear = Integer.parseInt(birthdayStr.substring(0, 4));
- int birthMonth = Integer.parseInt(birthdayStr.substring(4, 6));
- Calendar cal = new GregorianCalendar();
- int currYear = cal.get(Calendar.YEAR);
- int currMonth = cal.get(Calendar.MONTH);
- int age = currYear - birthYear;
- age -= (currMonth < birthMonth) ? 1 : 0;
- return "" + age;
- }
- }
-
- /**
- *
- * @param dateTimeStr
- * String 格式化的时间串
- * @param formatType
- * 数据格式类型 {@link #DB_STORE_DATE},{@link #EN_HTML_DISPLAY_DATE},{@link #CN_HTML_DISPLAY_DATE}
- * @param detal
- * int 增加或减少的时间
- * @param field
- * int 参见Calendar中关于时间字段属性的定义
- * @return String 返回的
- */
- public static String add(String dateTimeStr, int formatType, int detal, int field) {
- if (dateTimeStr == null || dateTimeStr.length() < 6) {
- return dateTimeStr;
- } else {
- try {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMMddHHmmss";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM-dd HH:mm:ss";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM.dd HH:mm:ss";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月' HH:mm:ss";
- break;
- default:
- formatStr = "yyyyMMddHHmmss";
- break;
- }
-
- formatStr = formatStr.substring(0, dateTimeStr.length());
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- Date d = sdf.parse(dateTimeStr);
- GregorianCalendar g = new GregorianCalendar();
- g.setTime(d);
- g.add(field, detal);
- d = g.getTime();
- return sdf.format(d);
- } catch (ParseException ex) {
-
- return dateTimeStr;
- }
- }
- }
-
- // /**
- // * @param date Date 时间
- // * @param detal int 增加的时间
- // * @param field int 参见Calendar中关于时间字段属性的定义
- // * @return Date
- // */
- // public static Date add(Date date, int detal, int field)
- // {
- // Calendar g = new GregorianCalendar();
- // g.setTime(date);
- // g.add(field, detal);
- // return g.getTime();
- // }
- /**
- * 日期、时间格式化
- *
- * @param date
- * Date 将要被格式化的日期对象
- * @param outFmt
- * String 返回样式,参照类说明,如:yyyy年MM月dd日
- * @return String 格式化后的日期、时间字符串,data为null时返回null,outFmt非法时返回yyyyMMdd格式
- */
- public static String getDateFormat(Date date, String outFmt) {
- if (null == date) {
- return null;
- }
- String newOutFmt = outFmt;
-
- if (null == newOutFmt || "".equals(newOutFmt.trim())) { // outFmt非法
- newOutFmt = "yyyyMMdd";
- }
-
- String retu = null;
- SimpleDateFormat dateFormat = null;
- try {
- dateFormat = new SimpleDateFormat(newOutFmt);
- } catch (IllegalArgumentException iaex) { // outFmt非法
- dateFormat = new SimpleDateFormat("yyyyMMdd");
- }
- retu = dateFormat.format(date);
-
- dateFormat = null;
-
- return retu;
- }
-
- /**
- * 把日期时间对象格式化为yyyyMMdd样式
- *
- * @param date
- * Date 将要被格式化的日期对象
- * @return String 格式化后的日期、时间字符串,如:20041001
- */
- public static String getDateFormat(Date date) {
- return getDateFormat(date, "yyyyMMdd");
- }
-
- /**
- * 把日期时间对象格式化为yyyyMMdd样式
- *
- * @param date
- * Date 将要被格式化的日期对象
- * @return String 格式化后的日期、时间字符串,如:20041001
- */
- public static String getDateFormatByFmt(Date date,String outFmt) {
- return getDateFormat(date, outFmt);
- }
-
- /**
- * 把系统当前日期时间格式化为指定的样式
- *
- * @param outFmt
- * String 返回样式,参照类说明,如:yyyy年MM月dd日
- * @return String 格式化后的日期、时间字符串,如:2004年10月01日
- */
- public static String getDateFormat(String outFmt) {
- return getDateFormat(new Date(), outFmt);
- }
-
- /**
- * 把系统当前日期时间格式化为默认样式yyyyMMdd
- *
- * @return String 格式化后的日期、时间字符串,如:20041001
- */
- public static String getDateFormat() {
- return getDateFormat(new Date(), "yyyyMMdd");
- }
-
- /**
- * 日期、时间格式化
- *
- * @param millis
- * long the number of milliseconds(毫秒) since January 1, 1970,
- * 00:00:00 GMT.
- * @param outFmt
- * String 返回样式,参照类说明,如:yyyy年MM月dd日
- * @return String 格式化后的日期、时间字符串
- */
- public static String getDateFormat(long millis, String outFmt) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(millis);
-
- String retu = getDateFormat(calendar.getTime(), outFmt);
- calendar = null;
- return retu;
- }
-
- /**
- * 日期、时间格式化
- *
- * @param datestr
- * String 存在一定格式的日期、时间字符串,如:20041001、200410011503
- * @param inFmt
- * String 对datestr参数格式说明,参照类说明,如:yyyyMMdd、yyyyMMddHHmm
- * @param outFmt
- * String 返回样式,参照类说明,如:yyyy年MM月dd日
- * @throws ParseException
- * 当datestr不能格式化为inFmt格式时抛出此异常
- * @return String 格式化后的日期、时间字符串,如:2004年10月01日、2004年10月01日
- *
- * 输出样式outFmt非法时,使用yyyyMMdd格式输出
- */
- public static String getDateFormat(String datestr, String inFmt, String outFmt) throws ParseException {
- if (null == datestr || "".equals(datestr.trim())) {
- return datestr;
- }
-
- if (null == inFmt || "".equals(inFmt.trim())) {
- return datestr;
- }
-
- String newOutFmt = outFmt;
- if (null == newOutFmt || "".equals(newOutFmt.trim())) { // 输出样式非法
- newOutFmt = "yyyyMMdd";
- }
-
- Date inDate = getDate(datestr, inFmt);
-
- if (null == inDate) { // 根据inFmt分析datestr时抛出异常
- return datestr;
- }
-
- String retu = getDateFormat(inDate, newOutFmt);
- inDate = null;
- return retu;
- }
-
- /**
- * 把日期时间字符串,按inFmt样式转化为日期对象,然后格式化为默认样式yyyyMMdd
- *
- * @param datestr
- * String 存在一定格式的日期、时间字符串,如:20041001、200410011503
- * @param inFmt
- * String 对datestr参数格式说明,参照类说明,如:yyyyMMdd、yyyyMMddHHmm
- * @throws ParseException
- * 当datestr不能格式化为inFmt格式时抛出此异常
- * @return String 格式化后的日期、时间字符串,如:20041001、20041001
- */
- public static String getDateFormat(String datestr, String inFmt) throws ParseException {
- return getDateFormat(datestr, inFmt, "yyyyMMdd");
- }
-
- /**
- * 根据inFmt的样式,日期时间字符串转化为日期时间对象
- *
- * @param datestr
- * String 日期时间字符串,如:20041001、2004年10月01日 15:03
- * @param inFmt
- * String 对datestr参数格式说明,参照类说明,如yyyyMMdd、yyyy年MM月dd日 HH:mm
- * @throws ParseException
- * 当datestr不能格式化为inFmt格式时抛出此异常
- * @return Date 日期时间对象,格式inFmt非法时,使用yyyyMMdd格式
- */
- public static Date getFillDate(String datestr, String inFmt,boolean end) throws ParseException {
- if (null == datestr || "".equals(datestr.trim())) {
- return null;
- }
-
- String newInFmt = inFmt;
- if (null == newInFmt || "".equals(newInFmt.trim())) { // inFmt非法
- newInFmt = "yyyyMMdd";
- }
- String[] endFlag = new String[]{"9","5"};
- String endStr = "";
- if(datestr.length()!=newInFmt.length()){
- int len = newInFmt.length()-datestr.length();
- if(end){
- for(int i=len;i>0;i--){
- endStr=endFlag[(i+1)%2]+endStr;
- }
- }else{
- for(int i=len;i>0;i--){
- endStr+="0";
- }
- }
- }
-
- datestr=datestr.trim()+endStr;
- Date inDate = null;
-
- // 依据inFmt格式把日期字符串转化为日期对象
- SimpleDateFormat inDateFormat = new SimpleDateFormat(newInFmt);
- inDateFormat.setLenient(true);
- inDate = inDateFormat.parse(datestr);
-
- inDateFormat = null;
- return inDate;
- }
- /**
- * 根据inFmt的样式,日期时间字符串转化为sql日期时间对象
- *
- * @param datestr
- * String 日期时间字符串,如:20041001、2004年10月01日 15:03
- * @param inFmt
- * String 对datestr参数格式说明,参照类说明,如yyyyMMdd、yyyy年MM月dd日 HH:mm
- * @throws ParseException
- * 当datestr不能格式化为inFmt格式时抛出此异常
- * @return Date 日期时间对象,格式inFmt非法时,使用yyyyMMdd格式
- */
- public static java.sql.Date getSqlDate(String datestr,String inFmt) throws ParseException{
- Date utilDate = getDate(datestr, inFmt);
- return new java.sql.Date(utilDate.getTime());
- }
-
- /**
- * 根据inFmt的样式,日期时间字符串转化为日期时间对象
- *
- * @param datestr
- * String 日期时间字符串,如:20041001、2004年10月01日 15:03
- * @param inFmt
- * String 对datestr参数格式说明,参照类说明,如yyyyMMdd、yyyy年MM月dd日 HH:mm
- * @throws ParseException
- * 当datestr不能格式化为inFmt格式时抛出此异常
- * @return Date 日期时间对象,格式inFmt非法时,使用yyyyMMdd格式
- */
- public static Date getDate(String datestr, String inFmt) throws ParseException {
- if (null == datestr || "".equals(datestr.trim())) {
- return null;
- }
-
- String newInFmt = inFmt;
- if (null == newInFmt || "".equals(newInFmt.trim())) { // inFmt非法
- newInFmt = "yyyyMMdd";
- }
-
- Date inDate = null;
-
- // 依据inFmt格式把日期字符串转化为日期对象
- SimpleDateFormat inDateFormat = new SimpleDateFormat(newInFmt);
- inDateFormat.setLenient(true);
- inDate = inDateFormat.parse(datestr);
-
- inDateFormat = null;
- return inDate;
- }
-
- /**
- *
- * @param date1
- * @param date2
- * @return
- * @author:李炜
- */
- public static int dateDiff(Date date1,Date date2){
- if(date1.compareTo(date2) == 0){
- return 0;
- }
- long second = Math.abs((date1.getTime() - date2.getTime())) / 1000;
- return (int) (second / SECONDS_ONE_DAY);
- }
-
- /**
- * 相差的时间(单位:秒)
- * @param date1
- * @param date2
- * @return
- */
- public static long secondDiff(Date date1,Date date2){
- if(date1.compareTo(date2) == 0){
- return 0;
- }
- long second = Math.abs((date1.getTime() - date2.getTime())) / 1000;
- return second;
- }
-
-
- public static int dateCompare(Date date1,Date date2){
- if(date1 == null){
- return -1;
- }
- if(date2 == null){
- return -1;
- }
- if(date1.compareTo(date2) == 0){
- return 0;
- }
- long second =(date1.getTime() - date2.getTime()) / 1000;
- return (int) (second / SECONDS_ONE_DAY);
- }
-
-
-
- public static int dateSimpleCompare(String dateStr1,String dateStr2,String format){
-
- Date date1 = null;
- Date date2 = null;
- try {
- SimpleDateFormat dateFormat = new SimpleDateFormat(format);
- date1 = dateFormat.parse(dateStr1);
- date2 = dateFormat.parse(dateStr2);
- if(date1.getTime()>date2.getTime()){
- return 1;
- }else if(date1.getTime()
- * <blockquote>
- * 计算去年今天星期几
- * Date date = DateUtils.addDate(new Date(),Calendar.YEAR,-1);
- * System.out.println(DateUtils.getDateFormat(date,"E"));
- * 打印60天后是什么日期,并显示为 yyyy-MM-dd 星期
- * Date date = DateUtils.addDate(new Date(),Calendar.DATE,60);
- * System.out.println(DateUtils.getDateFormat(date,"yyyy-MM-dd E"));
- * </blockquote>
- *
- *
- * @param date
- * Date 需要调整的日期时间对象
- * @param calendarField
- * int 对日期时间对象以什么单位进行调整:
- *
- *
- * <blockquote>
- * 年 Calendar.YEAR
- * 月 Calendar.MONTH
- * 日 Calendar.DATE
- * 时 Calendar.HOUR
- * 分 Calendar.MINUTE
- * 秒 Calendar.SECOND
- * </blockquote>
- *
- *
- * @param amount
- * int 调整数量,>0表向后调整(明天,明年),<0表向前调整(昨天,去年)
- * @return Date 调整后的日期时间对象
- */
- public static Date addDate(Date date, int calendarField, int amount) {
- if (null == date) {
- return date;
- }
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.add(calendarField, amount);
- return calendar.getTime();
- }
-
- /**
- * 对日期时间对象进行调整.
- *
- * @param datestr
- * String 需要调整的日期时间字符串,它的格式为yyyyMMdd
- * @param calendarField
- * int 对日期时间对象以什么单位进行调整
- * @param amount
- * int 调整数量
- * @throws ParseException
- * 当datestr不能格式化为yyyyMMdd格式时抛出此异常
- * @return Date 调整后的日期时间对象
- * @see #addDate(Date, int, int)
- */
- public static Date addDate(String datestr, int calendarField, int amount) throws ParseException {
- return addDate(getDate(datestr, "yyyyMMdd"), calendarField, amount);
- }
-
- /**
- * 根据出生日期,计算出在某一个日期的年龄
- *
- * @param birthday
- * Date 出生日期时间对象
- * @param date2
- * Date 计算日期对象
- * @return int 返回date2那一天出生日期为birthday的年龄,如果birthday大于date2则返回-1
- */
- public static int getAge(Date birthday, Date date2) {
- if (null == birthday || null == date2) {
- return -1;
- }
-
- if (birthday.after(date2)) { // birthday大于date2
- return -1;
- }
-
- int ibdYear = StringUtils.getInt(getDateFormat(birthday, "yyyy"), -1);
- int idate2Year = StringUtils.getInt(getDateFormat(date2, "yyyy"), -1);
-
- if (ibdYear < 0 || idate2Year < 0) {
- return -1;
- }
- if (ibdYear > idate2Year) {
- return -1;
- }
-
- return idate2Year - ibdYear + 1;
- }
-
- /**
- * 根据出生日期,计算出当前的年龄
- *
- * @param birthday
- * Date 出生日期时间对象
- * @return int 返回出生日期为birthday的年龄,如果birthday大于当前系统日期则返回-1
- */
- public static int getAge(Date birthday) {
- return getAge(birthday, new Date());
- }
-
- /**
- * 根据出生日期,计算出当前的年龄
- *
- * @param birthdaystr
- * String 出生日期时间字符串,其格式一定为yyyyMMdd
- * @throws ParseException
- * 当datestr不能格式化为yyyyMMdd格式时抛出此异常
- * @return int 返回出生日期为birthday的年龄,如果birthday大于当前系统日期则返回-1
- */
- public static int getAge(String birthdaystr) throws ParseException {
- return getAge(getDate(birthdaystr, "yyyyMMdd"));
- }
-
- public static String dbCurrtime(){
- return getCurrTime(DB_STORE_DATE);
- }
-
- /**
- * 得到14位的当前格式化时间
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link
- * @return java.lang.String
- */
- public static String getCurrTime(int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMMddHHmmss";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM-dd HH:mm:ss";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM.dd HH:mm:ss";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy年MM月dd HH:mm:ss";
- break;
- default:
- formatStr = "yyyyMMddHHmmss";
- break;
- }
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(new Date());
- }
- }
-
- /**
- * 得到8位的当前格式化日期
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link
- * @return java.lang.String
- */
- public static String getCurrDate(int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMMdd";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM-dd";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM.dd";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月'dd";
- break;
- default:
- formatStr = "yyyyMMdd";
- break;
- }
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(new Date());
- }
- }
-
- /**
- * 得到6位的当前格式化年月
- *
- * @param formatType
- * 时间格式的类型{@link #DB_STORE_DATE},{@link
- * @return java.lang.String
- */
- public static String getYearMonth(int formatType) {
- if (formatType < DB_STORE_DATE || formatType > CN_DISPLAY_DATE) {
- throw new IllegalArgumentException("时间格式化类型不是合法的值。");
- } else {
- String formatStr = null;
- switch (formatType) {
- case DB_STORE_DATE:
- formatStr = "yyyyMM";
- break;
- case HYPHEN_DISPLAY_DATE:
- formatStr = "yyyy-MM";
- break;
- case DOT_DISPLAY_DATE:
- formatStr = "yyyy.MM";
- break;
- case CN_DISPLAY_DATE:
- formatStr = "yyyy'年'MM'月'";
- break;
- default:
- formatStr = "yyyyMM";
- break;
- }
- SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
- return sdf.format(new Date());
- }
- }
-
- /**
- * 获取时间所对应的毫秒
- *
- * @param datetime
- * String 时间字符串
- * @param inFmt
- * String 时间格式化串
- * @return long 毫秒数
- * @throws ParseException
- * ParseException
- */
- public static long getTimeValue(String datetime, String inFmt) throws ParseException {
- return getDate(datetime, inFmt).getTime();
- }
-
- /**
- * 两个秒数只差
- * @param startTime
- * @param endTime
- * @param inFmt
- * @return
- */
- public static long consumeSecondsValue(String startTime,String endTime,String inFmt) throws ParseException{
- long startSeconds = getTimeValue(startTime,inFmt);
- long endSeconds = getTimeValue(endTime,inFmt);
- return (endSeconds - startSeconds)/1000;
- }
-
- /**
- * 获取时间字符串
- *
- * @param milliSeconds
- * long 从1970年到现在的毫
- * @param formatType
- * int 时间类型
- * @return String 时间字符串
- */
- public static String getTimeStr(long milliSeconds, int formatType) {
- Date d = new Date(milliSeconds);
- return getTimeStr(d, formatType);
- }
-
-
-
- /**
- * getTimeByValue
- *
- * @param time
- * 时间
- * @param timeOldFormat
- * 旧时间格式
- * @param timeNewFormat
- * 新时间格式
- * @return String
- * @author:Administrator
- */
- public static String getTimeByValue(String time, String timeOldFormat, String timeNewFormat) {
- SimpleDateFormat oldSdf = new SimpleDateFormat(timeOldFormat);
- SimpleDateFormat newSdf = new SimpleDateFormat(timeNewFormat);
- String newTime = time;
- try {
- if (Validator.hasText(time)) {
- // Date times = oldSdf.parse(time);
- newTime = newSdf.format(oldSdf.parse(time));
- }
- } catch (ParseException e1) {
-
- }
- return newTime;
- }
-
-
- /**
- * 返回上月的起始日期和结束日期,格式YYYYMMDD
- * @param time
- * @return
- * @author:lwei
- */
- public static String[] getLastMonthBetweenDay(Date time){
- Calendar cal = Calendar.getInstance();
- cal.setTime(time);
- int year = 0;
- int month = cal.get(Calendar.MONTH)-1; // 上个月月份
- if (month == 0) {
- year = cal.get(Calendar.YEAR) - 1;
- month = 12;
- } else {
- year = cal.get(Calendar.YEAR);
- }
- Calendar c = Calendar.getInstance();
- c.set(year, month, 1);
- int startDay = c.getActualMinimum(Calendar.DAY_OF_MONTH);//起始天数
- int endDay = c.getActualMaximum(Calendar.DAY_OF_MONTH); // 结束天数
- c.set(year, month,startDay);
- String startTime = getDateFormat(c.getTime());
- c.clear();
- c.set(year, month,endDay);
- String endTime = getDateFormat(c.getTime());
- return new String[]{startTime,endTime};
- }
-
- /**
- * 返回上月的起始日期和结束日期,格式YYYYMMDD
- * @param time
- * @return
- * @author:huanglm
- */
- public static String[] getLastMonthBetweenDayByFmt(Date time,String fmt){
- Calendar cal = Calendar.getInstance();
- cal.setTime(time);
- int year = 0;
- int month = cal.get(Calendar.MONTH)-1; // 上个月月份
- if (month == 0) {
- year = cal.get(Calendar.YEAR) - 1;
- month = 12;
- } else {
- year = cal.get(Calendar.YEAR);
- }
- Calendar c = Calendar.getInstance();
- c.set(year, month, 1);
- int startDay = c.getActualMinimum(Calendar.DAY_OF_MONTH);//起始天数
- int endDay = c.getActualMaximum(Calendar.DAY_OF_MONTH); // 结束天数
- c.set(year, month,startDay);
- String startTime = getDateFormatByFmt(c.getTime(),fmt);
- c.clear();
- c.set(year, month,endDay);
- String endTime = getDateFormatByFmt(c.getTime(),fmt);
- return new String[]{startTime,endTime};
- }
-
-
-
- /**
- * 获取两时间字符串的时间间隔描述
- * 例如:2010-10-10 10:10:10与2010-10-20 20:20:20
- * 的时间间隔描述串为:10天10时10分10秒
- * 如果开始时间大于结束时间返回负数,如:-10时10分10秒
- *
- * @param beginTime 开始时间字符串
- * @param endTime 结束时间字符串
- * @param inFmt String 时间格式化串
- * @return 两时间字符串的时间差 如:12天03时25分08秒
- */
- public static String getTimeBetweenStr(String beginTime,String endTime,String inFmt){
- SimpleDateFormat dfs = new SimpleDateFormat(inFmt);
- StringBuffer timeStrBuf = new StringBuffer();
- try {
- Date begin = dfs.parse(beginTime);
- Date end = dfs.parse(endTime);
- if (begin.compareTo(end) == 0 ) {
- return "1秒"; //如果开始时间等于结束时间 直接返回1秒
- }
- long between = (end.getTime() - begin.getTime()) / 1000; //除以1000是为了转换成秒
- if (between < 0 ) {
- timeStrBuf.append("-");
- between = -between;
- }
- long day = between / (24*60*60);
- long hour = between % (24*60*60) / 3600;
- long minute = between % (60*60) / 60;
- long second = between % 60;
- if (day != 0) {
- timeStrBuf.append(String.valueOf(day)+"天" );
- }
- if (hour != 0) {
- timeStrBuf.append(String.valueOf(hour)+"时" );
- }
-
- if(minute != 0 ) {
- timeStrBuf.append(String.valueOf(minute)+"分" );
- }
- if (second != 0 ) {
- timeStrBuf.append(String.valueOf(second)+"秒" );
- }
- } catch (Exception e) {
- return null;
- }
- return timeStrBuf.toString();
- }
-
- /**
- * 给时间加上或减去指定毫秒,秒,分,时,天、月或年等,返回变动后的时间
- *
- * @param date 要加减前的时间,如果不传,则为当前日期
- * @param field 时间域,有Calendar.MILLISECOND,Calendar.SECOND,Calendar.MINUTE,
- * * Calendar.HOUR,Calendar.DATE, Calendar.MONTH,Calendar.YEAR
- * @param amount 按指定时间域加减的时间数量,正数为加,负数为减。
- * @author huanglm
- * @return 变动后的时间
- */
- public static Date add(Date date, int field, int amount) {
- if (date == null) {
- date = new Date();
- }
-
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- cal.add(field, amount);
-
- return cal.getTime();
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addMilliSecond(Date date, int amount) {
- return add(date, Calendar.MILLISECOND, amount);
- }
-
- /**
- *
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addSecond(Date date, int amount) {
- return add(date, Calendar.SECOND, amount);
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addMiunte(Date date, int amount) {
- return add(date, Calendar.MINUTE, amount);
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addHour(Date date, int amount) {
- return add(date, Calendar.HOUR, amount);
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addDay(Date date, int amount) {
- return add(date, Calendar.DATE, amount);
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addMonth(Date date, int amount) {
- return add(date, Calendar.MONTH, amount);
- }
-
- /**
- *
- * @param date
- * @param amount
- * @author huanglm
- * @return
- */
- public static Date addYear(Date date, int amount) {
- return add(date, Calendar.YEAR, amount);
- }
- public static final SimpleDateFormat YYYYMMDDHHMMSS_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
- public static Date ORIGINAL_DATE = null;
- static {
- try {
- ORIGINAL_DATE = YYYYMMDDHHMMSS_DATE_FORMAT.parse("19700101080000");
- } catch (ParseException e) {
-
- }
- }
- /**
- * 从19700101080000开始增加指定的秒数
- * @param amount
- * @return
- */
- public static Date addSecond(int amount) {
- return addSecond(ORIGINAL_DATE, amount);
- }
- /**
- * 从19700101080000开始增加指定的秒数
- * @param amount
- * @return
- */
- public static String addSecondToString(int amount) {
- return YYYYMMDDHHMMSS_DATE_FORMAT.format(addSecond(ORIGINAL_DATE, amount));
- }
- /**
- * 测试
- *
- * @param args
- * args
- * @throws ParseException
- * ParseException
- * @author:Administrator
- */
- public static void main(String[] args) throws ParseException {
- Date date=new Date();
- System.out.println(addMonth(DateUtils.getDate("2024-01-29","yyyy-mm-dd"),1));
- date.setTime(1491040070000l);
- System.out.println(getTimeStr(date,2));
- }
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/log/LogUtil.java b/luqj-common/src/main/java/com/luqj/util/log/LogUtil.java
deleted file mode 100644
index 6e25eeb..0000000
--- a/luqj-common/src/main/java/com/luqj/util/log/LogUtil.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.luqj.util.log;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-public abstract class LogUtil {
-
- private static String getStackTrace(Throwable t) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- try {
- t.printStackTrace(pw);
- return sw.toString();
- } finally {
- pw.close();
- }
- }
-
- public static String exceptionMsg(String msg, Throwable e) {
- return msg + ",异常消息[" + getStackTrace(e) + "]";
- }
-
- public static String exceptionSimpleMsg(String msg, Throwable e) {
- return msg + ",异常消息[" + e.getLocalizedMessage() + "]";
- }
-
- /**
- * 获取计算程序运行的时钟
- *
- * @return clock
- */
- public static Clock getClock() {
- return new Clock() {
- /**开始时间*/
- private long startTime = System.nanoTime();
-
- /**
- * 消耗时间[毫秒]
- * @return 消耗时间
- */
- public long consume() {
- return LogUtil.consume(startTime, System.nanoTime());
- }
-
- /**
- * 结束时间
- */
- public long getEnd() {
- return System.nanoTime();
- }
-
- /**
- * 开始时间
- */
- public long getStart() {
- return startTime;
- }
-
- public long consumeSecond() {
- return LogUtil.consumeSecond(startTime, System.nanoTime());
- }
- };
- }
-
-
- /**
- * 消耗时间[纳秒]
- *
- * @return 消耗时间 秒
- */
- public static long consumeNano(long startTime, long endTime) {
- return (endTime - startTime) / 1000000000 + 1;
- }
-
- /**
- * 消耗时间[微秒]
- *
- * @return 消耗时间 秒
- */
- public static long consume(long startTime, long endTime) {
- return (endTime - startTime) / 1000000 + 1;
- }
-
- /**
- * 消耗时间[耗秒]
- *
- * @return 消耗时间 秒
- */
- public static long consumeSecond(long startTime, long endTime) {
- return (endTime - startTime) / 1000 + 1;
- }
-
- /**
- * getRootCause
- * 获取异常的原始异常,用于反馈异常的真实原因。
- *
- * @param ex 异常信息
- * @return 原始异常,最底层异常
- * @author 林小松
- */
- public static Throwable getRootCause(Throwable ex) {
- Throwable cause = ex;
- while (cause.getCause() != null) {
- cause = cause.getCause();
- }
- return cause;
- }
-
- /**
- * 递归寻找根异常异常信息
- *
- * @param ex 异常
- * @return 异常信息
- */
- public static String traceRootExceptionInfo(Throwable ex) {
- Throwable cause = ex;
- while (cause.getCause() != null) {
- cause = cause.getCause();
- }
- return cause.toString();
- }
-
- /**
- * 递归寻找引起异常的所有异常信息
- *
- * @param ex 异常
- * @return 异常信息
- */
- public static String tarceExceptionInfo(Throwable ex) {
- StringBuffer sb = new StringBuffer();
- Throwable cause = ex;
- sb.insert(0, cause);
- while (cause.getCause() != null) {
- cause = cause.getCause();
- sb.insert(0, cause.toString());
- }
- return sb.toString();
- }
-
- public static interface Clock {
-
-
- /**
- * 返回程序消耗的毫秒数
- *
- * @return 消耗毫秒数
- */
- long consume();
-
- /**
- * 返回程序消耗的秒数
- *
- * @return 消耗秒数
- */
- long consumeSecond();
-
- /**
- * 返回开始时间
- *
- * @return 开始时间
- * @author:lwei
- */
- long getStart();
-
- /**
- * 返回结束时间
- *
- * @return 结束时间
- * @author:lwei
- */
- long getEnd();
- }
-
-}
diff --git a/luqj-common/src/main/java/com/luqj/util/parse/SymbolSet.java b/luqj-common/src/main/java/com/luqj/util/parse/SymbolSet.java
deleted file mode 100644
index 7a53441..0000000
--- a/luqj-common/src/main/java/com/luqj/util/parse/SymbolSet.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.luqj.util.parse;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 符号集
- * @author chenzm
- */
-public class SymbolSet {
- /**等号*/
- public final static String SYMBOL_EQ = "=";
-
- /**空字符*/
- public final static Character SYMBOL_NULL = ' ';
-
- /**逗号*/
- public final static String SYMBOL_COMMA = ",";
-
- /**双引号*/
- public final static String SYMBOL_DQM = "\"";
-
- /**单引号*/
- public final static String SYMBOL_SQM = "\'";
-
- public static String chr2Str(char chr) {
- return "" + chr;
- }
-
- static boolean isInSymbol(Map