com.google.guava
guava
diff --git a/src/main/java/org/starrier/common/constant/ResourceNameConstant.java b/src/main/java/org/starrier/common/constant/ResourceNameConstant.java
index dbc356e..7eaa8bf 100644
--- a/src/main/java/org/starrier/common/constant/ResourceNameConstant.java
+++ b/src/main/java/org/starrier/common/constant/ResourceNameConstant.java
@@ -1,15 +1,9 @@
package org.starrier.common.constant;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
/**
* @author Starrier
* @date 2018/6/5.
*/
-@Getter
-@Setter
public class ResourceNameConstant {
public static final String BOOK = "book";
@@ -26,4 +20,15 @@ public class ResourceNameConstant {
private ResourceNameConstant() {
}
+ public static String getBOOK() {
+ return BOOK;
+ }
+
+ public static String getARTICLE() {
+ return ARTICLE;
+ }
+
+ public static String getCOMMENT() {
+ return COMMENT;
+ }
}
diff --git a/src/main/java/org/starrier/common/page/PageConstant.java b/src/main/java/org/starrier/common/page/PageConstant.java
index 1eb2dbb..8b227fa 100644
--- a/src/main/java/org/starrier/common/page/PageConstant.java
+++ b/src/main/java/org/starrier/common/page/PageConstant.java
@@ -1,15 +1,9 @@
package org.starrier.common.page;
-
-import lombok.Getter;
-import lombok.Setter;
-
/**
* @author Starrier
* @date 2018/6/5.
*/
-@Getter
-@Setter
public class PageConstant {
/**
@@ -25,9 +19,16 @@ public class PageConstant {
/**
* Prevent instantiation.
*
- * And if you need expose, {@link lombok.NoArgsConstructor} instead of if.
*/
private PageConstant() {
}
+ public static int getPAGE() {
+ return PAGE;
+ }
+
+ public static int getPerPage() {
+ return PER_PAGE;
+ }
+
}
diff --git a/src/main/java/org/starrier/common/page/PaginatedResult.java b/src/main/java/org/starrier/common/page/PaginatedResult.java
index 428ae0c..94aae0d 100644
--- a/src/main/java/org/starrier/common/page/PaginatedResult.java
+++ b/src/main/java/org/starrier/common/page/PaginatedResult.java
@@ -1,25 +1,17 @@
package org.starrier.common.page;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.ToString;
-import lombok.experimental.Accessors;
-
import java.io.Serializable;
/**
* @author Starrier
* @date 2019/1/9.
*/
-@Accessors(chain = true)
-@NoArgsConstructor
-@Getter
-@Setter
-@ToString
public class PaginatedResult implements Serializable {
private static final long serialVersionUID = 6191745064790884707L;
+
+ private PaginatedResult(){}
+
/**
* Current page number
*/
@@ -35,4 +27,40 @@ public class PaginatedResult implements Serializable {
*/
private Object data;
+ public static long getSerialVersionUID() {
+ return serialVersionUID;
+ }
+
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(int currentPage) {
+ this.currentPage = currentPage;
+ }
+
+ public int getTotalPage() {
+ return totalPage;
+ }
+
+ public void setTotalPage(int totalPage) {
+ this.totalPage = totalPage;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ @Override
+ public String toString() {
+ return "PaginatedResult{" +
+ "currentPage=" + currentPage +
+ ", totalPage=" + totalPage +
+ ", data=" + data +
+ '}';
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/starrier/common/page/ParameterInvalidItem.java b/src/main/java/org/starrier/common/page/ParameterInvalidItem.java
index 43de186..0eff820 100644
--- a/src/main/java/org/starrier/common/page/ParameterInvalidItem.java
+++ b/src/main/java/org/starrier/common/page/ParameterInvalidItem.java
@@ -1,9 +1,5 @@
package org.starrier.common.page;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
import java.io.Serializable;
/**
@@ -12,13 +8,27 @@
* @author Starrier
* @date 2019/1/31.
*/
-@Getter
-@Setter
-@NoArgsConstructor
public class ParameterInvalidItem implements Serializable {
private String fieldName;
private String message;
+ private ParameterInvalidItem(){}
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
}
diff --git a/src/main/java/org/starrier/common/page/ResourceNotFoundException.java b/src/main/java/org/starrier/common/page/ResourceNotFoundException.java
index 378d15c..7db839d 100644
--- a/src/main/java/org/starrier/common/page/ResourceNotFoundException.java
+++ b/src/main/java/org/starrier/common/page/ResourceNotFoundException.java
@@ -1,17 +1,11 @@
package org.starrier.common.page;
-import lombok.AllArgsConstructor;
-import lombok.Setter;
-import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
/**
* @author Starrier
* @date 2018/6/5.
*/
-@Setter
-@Accessors(chain = true)
-@AllArgsConstructor
public class ResourceNotFoundException extends RuntimeException {
private static final long serialVersionUID = -2565431806475335331L;
@@ -20,6 +14,11 @@ public class ResourceNotFoundException extends RuntimeException {
private final Long id;
+ public ResourceNotFoundException(String resourceName, Long id) {
+ this.resourceName = resourceName;
+ this.id = id;
+ }
+
@Override
public String getMessage() {
return StringUtils.capitalize(resourceName) + " with id " + id + " is not found.";
diff --git a/src/main/java/org/starrier/common/result/Result.java b/src/main/java/org/starrier/common/result/Result.java
index f8f2aa1..ff213c1 100644
--- a/src/main/java/org/starrier/common/result/Result.java
+++ b/src/main/java/org/starrier/common/result/Result.java
@@ -1,16 +1,10 @@
package org.starrier.common.result;
import com.google.common.collect.Maps;
-import lombok.AccessLevel;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.ToString;
-import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Map;
+import java.util.Objects;
/**
*
Api Response Code Wrapper
@@ -20,12 +14,6 @@
* @date 2018/11/11.
* @see Result is the enhanced and custom version of response.
*/
-@Accessors(chain = true)
-@Setter
-@Getter
-@ToString
-@AllArgsConstructor
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Result implements Serializable {
private static final long serialVersionUID = -1709587390161841001L;
@@ -38,6 +26,8 @@ public class Result implements Serializable {
private Object data;
+ private Result(){
+ }
public Result(Integer errorCode, String errMessage) {
this.code = errorCode;
this.message = errMessage;
@@ -50,6 +40,13 @@ private Result(Builder builder) {
this.url = builder.url;
}
+ public Result(Integer code, String message, String url, Object data) {
+ this.code = code;
+ this.message = message;
+ this.url = url;
+ this.data = data;
+ }
+
public static Result success() {
Result result = new Result();
result.setResultCode(ResultCode.SUCCESS);
@@ -100,6 +97,26 @@ public static Builder builder() {
return new Builder();
}
+ public static long getSerialVersionUID() {
+ return serialVersionUID;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ private void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
public Integer getCode() {
return code;
}
@@ -119,7 +136,23 @@ public Map simple() {
return simple;
}
- @ToString
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Result result = (Result) o;
+ return code.equals(result.code) &&
+ message.equals(result.message) &&
+ url.equals(result.url) &&
+ data.equals(result.data);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(code, message, url, data);
+ }
+
+
public static class Builder {
private Integer code;
private String message;
@@ -149,5 +182,15 @@ public Builder url(String url) {
public Result build() {
return new Result(this);
}
+
+ @Override
+ public String toString() {
+ return "Builder{" +
+ "code=" + code +
+ ", message='" + message + '\'' +
+ ", url='" + url + '\'' +
+ ", data=" + data +
+ '}';
+ }
}
}
diff --git a/src/main/java/org/starrier/common/token/DESBuilder.java b/src/main/java/org/starrier/common/token/DESBuilder.java
index 9518238..68cfd7c 100644
--- a/src/main/java/org/starrier/common/token/DESBuilder.java
+++ b/src/main/java/org/starrier/common/token/DESBuilder.java
@@ -1,7 +1,5 @@
package org.starrier.common.token;
-import lombok.Getter;
-import lombok.Setter;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.KeyGenerator;
@@ -21,11 +19,16 @@
*/
public class DESBuilder {
-
- @Getter
- @Setter
private Key key;
+ public Key getKey() {
+ return key;
+ }
+
+ public void setKey(Key key) {
+ this.key = key;
+ }
+
/**
* 构造函数.
*
diff --git a/src/main/java/org/starrier/common/token/DESCoder.java b/src/main/java/org/starrier/common/token/DESCoder.java
index 5266a74..3ee4349 100644
--- a/src/main/java/org/starrier/common/token/DESCoder.java
+++ b/src/main/java/org/starrier/common/token/DESCoder.java
@@ -1,11 +1,13 @@
package org.starrier.common.token;
-import lombok.SneakyThrows;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
+import java.security.InvalidKeyException;
import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
import static org.starrier.common.token.TokenConstant.KEY_ALGORTHM;
@@ -17,15 +19,13 @@
*/
public class DESCoder {
- @SneakyThrows(Exception.class)
- private Key toKey(byte[] key) {
+ private Key toKey(byte[] key) throws InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException {
DESKeySpec dks = new DESKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(KEY_ALGORTHM);
return keyFactory.generateSecret(dks);
}
- @SneakyThrows(Exception.class)
- public Key toKey(String key) {
+ public Key toKey(String key) throws InvalidKeySpecException, InvalidKeyException, NoSuchAlgorithmException {
byte[] keyBytes = Base64.decodeBase64(key);
return toKey(keyBytes);
}
diff --git a/src/main/java/org/starrier/common/token/TokenUtils.java b/src/main/java/org/starrier/common/token/TokenUtils.java
index 126e868..f94f34a 100644
--- a/src/main/java/org/starrier/common/token/TokenUtils.java
+++ b/src/main/java/org/starrier/common/token/TokenUtils.java
@@ -4,8 +4,10 @@
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
-import lombok.NonNull;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
@@ -28,7 +30,8 @@ public class TokenUtils {
* @param claims
* @return
*/
- public static String generateToken(Map claims) {
+ public static String generateToken(Map claims) throws InvalidKeySpecException, InvalidKeyException,
+ NoSuchAlgorithmException {
return Jwts.builder()
.setClaims(claims)
.setExpiration(new Date(System.currentTimeMillis() + 30000L))
@@ -42,7 +45,8 @@ public static String generateToken(Map claims) {
* @param token 要解析的token信息
* @return
*/
- private static Optional getClaimsFromToken(String token) {
+ private static Optional getClaimsFromToken(String token) throws InvalidKeySpecException, InvalidKeyException,
+ NoSuchAlgorithmException {
return Optional.ofNullable(Jwts.parser()
.setSigningKey(new DESCoder().toKey(SECRET))
.parseClaimsJws(token)
@@ -66,12 +70,13 @@ public static boolean isExpired(String token) throws Exception {
* @param token 要解析的token信息
* @return
*/
- private static Map extractInfo(String token) {
+ private static Map extractInfo(String token) throws InvalidKeySpecException, InvalidKeyException,
+ NoSuchAlgorithmException {
Optional claims = getClaimsFromToken(token);
if (claims.isPresent()) {
Set keySet = claims.get().keySet();
Map info = Maps.newHashMapWithExpectedSize(keySet.size());
- keySet.forEach((@NonNull String key) -> info.put(key, claims.get().get(key)));
+ keySet.forEach(key -> info.put(key, claims.get().get(key)));
return info;
}
return Collections.emptyMap();
diff --git a/src/main/java/org/starrier/common/utils/DateUtils.java b/src/main/java/org/starrier/common/utils/DateUtils.java
index f7daed0..561b89a 100644
--- a/src/main/java/org/starrier/common/utils/DateUtils.java
+++ b/src/main/java/org/starrier/common/utils/DateUtils.java
@@ -1,7 +1,6 @@
package org.starrier.common.utils;
import com.google.common.collect.Lists;
-import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.core.convert.converter.Converter;
@@ -112,10 +111,10 @@ public static String getDay(String date, int num) {
}
/**
- * @param date
+ * @param date 字符串日期
* @param num
* @param format
- * @return
+ * @return 字符串日期
*/
public static String getDay(String date, int num, String format) {
return getDay(parseStringToLong(date), num, DATE_FORMAT_DEFAULT);
@@ -124,9 +123,9 @@ public static String getDay(String date, int num, String format) {
/**
* 获取指定日期前后num天的日期
*
- * @param date
- * @param num
- * @return
+ * @param date 毫秒数
+ * @param num 指定距今的天数
+ * @return 字符串日期
*/
public static String getDay(long date, int num) {
return getDay(date, num, DATE_FORMAT_DEFAULT);
@@ -202,12 +201,14 @@ public static long getDayStartTime(String date) {
}
/**
+ *
+ * 2017年10月6日 下午5:58:58
* 获取指定日期结束时间
*
- * @param date
- * @return
+ * @param date 时间
+ * @return 毫秒数
* @author yangwenkui
- * @time 2017年10月6日 下午5:58:58
+ *
*/
public static long getDayEndTime(String date) {
Calendar cal = Calendar.getInstance();
@@ -323,22 +324,37 @@ private static long todayZeroTime() {
}
@Override
- public Date convert(String source) {
+ public Date convert(String source) {
String value = source.trim();
if (StringUtils.EMPTY.equals(value)) {
return null;
}
if (source.matches("^\\d{4}-\\d{1,2}$")) {
- return parseDate(source, FOR_MARTS.get(0));
+ try {
+ return parseDate(source, FOR_MARTS.get(0));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")) {
- return parseDate(source, FOR_MARTS.get(1));
- } else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")) {
- return parseDate(source, FOR_MARTS.get(2));
- } else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")) {
- return parseDate(source, FOR_MARTS.get(3));
- } else {
- throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
+ try {
+ return parseDate(source, FOR_MARTS.get(1));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ } else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}$")) {
+ try {
+ return parseDate(source, FOR_MARTS.get(2));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ } else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}$")) {
+ try {
+ return parseDate(source, FOR_MARTS.get(3));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
}
+ throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
}
/**
@@ -348,8 +364,7 @@ public Date convert(String source) {
* @param format String 格式
* @return Date 日期
*/
- @SneakyThrows(Exception.class)
- public Date parseDate(String dateStr, String format) {
+ public Date parseDate(String dateStr, String format) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.parse(dateStr);
}
diff --git a/src/main/java/org/starrier/common/utils/FetchSensitiveWordUtil.java b/src/main/java/org/starrier/common/utils/FetchSensitiveWordUtil.java
index ead1ea5..70e6250 100644
--- a/src/main/java/org/starrier/common/utils/FetchSensitiveWordUtil.java
+++ b/src/main/java/org/starrier/common/utils/FetchSensitiveWordUtil.java
@@ -1,13 +1,12 @@
package org.starrier.common.utils;
import com.google.common.collect.Maps;
-import lombok.Cleanup;
-import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
@@ -24,8 +23,7 @@ public class FetchSensitiveWordUtil {
* @param filePath {@link String}
* @return {@link Map }
*/
- @SneakyThrows(IOException.class)
- public Map fetchSensitiveWords(final String filePath) {
+ public Map fetchSensitiveWords(final String filePath) throws IOException {
Map wordsMaps = Maps.newHashMap();
File file = new File(filePath);
@@ -34,8 +32,8 @@ public Map fetchSensitiveWords(final String filePath) {
return new HashMap<>();
}
- @Cleanup InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
- @Cleanup BufferedReader bufferedReader = new BufferedReader(reader);
+ InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
+ BufferedReader bufferedReader = new BufferedReader(reader);
String lineText = null;
while ((lineText = bufferedReader.readLine()) != null) {
diff --git a/src/main/java/org/starrier/common/utils/PageUtil.java b/src/main/java/org/starrier/common/utils/PageUtil.java
index cc0a068..32d9059 100644
--- a/src/main/java/org/starrier/common/utils/PageUtil.java
+++ b/src/main/java/org/starrier/common/utils/PageUtil.java
@@ -1,6 +1,5 @@
package org.starrier.common.utils;
-import lombok.SneakyThrows;
import org.starrier.common.page.ParameterIllegalException;
/**
@@ -75,8 +74,7 @@ public static int parsePerPage(String perPageString, int defaultValue) {
* @param defaultValue default value, if parameterString == null
* @return parsed parameter
*/
- @SneakyThrows(ParameterIllegalException.class)
- private static int parseParameter(String parameterString, int defaultValue) {
+ private static int parseParameter(String parameterString, int defaultValue)throws ParameterIllegalException {
if (parameterString == null) {
return defaultValue;
} else {
diff --git a/src/main/java/org/starrier/common/utils/SensitiveWordUtil.java b/src/main/java/org/starrier/common/utils/SensitiveWordUtil.java
index 05940b3..1e8290d 100644
--- a/src/main/java/org/starrier/common/utils/SensitiveWordUtil.java
+++ b/src/main/java/org/starrier/common/utils/SensitiveWordUtil.java
@@ -1,8 +1,5 @@
package org.starrier.common.utils;
-import lombok.Getter;
-import lombok.Setter;
-
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -22,8 +19,6 @@
*
* Description :
*/
-@Getter
-@Setter
public class SensitiveWordUtil {
/**
@@ -282,5 +277,7 @@ private static int checkSensitiveWord(String txt, int beginIndex, int matchType)
}
return matchFlag;
}
+
+
}