Skip to content

Commit

Permalink
Trie implementation for Route matching (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Danilenko <alexander.danilenko@revolut.com>
  • Loading branch information
lazer-dev and Alex Danilenko committed Apr 22, 2024
1 parent 455cf4c commit 1fb9e2a
Show file tree
Hide file tree
Showing 12 changed files with 726 additions and 156 deletions.
7 changes: 1 addition & 6 deletions build.gradle
Expand Up @@ -13,12 +13,7 @@ subprojects {
apply plugin: 'jacoco'
apply plugin: 'org.unbroken-dome.test-sets'

ext {
jvmVersion = JavaVersion.VERSION_1_8
}

sourceCompatibility = jvmVersion
targetCompatibility = jvmVersion
java.toolchain.languageVersion = JavaLanguageVersion.of(8)

compileJava.options.encoding = 'UTF-8'

Expand Down
@@ -0,0 +1,24 @@
/*
* Copyright 2022 - Alex Danilenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package spotty.common.exception;

public class SpottyRouteDuplicationException extends SpottyException {

public SpottyRouteDuplicationException(String message, Object... args) {
super(message, args);
}

}
6 changes: 3 additions & 3 deletions core/src/main/java/spotty/common/utils/Memoized.java
Expand Up @@ -26,7 +26,7 @@ private Memoized() {

public static <T> Supplier<T> lazy(Supplier<T> supplier) {
return new Supplier<T>() {
private T memoized;
private volatile T memoized;

@Override
public T get() {
Expand All @@ -41,8 +41,8 @@ public T get() {

public static IntSupplier lazy(IntSupplier supplier) {
return new IntSupplier() {
private boolean isMemoized = false;
private int value;
private volatile boolean isMemoized = false;
private volatile int value;

@Override
public int getAsInt() {
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/spotty/common/utils/RouterUtils.java
Expand Up @@ -45,7 +45,12 @@ public static Result compileMatcher(String pathTemplate) {
}

public static String normalizePath(String path) {
return path.replaceAll(REGEX, "*$2");
if (!path.startsWith("/")) {
path = "/" + path;
}

return path.replaceAll(REGEX, "*$2")
.replaceAll("\\*+", "*");
}

public static class Result {
Expand Down
Expand Up @@ -18,14 +18,17 @@
import org.apache.tika.Tika;

import java.net.URL;
import java.util.function.Supplier;

import static spotty.common.utils.Memoized.lazy;

public final class FileTypeDetector implements TypeDetector {

private final Tika tika = new Tika();
private static final Supplier<Tika> tika = lazy(() -> new Tika());

@Override
public String detect(URL path) throws Exception {
return tika.detect(path);
return tika.get().detect(path);
}

}

0 comments on commit 1fb9e2a

Please sign in to comment.