You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

4 months ago
## Breakdown URL
### Instructions
4 months ago
Create a class `BreakdownURL` that provides a method to parse and validate URLs using regex.The method should extract and return the following URL components: `protocol`, `domain`, `port`, `path` and `query`
Assume the URL is always correct.
The method should extract and return URL components the parameters. The URL is always correct.
4 months ago
> Give back in the map just the existing component.
### Expected Class
```java
4 months ago
public class BreakdownURL {
public Map<String, String> parseURL(String url) {
// Implementation to parse and validate URLs using regex
}
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your class:
```java
import java.util.Map;
public class ExerciseRunner {
public static void main(String[] args) {
4 months ago
BreakdownURL parser = new BreakdownURL();
// Test case 1
4 months ago
String URL1 = "https://www.example.com:8080/path?name=value";
Map<String, String> components1 = parser.parseURL(URL1);
System.out.println("Components of URL 1: " + components1);
// Test case 2
4 months ago
String URL2 = "http://example.com/";
Map<String, String> components2 = parser.parseURL(URL2);
System.out.println("Components of URL 2: " + components2);
}
}
```
### Expected Output
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Components of URL 1: {protocol=https, domain=www.example.com, port=8080, path=/path, query=name=value}
Components of URL 2: {protocol=http, domain=example.com, path=/}
$
```