Добавил Parser

This commit is contained in:
Struchkov Mark 2022-07-23 10:40:47 +03:00
parent c52ec11a4b
commit ae8391ccb8
10 changed files with 87 additions and 9 deletions

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti-bom</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
<packaging>pom</packaging>
<name>Haiti BOM</name>
@ -30,7 +30,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<haiti.ver>1.0.3</haiti.ver>
<haiti.ver>1.1.0</haiti.ver>
<haiti.exception.ver>${haiti.ver}</haiti.exception.ver>
<haiti.context.ver>${haiti.ver}</haiti.context.ver>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
</parent>
<artifactId>haiti-context</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
</parent>
<artifactId>haiti-core</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
</parent>
<artifactId>haiti-exception</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
</parent>
<artifactId>haiti-filter</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
</parent>
<name>Haiti Utils</name>

View File

@ -0,0 +1,38 @@
package dev.struchkov.haiti.utils;
import dev.struchkov.haiti.utils.domain.CompositeUrl;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static dev.struchkov.haiti.utils.Checker.checkNull;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public final class Parser {
private static Pattern URL_PARSE;
private Parser() {
utilityClass();
}
public static CompositeUrl url(String url) {
final Matcher matcher = getUrlParse().matcher(url);
matcher.find();
final String protocol = matcher.group(1);
final String domain = matcher.group(2);
final String port = matcher.group(3);
final String path = matcher.group(4);
return CompositeUrl.of(protocol, domain, port, path);
}
private static Pattern getUrlParse() {
if (checkNull(URL_PARSE)) {
URL_PARSE = Pattern.compile("(https?://)([^:^/]*)(:\\d*)?(.*)?");
}
return URL_PARSE;
}
}

View File

@ -0,0 +1,39 @@
package dev.struchkov.haiti.utils.domain;
import java.util.Optional;
public class CompositeUrl {
private final String protocol;
private final String domain;
private final String port;
private final String path;
private CompositeUrl(String protocol, String domain, String port, String path) {
this.protocol = protocol;
this.domain = domain;
this.port = port;
this.path = path;
}
public static CompositeUrl of(String protocol, String domain, String port, String path) {
return new CompositeUrl(protocol, domain, port, path);
}
public Optional<String> getProtocol() {
return Optional.ofNullable(protocol);
}
public Optional<String> getDomain() {
return Optional.ofNullable(domain);
}
public Optional<String> getPort() {
return Optional.ofNullable(port);
}
public Optional<String> getPath() {
return Optional.ofNullable(path);
}
}

View File

@ -1,5 +1,6 @@
module haiti.utils {
exports dev.struchkov.haiti.utils;
exports dev.struchkov.haiti.utils.domain;
requires haiti.exception;
}

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.haiti</groupId>
<artifactId>haiti</artifactId>
<version>1.0.3</version>
<version>1.1.0</version>
<packaging>pom</packaging>
<name>Haiti Framework</name>
@ -39,7 +39,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<haiti.ver>1.0.3</haiti.ver>
<haiti.ver>1.1.0</haiti.ver>
<haiti.bom.ver>${haiti.ver}</haiti.bom.ver>
<haiti.exception.ver>${haiti.ver}</haiti.exception.ver>