-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/sirius/spurt/common/validator/QuestionValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.sirius.spurt.common.validator; | ||
|
||
import static com.sirius.spurt.common.meta.ResultCode.QUESTION_THREE_SECONDS; | ||
|
||
import com.sirius.spurt.common.exception.GlobalException; | ||
import java.sql.Timestamp; | ||
|
||
public class QuestionValidator { | ||
private static long BOARD_DUPLICATE_TIME = 3000L; | ||
|
||
public static void validate(Timestamp timestamp) { | ||
if (isWithin3SecondsDifference(timestamp)) { | ||
throw new GlobalException(QUESTION_THREE_SECONDS); | ||
} | ||
} | ||
|
||
private static boolean isWithin3SecondsDifference(Timestamp timestamp) { | ||
return new Timestamp(System.currentTimeMillis()).getTime() - timestamp.getTime() < BOARD_DUPLICATE_TIME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters