Skip to content

Commit 1fb9e2a

Browse files
lazer-devAlex Danilenko
andauthored
Trie implementation for Route matching (#58)
Co-authored-by: Alex Danilenko <[email protected]>
1 parent 455cf4c commit 1fb9e2a

File tree

12 files changed

+726
-156
lines changed

12 files changed

+726
-156
lines changed

build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ subprojects {
1313
apply plugin: 'jacoco'
1414
apply plugin: 'org.unbroken-dome.test-sets'
1515

16-
ext {
17-
jvmVersion = JavaVersion.VERSION_1_8
18-
}
19-
20-
sourceCompatibility = jvmVersion
21-
targetCompatibility = jvmVersion
16+
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
2217

2318
compileJava.options.encoding = 'UTF-8'
2419

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2022 - Alex Danilenko
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package spotty.common.exception;
17+
18+
public class SpottyRouteDuplicationException extends SpottyException {
19+
20+
public SpottyRouteDuplicationException(String message, Object... args) {
21+
super(message, args);
22+
}
23+
24+
}

core/src/main/java/spotty/common/utils/Memoized.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private Memoized() {
2626

2727
public static <T> Supplier<T> lazy(Supplier<T> supplier) {
2828
return new Supplier<T>() {
29-
private T memoized;
29+
private volatile T memoized;
3030

3131
@Override
3232
public T get() {
@@ -41,8 +41,8 @@ public T get() {
4141

4242
public static IntSupplier lazy(IntSupplier supplier) {
4343
return new IntSupplier() {
44-
private boolean isMemoized = false;
45-
private int value;
44+
private volatile boolean isMemoized = false;
45+
private volatile int value;
4646

4747
@Override
4848
public int getAsInt() {

core/src/main/java/spotty/common/utils/RouterUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ public static Result compileMatcher(String pathTemplate) {
4545
}
4646

4747
public static String normalizePath(String path) {
48-
return path.replaceAll(REGEX, "*$2");
48+
if (!path.startsWith("/")) {
49+
path = "/" + path;
50+
}
51+
52+
return path.replaceAll(REGEX, "*$2")
53+
.replaceAll("\\*+", "*");
4954
}
5055

5156
public static class Result {

core/src/main/java/spotty/server/files/detector/FileTypeDetector.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
import org.apache.tika.Tika;
1919

2020
import java.net.URL;
21+
import java.util.function.Supplier;
22+
23+
import static spotty.common.utils.Memoized.lazy;
2124

2225
public final class FileTypeDetector implements TypeDetector {
2326

24-
private final Tika tika = new Tika();
27+
private static final Supplier<Tika> tika = lazy(() -> new Tika());
2528

2629
@Override
2730
public String detect(URL path) throws Exception {
28-
return tika.detect(path);
31+
return tika.get().detect(path);
2932
}
3033

3134
}

0 commit comments

Comments
 (0)