forked from enola-dev/enola
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (ide): Bump google-java-formatter from 1.20.0 to 1.21.0
This fixes google/google-java-format#1072.
- Loading branch information
Showing
8 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
common/common/src/main/java/dev/enola/common/io/iri/IRIs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2024 The Enola <https://enola.dev> Authors | ||
* | ||
* 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 | ||
* | ||
* https://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 dev.enola.common.io.iri; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
/** | ||
* Utility methods for Internationalized Resource Identifiers (IRIs). | ||
* | ||
* <p>See <a href="https://datatracker.ietf.org/doc/html/rfc3987">RFC 3987</a>. | ||
*/ | ||
public final class IRIs { | ||
// see also (new) class dev.enola.common.io.resource.URIs | ||
|
||
/** | ||
* Resolves an IRI reference against a base IRI and returns the resulting IRI as a String. | ||
* | ||
* <p>See <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-4">Section §4 of RFC | ||
* 3986</a>. | ||
* | ||
* <p>This is currently implemented using {@link java.net.URI#resolve()}. This works great, but | ||
* it creates (two) intermediate URI objects. If this ever becomes a problem for performance, | ||
* this implementation could be optimized to work directly on Strings. | ||
*/ | ||
public static String resolve(String base, String reference) throws URISyntaxException { | ||
return toURI(base).resolve(reference).toString(); | ||
} | ||
|
||
public static URI toURI(String iri) throws URISyntaxException { | ||
return new URI(iri); | ||
} | ||
|
||
private IRIs() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common/common/src/test/java/dev/enola/common/io/iri/IRIsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2024 The Enola <https://enola.dev> Authors | ||
* | ||
* 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 | ||
* | ||
* https://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 dev.enola.common.io.iri; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class IRIsTest { | ||
|
||
@Test | ||
public void toURI() throws URISyntaxException { | ||
var iri = "https://en.wiktionary.org/wiki/Ῥόδος"; | ||
assertThat(IRIs.toURI(iri)).isEqualTo(new URI(iri)); | ||
} | ||
|
||
@Test | ||
public void resolve() throws URISyntaxException { | ||
var base = "https://en.wiktionary.org/wiki/Ῥόδος"; | ||
var rel = "ῥόα"; | ||
var expected = "https://en.wiktionary.org/wiki/ῥόα"; | ||
assertThat(IRIs.resolve(base, rel)).isEqualTo(expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters