Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy routes with final classes and remove unnecessary public access #91

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public final class CtxServiceManager implements SpiServiceManager {

private final String scheme;
private final String contextPath;

private final SpiServiceManager delegate;

CtxServiceManager(SpiServiceManager delegate, String scheme, String contextPath) {
Expand Down
14 changes: 7 additions & 7 deletions avaje-jex/src/main/java/io/avaje/jex/routes/PathParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class PathParser {
final class PathParser {

private final String rawPath;
private final List<String> paramNames = new ArrayList<>();
Expand Down Expand Up @@ -33,11 +33,11 @@ class PathParser {
this.literal = segmentCount > 1 && regBuilder.literal();
}

public boolean matches(String url) {
boolean matches(String url) {
return matchRegex.matcher(url).matches();
}

public Map<String, String> extractPathParams(String uri) {
Map<String, String> extractPathParams(String uri) {
Map<String, String> pathMap = new LinkedHashMap<>();
final List<String> values = values(uri);
for (int i = 0; i < values.size(); i++) {
Expand Down Expand Up @@ -70,28 +70,28 @@ private PathSegment parseSegment(String segment) {
/**
* Return the raw path that was parsed (match path).
*/
public String raw() {
String raw() {
return rawPath;
}

/**
* Return the number of path segments.
*/
public int segmentCount() {
int segmentCount() {
return segmentCount;
}

/**
* Return true if one of the segments is wildcard or slash accepting.
*/
public boolean multiSlash() {
boolean multiSlash() {
return multiSlash;
}

/**
* Return true if all path segments are literal.
*/
public boolean literal() {
boolean literal() {
return literal;
}
}
10 changes: 5 additions & 5 deletions avaje-jex/src/main/java/io/avaje/jex/routes/PathSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ boolean multiSlash() {
return false;
}

static class SlashIgnoringParameter extends Parameter {
static final class SlashIgnoringParameter extends Parameter {
SlashIgnoringParameter(String param) {
super(param, "[^/]+?"); // Accepting everything except slash;);
}
}

static class SlashAcceptingParameter extends Parameter {
static final class SlashAcceptingParameter extends Parameter {
SlashAcceptingParameter(String param) {
super(param, ".+?"); // Accept everything
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public void addParamName(List<String> paramNames) {
}
}

static class Multi extends PathSegment {
static final class Multi extends PathSegment {

private final List<PathSegment> segments;

Expand Down Expand Up @@ -93,7 +93,7 @@ void addParamName(List<String> paramNames) {
}
}

static class Literal extends PathSegment {
static final class Literal extends PathSegment {
private final String content;

Literal(String content) {
Expand All @@ -116,7 +116,7 @@ public void addParamName(List<String> paramNames) {
}
}

static class Wildcard extends PathSegment {
static final class Wildcard extends PathSegment {

@Override
boolean multiSlash() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import static java.util.stream.Collectors.toList;

class PathSegmentParser {
final class PathSegmentParser {

private static final PathSegment WILDCARD = new PathSegment.Wildcard();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Helper for PathParser to build regex for the path.
*/
class RegBuilder {
final class RegBuilder {
private final StringJoiner full = new StringJoiner("/");
private final StringJoiner extract = new StringJoiner("/");
private boolean trailingSlash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.avaje.jex.ExchangeHandler;
import io.avaje.jex.security.Role;

class RouteEntry implements SpiRoutes.Entry {
final class RouteEntry implements SpiRoutes.Entry {

private final AtomicLong active = new AtomicLong();
private final PathParser path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

class RouteIndex {
final class RouteIndex {

/**
* Partition entries by the number of path segments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.EnumMap;
import java.util.List;

public class RoutesBuilder {
public final class RoutesBuilder {

private final EnumMap<Routing.Type, RouteIndex> typeMap = new EnumMap<>(Routing.Type.class);
private final boolean ignoreTrailingSlashes;
Expand Down
13 changes: 5 additions & 8 deletions avaje-jex/src/main/java/io/avaje/jex/routes/UrlDecode.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.avaje.jex.routes;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class UrlDecode {
import static java.nio.charset.StandardCharsets.UTF_8;

public static String decode(String s) {
try {
return URLDecoder.decode(s.replace("+", "%2B"), "UTF-8").replace("%2B", "+");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Not expected", e);
}
final class UrlDecode {

static String decode(String s) {
return URLDecoder.decode(s.replace("+", "%2B"), UTF_8).replace("%2B", "+");
}

}