Skip to content

Commit

Permalink
doc: Write JavaDoc and comments for UrlMappingPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Jul 5, 2023
1 parent cf6aac3 commit 22d6748
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Represents a URL mapping pattern for routing purposes.
* The pattern can include variable path parameters or query strings.
*/

public class UrlMappingPattern {

private static final String URL_PARAMETER_REGEX = "\\{(\\w*?)\\}";
Expand Down Expand Up @@ -55,6 +60,13 @@ public String getMappingPattern() {
return urlMappingPattern.replaceFirst(URL_FORMAT_REGEX, "");
}

/**
* Extracts path parameters from the given URL and returns a {@link Map} of parameter names to values.
*
* @param url the URL from which to extract path parameters
* @return a {@link Map} containing path parameter names and their corresponding values,
* or null if the URL does not match the defined URL mapping pattern
*/
public Map<String, String> extractPathParameterValues(String url) {
Matcher matcher = compiledUrlMappingPattern.matcher(url);
if (matcher.matches()) {
Expand All @@ -81,6 +93,12 @@ private void acquireParamNames() {
}
}

/**
* Extracts parameters from the provided {@link Matcher} object and returns a {@link Map} of parameter names to values.
*
* @param matcher the Matcher object used to match and capture parameter values
* @return a {@link Map} containing parameter names and their corresponding values
*/
private Map<String, String> extractParameters(Matcher matcher) {
Map<String, String> values = new HashMap<>((int) (matcher.groupCount() / 0.75f + 1));
for (int i = 0; i < matcher.groupCount(); i++) {
Expand Down

0 comments on commit 22d6748

Please sign in to comment.