Skip to content

Commit

Permalink
add matcher constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrmffldrhrl committed Oct 29, 2020
1 parent c9c994c commit a44acde
Show file tree
Hide file tree
Showing 42 changed files with 179 additions and 147 deletions.
58 changes: 41 additions & 17 deletions src/main/java/com/github/wjrmffldrhrl/Area.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
package com.github.wjrmffldrhrl;

import com.github.wjrmffldrhrl.exception.InvalidIndexException;
import com.github.wjrmffldrhrl.exception.InvalidValueException;

import java.util.regex.Matcher;

/**
* String index area
* String slice util
*
* @author wjrmffldrhrl
*/
public class Area {

private final int start;
private final int end;
private final int length;

/**
* Constructor with int
* @param start int
* @param end int
* @throws InvalidValueException If try initialize with invalid value
* <h4>Invalid value list</h4>
* <li> Input under 0</li>
* <li> End value under then start value </li>
* <li> Area length 0</li>
*/
public Area(int start, int end) {
if(isInvalid(start, end)) { throw new InvalidValueException("Input valid value"); }
this.start = start;
this.end = end;
this.length = end - start;
}

/**
* Constructor
* @param startIndex int
* @param endIndex int
* Constructor with matcher
* @param matcher Need to available matcher
*/
public Area(int startIndex, int endIndex) {
if(startIndex < 0 || endIndex < 0) { throw new InvalidIndexException("Area index must over then 0"); }
if(startIndex > endIndex) { throw new InvalidIndexException("Start index must over then end index"); }
if(startIndex == endIndex) { throw new InvalidIndexException("Area length must over then 0"); }
this.start = startIndex;
this.end = endIndex;
public Area(Matcher matcher) {
this(matcher.start(), matcher.end());
}

/**
* Check index area overlap
* @param compareArea Area
* @return If compareArea index overlap with this Area : true
* else : false
* @return <li>If compareArea index overlap with this Area : true</li>
* <li>else : false</li>
*/
public boolean isOverlap(Area compareArea) {

Expand All @@ -49,7 +64,7 @@ public boolean isOverlap(Area compareArea) {
/**
* Check compareArea equals this area
* @param compareArea Area
* @return boolean
* @return Check is have same value
*/
public boolean equals(Area compareArea) {
return compareArea.getStart() == this.start && compareArea.getEnd() == this.end;
Expand All @@ -58,7 +73,7 @@ public boolean equals(Area compareArea) {

/**
* Get same index area
* @return Area
* @return New area instance what have same value
*/
@Override
public Area clone() {
Expand All @@ -67,15 +82,24 @@ public Area clone() {

/**
* Get start index
* @return int
* @return start value
*/
public int getStart() { return this.start; }

/**
* Get end index
* @return int
* @return end value
*/
public int getEnd() { return this.end; }

/**
* Get area length
* @return area length
*/
public int getLength() { return this.length; }


private boolean isInvalid(int startValue, int endValue) {
return startValue < 0 || endValue < 0 || startValue > endValue || startValue == endValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*
* @author wjrmffldrhrl
*/
public class InvalidIndexException extends RuntimeException{
public class InvalidValueException extends RuntimeException{
/**
* Throw InvalidIndexException
* @param e String
*/
public InvalidIndexException(String e) { super(e); }
public InvalidValueException(String e) { super(e); }
}
8 changes: 4 additions & 4 deletions src/test/java/Area/AreaTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package Area;

import com.github.wjrmffldrhrl.Area;
import com.github.wjrmffldrhrl.exception.InvalidIndexException;
import com.github.wjrmffldrhrl.exception.InvalidValueException;
import org.junit.Assert;
import org.junit.Test;

public class AreaTest {

@Test(expected = InvalidIndexException.class)
@Test(expected = InvalidValueException.class)
public void underZeroIndexTest() {
new Area(-1 , 4);
}

@Test(expected = InvalidIndexException.class)
@Test(expected = InvalidValueException.class)
public void inputInvalidIndexTest() {
new Area(6, 4);
}

@Test(expected = InvalidIndexException.class)
@Test(expected = InvalidValueException.class)
public void sameIndexTest() {
new Area(4 , 4);
}
Expand Down
Binary file removed target/Area-0.0.3-javadoc.jar
Binary file not shown.
14 changes: 0 additions & 14 deletions target/Area-0.0.3-javadoc.jar.asc

This file was deleted.

14 changes: 0 additions & 14 deletions target/Area-0.0.3-sources.jar.asc

This file was deleted.

Binary file removed target/Area-0.0.3.jar
Binary file not shown.
14 changes: 0 additions & 14 deletions target/Area-0.0.3.jar.asc

This file was deleted.

14 changes: 0 additions & 14 deletions target/Area-0.0.3.pom.asc

This file was deleted.

Binary file added target/Area-0.0.4-javadoc.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions target/Area-0.0.4-javadoc.jar.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEEoUmoWMxC4Oy+ly1Mn4PFuBvpcWkFAl+aF1IACgkQn4PFuBvp
cWnjawv/eE+d2Y4JcN+OciHiS7+mbWoxAuQ8LbjKl/aPr7QXxercK5Wv7oMgt++2
caVWFPHNNqlQkmEiSbORgmjIEVLgkY0dsIw/CzyPw0zYAM9t5gp5CBuTMSWPAGei
U25KG7QHmdrEUKCJhIdzktASikfBztcc+Xlfni+ILTPin5F1hpkdFY8RWAAzZTZa
ceeI1quDmXm3Xowj0m65BePk4rYiiMuIiESWc/p2Q1dcQtgujIzq/M91e1L20wh+
cuenVO9Vqfzx4do1jIVQd3AcYCm7Q//qTUC1ss6qGZzO/G5Qt2A04P7ze0616Ib3
wDqbr8AG7WpUab3HvaN50G6MmiXILXxp4JyxCDqNPe6TMSHyQ0ZLRszz4rmsEeLh
3pDdkvY3Po7v2BWVM7Dn/uHIyvKaNgUTe903aO49dgRpNB7ln/XhZwLK5O+FZtYT
GptORetKRwFtaHoCTZ84M+IdQpIePSvmHDTFKoRjZZiP7HK8PygpL9hFEc0Whvt2
i0Wi5igI
=HLDX
-----END PGP SIGNATURE-----
Binary file not shown.
14 changes: 14 additions & 0 deletions target/Area-0.0.4-sources.jar.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEEoUmoWMxC4Oy+ly1Mn4PFuBvpcWkFAl+aF1EACgkQn4PFuBvp
cWk4Hgv+O02WvJsx5k8F0mhfxIaySBnhgfY6U4D2SFzMvT2U+QbTn2CcNHPd2h3w
kIixyRebkg1KHopH8Um62Oxc1uQRsgIo7uYy5yg+pf85CgHUUyyn/2anb7YqlLqr
65pTz2AWxckqsUMcjpW4I8JbZEx8CGzJv4kMBY52U7a1CJLO/KkG9ftIrtS6TQUe
8FZ8dSjU6eRaLpB9Ew+FUWOiKLLggrsRRGwMX/92MN2Idfr/sdExJteBCcnKH2gg
pnHi/G4BqnuhFi85t1zxN/cTfwnOiuacwwo37dmdIT2ce6WRRHPT0b82xLm9YPov
zsHSmmCz1Xw5N+mJaja101Lp5PvN218gQWMsbu0aQkEt65lg25aqd5DOFSloiYCi
XR+BPIE7kEywiwIEc5KQS9Ji6YB+fPYkAvQTqej9iEwzuZrifSgYyaKDT1uGz+D7
1FRaHLEY3WQOQS6JAE/1jL7G/qoiYWSmmbdPj3NM0id6PL3s7giaQFwY/tNzZSKY
UtmjLzYT
=eNSv
-----END PGP SIGNATURE-----
Binary file added target/Area-0.0.4.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions target/Area-0.0.4.jar.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEEoUmoWMxC4Oy+ly1Mn4PFuBvpcWkFAl+aF1EACgkQn4PFuBvp
cWlmYwv/dFyDE66Q6Lu3TrLT2QxsCnzIKVhaQL215LLMqbE+w4K68qU9QvpaQKtE
UDEKokyofSCyFoSmHjBe5V3CgP6S8zBTNKpTftCplh/Uw4l4Rsi6cPRJC2C67e27
iMY8lVTsjTBziwZf6qyN3XX0/mv+ZtsSCPiXWkeo8lqVXCuHTyX19tFj+0KEgGaQ
XlRlaDU1AHBDSSJWeVNJZtWajFO06lsoAjYfVP9neaYK34AaR74r1Rb4mHwDezhu
583o9gm21QlVhtVPKiVGklMtTDL2Ym68pmxQ739ihs6bVSEIyKXkwG5hBlVDEDdB
bO/OH54jKqcZG4tigH21kE00OL43a3Dx5tAFbIDUW/7CLgb2EqGtajxfv2a24/jI
xx9xEb3lND/SQYZXihScVyqNJgoKGExoZPBxbnmPBAiYGa3DsWgSYNJu7le5Saf8
9k+5WP4yuNlY2Ph70JLnX9GV9CMKFnkV4TMDup830mat7c8zy1X2EEPD0e5pkTPF
jM+oTr1u
=jT7M
-----END PGP SIGNATURE-----
10 changes: 9 additions & 1 deletion target/Area-0.0.3.pom → target/Area-0.0.4.pom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.wjrmffldrhrl</groupId>
<artifactId>Area</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>
<packaging>jar</packaging>

<name>Area</name>
Expand All @@ -16,6 +16,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://opensource.org/licenses/Apache-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
Expand Down
14 changes: 14 additions & 0 deletions target/Area-0.0.4.pom.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP SIGNATURE-----

iQGzBAABCAAdFiEEoUmoWMxC4Oy+ly1Mn4PFuBvpcWkFAl+aF1EACgkQn4PFuBvp
cWmWSQwAhDob0IdaWeFroWeGU6DTA4R9h4OOsuJ6DeFigjGLjm+YnVHjVhy9tdRv
+8LoKuTgE/ErXUB0BV0GJBswiuz9mQnt701Jo2bPLVOgueLjqAcT9zNOrD2N3Bd0
0Rc9V8wrNEXowO4EQcm17ThsmQCaxmFIRb4mywegqSzhSo3xwNQWW39qpx4ZyKeU
oKGEhb4uCKvLWcEY70yCHNKbBx/nsoIE2gC+0cjz2lG+rWkebWJ2HgZzWiFQk71M
H7fNMjarphHPkb/lOPRGXm0sqT0LSKyP1K7hoIE5R4uoOluDK3sVyLjHpuDaBgG4
vbslkeRw8Ws7DqfcO2cgxFQquITR7S9wlaQqQf/44cKldhuGQS5CY+H53cKOVrlm
BR15uRCCmmDPT/Hx+jx1wVpyK0gUdId4zZJZyamRjqfujGVTqVpzagEk+3nc4+Im
byvdFv/oboDjfWWfROnF8XwbIyRq+E68/FyupbSHbwePYhzyoVtAMwZpDuSGgCUa
f4Olf0jJ
=tW8z
-----END PGP SIGNATURE-----
4 changes: 2 additions & 2 deletions target/apidocs/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="ko">
<head>
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 09:53:41 KST 2020 -->
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 10:13:35 KST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (Area 0.0.3 API)</title>
<title>All Classes (Area 0.0.4 API)</title>
<meta name="date" content="2020-10-29">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions target/apidocs/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="ko">
<head>
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 09:53:41 KST 2020 -->
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 10:13:35 KST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>All Classes (Area 0.0.3 API)</title>
<title>All Classes (Area 0.0.4 API)</title>
<meta name="date" content="2020-10-29">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions target/apidocs/com/github/wjrmffldrhrl/Area.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="ko">
<head>
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 09:53:40 KST 2020 -->
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 10:13:34 KST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Area (Area 0.0.3 API)</title>
<title>Area (Area 0.0.4 API)</title>
<meta name="date" content="2020-10-29">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
Expand All @@ -13,7 +13,7 @@
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Area (Area 0.0.3 API)";
parent.document.title="Area (Area 0.0.4 API)";
}
}
catch(err) {
Expand Down
6 changes: 3 additions & 3 deletions target/apidocs/com/github/wjrmffldrhrl/class-use/Area.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="ko">
<head>
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 09:53:41 KST 2020 -->
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 10:13:35 KST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uses of Class com.github.wjrmffldrhrl.Area (Area 0.0.3 API)</title>
<title>Uses of Class com.github.wjrmffldrhrl.Area (Area 0.0.4 API)</title>
<meta name="date" content="2020-10-29">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
Expand All @@ -13,7 +13,7 @@
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Uses of Class com.github.wjrmffldrhrl.Area (Area 0.0.3 API)";
parent.document.title="Uses of Class com.github.wjrmffldrhrl.Area (Area 0.0.4 API)";
}
}
catch(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="ko">
<head>
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 09:53:40 KST 2020 -->
<!-- Generated by javadoc (1.8.0_261) on Thu Oct 29 10:13:34 KST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>InvalidIndexException (Area 0.0.3 API)</title>
<title>InvalidIndexException (Area 0.0.4 API)</title>
<meta name="date" content="2020-10-29">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
Expand All @@ -13,7 +13,7 @@
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="InvalidIndexException (Area 0.0.3 API)";
parent.document.title="InvalidIndexException (Area 0.0.4 API)";
}
}
catch(err) {
Expand Down
Loading

0 comments on commit a44acde

Please sign in to comment.