-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Browser README.md 작성
- Loading branch information
ziponia
committed
Sep 17, 2019
1 parent
8f330b6
commit 816a3ca
Showing
7 changed files
with
239 additions
and
89 deletions.
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
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,53 @@ | ||
# Utility Component | ||
|
||
## Getting Start | ||
|
||
```xml | ||
<dependency> | ||
<groupId>com.github.ziponia.lib</groupId> | ||
<artifactId>util</artifactId> | ||
<version>{library version}</version> | ||
</dependency> | ||
``` | ||
|
||
_Gradle_ | ||
|
||
```groovy | ||
implementation 'com.github.ziponia.lib:util:{library version}' | ||
``` | ||
|
||
## Browser | ||
|
||
class `DateUtilComponent` | ||
|
||
날짜 관련 컴포넌트 | ||
|
||
| method | param | return | description | | ||
| :------------- | :------------------ | :------------- | :------------------------------------------- | | ||
| toAfterMinute | java.util.Date, int | java.util.Date | 기준 이후의 분 시점을 반환합니다. | | ||
| toBeforeMinute | java.util.Date, int | java.util.Date | 기준 이전의 분 시점을 반환합니다. | | ||
| lastDate | java.util.Date | int | Date 객체 기준으로 마지막 날짜를 반환합니다. | | ||
| lastDate | int, int | int | 년, 월 기준으로 마지막 날을 반환합니다. | | ||
|
||
class `VerifyUtilComponent` | ||
|
||
검증 관련 컴포넌트 | ||
|
||
| method | param | return | description | | ||
| :-------------------------------- | :----- | :------ | :-------------------------------------------- | | ||
| passwordThen8AndSpecialCharacters | String | boolean | 최소 8 자 이상, 숫자, 특수문자 1개이상씩 포함 | | ||
| checkCellphone | String | boolean | 휴대폰번호 유효성 체크 | | ||
| checkLicenseValidity | String | boolean | 운전 면허번호 유효성 체크 | | ||
|
||
class `UtilComponent` | ||
|
||
기본 유틸리티 컴포넌트 | ||
|
||
| method | param | return | description | | ||
| :-------------------------------- | :----------------------------- | :----- | :--------------------------------------------------------------- | | ||
| keyGenerator | int, boolean | String | 랜덤키를 만듭니다, 두번째 인자가 true 면, 숫자로만 만듭니다. | | ||
| byteArrayToBinaryString | byte[] | String | 바이너리 바이트 배열을 스트링으로 변환 | | ||
| byteToBinaryString | byte | String | 바이너리 바이트를 스트링으로 변환 | | ||
| binaryStringToByteArray | String | byte[] | 바이너리 스트링을 바이트배열로 변환 | | ||
| binaryStringToByte | String | byte | 바이너리 스트링을 바이트로 변환 | | ||
| calculationDistanceFromGeographic | double, double, double, double | double | 위도, 경도를 사용하여 시작점과 끝점의 거리를 구합니다. (단위 km) | |
57 changes: 57 additions & 0 deletions
57
util/src/main/java/com/ziponia/util/DateUtilComponent.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,57 @@ | ||
package com.ziponia.util; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
public class DateUtilComponent { | ||
|
||
/** | ||
* currentDate 기준 이후의 분 시점을 반환합니다. | ||
* | ||
* @param currentDate 변환 할 시간 | ||
* @param afterMinute 변환 할 시점 | ||
* @return java.util.Date | ||
*/ | ||
public static Date toAfterMinute(Date currentDate, int afterMinute) { | ||
int targetTime = 60 * afterMinute * 1000; // 초 | ||
return new Date(currentDate.getTime() + targetTime); | ||
} | ||
|
||
/** | ||
* currentDate 기준 이전의 분 시점을 반환합니다. | ||
* | ||
* @param currentDate 변환 할 시간 | ||
* @param beforeMinute 변환 할 시점 | ||
* @return java.util.Date | ||
*/ | ||
public static Date toBeforeMinute(Date currentDate, int beforeMinute) { | ||
int targetTime = 60 * beforeMinute * 1000; // 초 | ||
return new Date(currentDate.getTime() - targetTime); | ||
} | ||
|
||
/** | ||
* Date 객체 기준으로 마지막 날짜를 반환합니다. | ||
* | ||
* @param date 기준일이 될 Date | ||
* @return 마지막 날짜. | ||
*/ | ||
public static int lastDate(Date date) { | ||
Calendar cal = Calendar.getInstance(); | ||
cal.setTime(date); | ||
return cal.getActualMaximum(Calendar.DATE); | ||
} | ||
|
||
/** | ||
* 년, 월 기준으로 마지막 날을 반환합니다. | ||
* | ||
* @param year 기준 년 | ||
* @param month 기준 월 (ex, 8월 -> month = 8, -1 아닙니다.) | ||
* @return 마지막 날짜. | ||
*/ | ||
public static int lastDate(int year, int month) { | ||
Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.YEAR, year); | ||
cal.set(Calendar.MONTH, month - 1); | ||
return cal.getActualMaximum(Calendar.DATE); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
util/src/main/java/com/ziponia/util/VerifyUtilComponent.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,58 @@ | ||
package com.ziponia.util; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class VerifyUtilComponent { | ||
|
||
/** | ||
* 패스워드 정규식 | ||
* 최소 8 자 이상, 숫자, 특수문자 1개이상씩 포함 | ||
* | ||
* @param password 체크 할 비밀번호 평문 | ||
* @return boolean | ||
*/ | ||
public static boolean passwordThen8AndSpecialCharacters(String password) { | ||
Pattern p = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$"); | ||
Matcher m = p.matcher(password); | ||
return m.matches(); | ||
} | ||
|
||
/** | ||
* 휴대폰번호 유효성 체크 | ||
* | ||
* @param str 휴대폰번호 | ||
* @return boolean | ||
*/ | ||
public static boolean checkCellphone(String str) { | ||
//010, 011, 016, 017, 018, 019 | ||
return str.matches("(01[016789])-(\\d{3,4})-(\\d{4})"); | ||
} | ||
|
||
/** | ||
* 운전 면허번호 유효성 체크 | ||
* 지역명이 포함된 운전면허번호 조회시 경북-95-255933-61 방식으로 넘깁니다. | ||
* 숫자만 포함된 운전면허번호 조회시에도 19-95-255933-61 방식으로 통일합니다. | ||
* | ||
* @param licenseNo 유효성을 체크할 면허번호를 입력합니다. | ||
* @return boolean | ||
*/ | ||
public static boolean checkLicenseValidity(String licenseNo) { | ||
|
||
String regex = ".*[ㄱ-ㅎㅏ-ㅣ가-힣]+.*"; //한글이 포함되어 있는 운전면허번호 구분 | ||
|
||
Pattern pattern = Pattern.compile(regex); | ||
Matcher matcher = pattern.matcher(licenseNo); | ||
|
||
if (matcher.matches()) { | ||
String regex1 = "^([가-힣]{2}(\\s|-)?|[가-힣]{2}-?)(\\s|-)?\\d{2}(\\s|-)?\\d{6}(\\s|-)?\\d{2}$"; //지역명 포함 운전면허번호 | ||
pattern = Pattern.compile(regex1); | ||
} else { | ||
String regex2 = "^((1[1-9])|(2[0-6])|(26)|(28))(\\s|-)?\\d{2}(\\s|-)?\\d{6}(\\s|-)?\\d{2}$"; //숫자만 포함 운전면허번호 | ||
pattern = Pattern.compile(regex2); | ||
} | ||
|
||
matcher = pattern.matcher(licenseNo); | ||
return matcher.matches(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
util/src/test/java/com/ziponia/util/DateUtilComponentTest.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,42 @@ | ||
package com.ziponia.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import java.util.Calendar; | ||
|
||
@RunWith(JUnit4.class) | ||
public class DateUtilComponentTest { | ||
|
||
@Test | ||
public void dateLastTest() { | ||
|
||
int year = 2018; | ||
int month = 2; | ||
|
||
Calendar cal = Calendar.getInstance(); | ||
cal.set(Calendar.YEAR, year); | ||
cal.set(Calendar.MONTH, month - 1); | ||
int last = DateUtilComponent.lastDate(cal.getTime()); | ||
|
||
System.out.println(String.format("%d 년 %d월 의 마지막날은 %d일 입니다.", year, month - 1, last)); | ||
|
||
// 2018 년 2월은 28 일까지 입니다. | ||
Assert.assertEquals(28, last); | ||
} | ||
|
||
@Test | ||
public void dateLastByYM() { | ||
int year = 2019; | ||
int month = 6; | ||
|
||
int last = DateUtilComponent.lastDate(year, month); | ||
|
||
System.out.println(String.format("%d 년 %d월 의 마지막날은 %d일 입니다.", year, month, last)); | ||
|
||
// 2019 년 6월은 30 일까지 입니다. | ||
Assert.assertEquals(30, last); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
util/src/test/java/com/ziponia/util/VerifyUtilComponentTest.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,28 @@ | ||
package com.ziponia.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class VerifyUtilComponentTest { | ||
|
||
@Test | ||
public void passwordThen8AndSpecialCharactersTest() { | ||
|
||
// only number length 4 | ||
boolean p1 = VerifyUtilComponent.passwordThen8AndSpecialCharacters("1234"); | ||
|
||
// number is not found | ||
boolean p2 = VerifyUtilComponent.passwordThen8AndSpecialCharacters("p@sswordsIsTrue"); | ||
|
||
// Special Characters is not found | ||
boolean p3 = VerifyUtilComponent.passwordThen8AndSpecialCharacters("passwordIsTrue78"); | ||
|
||
// Good Password | ||
boolean p4 = VerifyUtilComponent.passwordThen8AndSpecialCharacters("p@ss3WordIl0veU"); | ||
|
||
Assert.assertFalse(p1); | ||
Assert.assertFalse(p2); | ||
Assert.assertFalse(p3); | ||
Assert.assertTrue(p4); | ||
} | ||
} |