Skip to content

Commit

Permalink
Seal Internal Classes (#12)
Browse files Browse the repository at this point in the history
* seal internal classes

* Google Java Format

* Update README.md

---------

Co-authored-by: github-actions <>
  • Loading branch information
SentryMan authored Nov 7, 2024
1 parent 1e4ed8e commit 3fabc34
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class LambdaRequestHandler
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-api</artifactId>
<version>2.8-RC3</version>
<version>2.8</version>
</dependency>

<!-- Annotation processor -->
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-sigma-generator</artifactId>
<version>2.8-RC3</version>
<version>2.8</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.avaje.sigma.routes.SpiRoutes;
import java.util.Map;

class DSigmaFunction implements Sigma.HttpFunction {
final class DSigmaFunction implements Sigma.HttpFunction {

private final SpiRoutes routes;
private final ServiceManager manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import java.util.List;
import java.util.Map;

/** */
class DefaultRouting implements Router {
final class DefaultRouting implements Router {

private static final String SLASH = "/";
private final List<Router.Entry> handlers = new ArrayList<>();
Expand Down Expand Up @@ -45,8 +44,7 @@ public Router addAll(Collection<HttpService> routes) {
}

private void add(HttpMethod verb, String path, Handler handler) {
Entry lastEntry;
lastEntry = new Entry(verb, path(path), handler);
Entry lastEntry = new Entry(verb, path(path), handler);
handlers.add(lastEntry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.avaje.sigma.body.BodyMapper;

/** Core implementation of SpiServiceManager provided to specific implementations like jetty etc. */
class ServiceManager {
final class ServiceManager {

private final Map<String, BodyMapper> mappers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;
import java.util.Map;

class SigmaContext implements HttpContext {
final class SigmaContext implements HttpContext {

public static final String CONTENT_TYPE = "Content-Type";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Map;

/** Filter with special matchAll. */
class FilterEntry implements SpiRoutes.Entry {
final class FilterEntry implements SpiRoutes.Entry {

private final String path;
private final boolean matchAll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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
14 changes: 7 additions & 7 deletions avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.List;

abstract class PathSegment {
abstract sealed class PathSegment {

abstract String asRegexString(boolean extract);

Expand All @@ -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 All @@ -35,7 +35,7 @@ boolean multiSlash() {
}
}

private abstract static class Parameter extends PathSegment {
private abstract static sealed class Parameter extends PathSegment {
private final String name;
private final String regex;

Expand All @@ -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 java.util.regex.MatchResult;
import java.util.regex.Pattern;

class PathSegmentParser {
final class PathSegmentParser {

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

Expand All @@ -31,7 +31,7 @@ class PathSegmentParser {
}

static PathSegment parse(String seg, String rawPath) {
if (seg.equals("*")) {
if ("*".equals(seg)) {
return WILDCARD;
}
return new PathSegmentParser(seg, rawPath).parse();
Expand All @@ -42,10 +42,7 @@ PathSegment parse() {
if (matchOnlyStartEnd('<', '>')) {
return new PathSegment.SlashAcceptingParameter(trim(segment));
}
if (matchOnlyStartEnd('{', '}')) {
return new PathSegment.SlashIgnoringParameter(trim(segment));
}
if (matchParamWithRegex(segment)) {
if (matchOnlyStartEnd('{', '}') || matchParamWithRegex(segment)) {
return new PathSegment.SlashIgnoringParameter(trim(segment));
}
if (matchLiteral(segment)) {
Expand Down Expand Up @@ -79,7 +76,7 @@ private PathSegment parseMultiSegment() {
}

private PathSegment tokenSegment(String token) {
if (token.equals("*")) {
if ("*".equals(token)) {
return WILDCARD;
} else if (token.startsWith("<")) {
return slashAccepting(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.regex.Pattern;

/** 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 @@ -4,7 +4,7 @@
import io.avaje.sigma.HttpContext;
import java.util.Map;

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

private final PathParser path;
private final Handler handler;
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. */
private final RouteIndex.Entry[] entries = new RouteIndex.Entry[6];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.Map;

class Routes implements SpiRoutes {
final class Routes implements SpiRoutes {

/** The "real" handlers by http method. */
private final EnumMap<Router.HttpMethod, RouteIndex> typeMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.Map;

public class RoutesBuilder {
public final class RoutesBuilder {

private final EnumMap<Router.HttpMethod, RouteIndex> typeMap =
new EnumMap<>(Router.HttpMethod.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;

/** Route matching and filter handling. */
public interface SpiRoutes {
public sealed interface SpiRoutes permits Routes {

/** Find the matching handler entry given the type and request URI. */
Entry match(Router.HttpMethod type, String pathInfo);
Expand All @@ -19,7 +19,7 @@ public interface SpiRoutes {
void handleException(HttpContext ctx, Exception e);

/** A route entry. */
interface Entry {
sealed interface Entry permits FilterEntry, RouteEntry {

/** Return true if it matches the request URI. */
boolean matches(String requestUri);
Expand Down

0 comments on commit 3fabc34

Please sign in to comment.