From 3fabc3426e88911f2175ee1baaf1f3c25e159f19 Mon Sep 17 00:00:00 2001
From: Josiah Noel <32279667+SentryMan@users.noreply.github.com>
Date: Thu, 7 Nov 2024 09:36:40 -0500
Subject: [PATCH] Seal Internal Classes (#12)
* seal internal classes
* Google Java Format
* Update README.md
---------
Co-authored-by: github-actions <>
---
README.md | 4 ++--
.../java/io/avaje/sigma/core/DSigmaFunction.java | 2 +-
.../java/io/avaje/sigma/core/DefaultRouting.java | 6 ++----
.../java/io/avaje/sigma/core/ServiceManager.java | 2 +-
.../java/io/avaje/sigma/core/SigmaContext.java | 2 +-
.../java/io/avaje/sigma/routes/FilterEntry.java | 2 +-
.../java/io/avaje/sigma/routes/PathParser.java | 2 +-
.../java/io/avaje/sigma/routes/PathSegment.java | 14 +++++++-------
.../io/avaje/sigma/routes/PathSegmentParser.java | 11 ++++-------
.../java/io/avaje/sigma/routes/RegBuilder.java | 2 +-
.../java/io/avaje/sigma/routes/RouteEntry.java | 2 +-
.../java/io/avaje/sigma/routes/RouteIndex.java | 2 +-
.../main/java/io/avaje/sigma/routes/Routes.java | 2 +-
.../java/io/avaje/sigma/routes/RoutesBuilder.java | 2 +-
.../main/java/io/avaje/sigma/routes/SpiRoutes.java | 4 ++--
15 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/README.md b/README.md
index d234ace..7ec09a5 100644
--- a/README.md
+++ b/README.md
@@ -41,14 +41,14 @@ public class LambdaRequestHandler
io.avaje
avaje-http-api
- 2.8-RC3
+ 2.8
io.avaje
avaje-http-sigma-generator
- 2.8-RC3
+ 2.8
provided
true
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/core/DSigmaFunction.java b/avaje-sigma/src/main/java/io/avaje/sigma/core/DSigmaFunction.java
index 76041a5..996783b 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/core/DSigmaFunction.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/core/DSigmaFunction.java
@@ -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;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/core/DefaultRouting.java b/avaje-sigma/src/main/java/io/avaje/sigma/core/DefaultRouting.java
index ebbf7ee..5780594 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/core/DefaultRouting.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/core/DefaultRouting.java
@@ -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 handlers = new ArrayList<>();
@@ -45,8 +44,7 @@ public Router addAll(Collection 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);
}
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/core/ServiceManager.java b/avaje-sigma/src/main/java/io/avaje/sigma/core/ServiceManager.java
index 9d1c353..c5e7221 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/core/ServiceManager.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/core/ServiceManager.java
@@ -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 mappers;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/core/SigmaContext.java b/avaje-sigma/src/main/java/io/avaje/sigma/core/SigmaContext.java
index 493b324..1ec7ed9 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/core/SigmaContext.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/core/SigmaContext.java
@@ -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";
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/FilterEntry.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/FilterEntry.java
index f6a4917..2f22214 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/FilterEntry.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/FilterEntry.java
@@ -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;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathParser.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathParser.java
index 02e06f8..591453b 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathParser.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathParser.java
@@ -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 paramNames = new ArrayList<>();
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegment.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegment.java
index b07329e..24e83a8 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegment.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegment.java
@@ -4,7 +4,7 @@
import java.util.List;
-abstract class PathSegment {
+abstract sealed class PathSegment {
abstract String asRegexString(boolean extract);
@@ -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
}
@@ -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;
@@ -60,7 +60,7 @@ public void addParamName(List paramNames) {
}
}
- static class Multi extends PathSegment {
+ static final class Multi extends PathSegment {
private final List segments;
@@ -93,7 +93,7 @@ void addParamName(List paramNames) {
}
}
- static class Literal extends PathSegment {
+ static final class Literal extends PathSegment {
private final String content;
Literal(String content) {
@@ -116,7 +116,7 @@ public void addParamName(List paramNames) {
}
}
- static class Wildcard extends PathSegment {
+ static final class Wildcard extends PathSegment {
@Override
boolean multiSlash() {
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegmentParser.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegmentParser.java
index 243d4e1..1e8d129 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegmentParser.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/PathSegmentParser.java
@@ -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();
@@ -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();
@@ -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)) {
@@ -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);
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RegBuilder.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RegBuilder.java
index e34a20f..0dd9fd7 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RegBuilder.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RegBuilder.java
@@ -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;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteEntry.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteEntry.java
index 0a19275..0be7ecd 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteEntry.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteEntry.java
@@ -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;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteIndex.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteIndex.java
index b08d944..e419c1e 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteIndex.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RouteIndex.java
@@ -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];
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/Routes.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/Routes.java
index 19be35a..7bc5879 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/Routes.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/Routes.java
@@ -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 typeMap;
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RoutesBuilder.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RoutesBuilder.java
index ec68089..672eb3a 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/RoutesBuilder.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/RoutesBuilder.java
@@ -7,7 +7,7 @@
import java.util.List;
import java.util.Map;
-public class RoutesBuilder {
+public final class RoutesBuilder {
private final EnumMap typeMap =
new EnumMap<>(Router.HttpMethod.class);
diff --git a/avaje-sigma/src/main/java/io/avaje/sigma/routes/SpiRoutes.java b/avaje-sigma/src/main/java/io/avaje/sigma/routes/SpiRoutes.java
index 3349bf7..9044aa7 100644
--- a/avaje-sigma/src/main/java/io/avaje/sigma/routes/SpiRoutes.java
+++ b/avaje-sigma/src/main/java/io/avaje/sigma/routes/SpiRoutes.java
@@ -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);
@@ -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);