Change type of ExecutorURI value to URI

This commit is contained in:
2021-11-04 17:23:49 +01:00
parent 06172b34cd
commit 5606de7c26
2 changed files with 5 additions and 21 deletions

View File

@@ -1,23 +1,13 @@
package ch.unisg.common.valueobject;
import ch.unisg.common.exception.InvalidExecutorURIException;
import java.net.URI;
import lombok.Value;
@Value
public class ExecutorURI {
private String value;
private URI value;
public ExecutorURI(String uri) throws InvalidExecutorURIException {
String ip = uri.split(":")[0];
int port = Integer.parseInt(uri.split(":")[1]);
// Check if valid ip4
if (!ip.equalsIgnoreCase("localhost") &&
!uri.matches("^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)(\\.(?!$)|$)){4}$")) {
throw new InvalidExecutorURIException();
// Check if valid port
} else if (port < 1024 || port > 65535) {
throw new InvalidExecutorURIException();
}
this.value = uri;
public ExecutorURI(String uri) {
this.value = URI.create(uri);
}
}