Skip to content

Commit ca07cec

Browse files
committed
feat: common.struct + common.io.object
1 parent 495a0ac commit ca07cec

15 files changed

+429
-0
lines changed

java/dev/enola/common/io/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ java_library(
2222
srcs = glob(
2323
[
2424
"*.java",
25+
"object/*.java",
2526
"mediatype/*.java",
2627
"hashbrown/*.java",
2728
"resource/**/*.java",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.io.object;
19+
20+
import dev.enola.common.io.resource.ReadableResource;
21+
22+
import java.io.IOException;
23+
import java.util.Optional;
24+
25+
public interface ObjectReader {
26+
27+
// TODO <T> Iterator<T> readAll(ReadableResource resource, Class<T> type) throws IOException;
28+
29+
default <T> T read(ReadableResource resource, Class<T> type) throws IOException {
30+
return optional(resource, type)
31+
.orElseThrow(
32+
() ->
33+
new IOException(
34+
getClass()
35+
+ " cannot read "
36+
+ resource.uri()
37+
+ " as "
38+
+ type.getTypeName()));
39+
}
40+
41+
<T> Optional<T> optional(ReadableResource resource, Class<T> type) throws IOException;
42+
43+
// PS: There is intentionally no ResolvedType / TypeReference / TypeToken sorta support!
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.io.object;
19+
20+
import dev.enola.common.io.resource.ReadableResource;
21+
22+
import java.io.IOException;
23+
import java.util.Optional;
24+
25+
public class ObjectReaderChain implements ObjectReader {
26+
27+
@Override
28+
public <T> Optional<T> optional(ReadableResource resource, Class<T> type) throws IOException {
29+
return null;
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.io.object;
19+
20+
public interface ObjectWriter {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.io.object;
19+
20+
public class ObjectWriterChain implements ObjectWriter {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/** I/O for {@link dev.enola.common.struct}. */
20+
@NullMarked
21+
package dev.enola.common.io.object;
22+
23+
import org.jspecify.annotations.NullMarked;

java/dev/enola/common/struct/BUILD

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright 2023 The Enola <https://enola.dev> Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
load("@rules_java//java:defs.bzl", "java_library")
18+
load("//tools/bazel:junit.bzl", "junit_tests")
19+
20+
java_library(
21+
name = "struct",
22+
srcs = glob(
23+
["*.java"],
24+
exclude = ["*Test.java"],
25+
),
26+
visibility = ["//:__subpackages__"],
27+
deps = [
28+
"@enola_maven//:com_google_errorprone_error_prone_annotations",
29+
"@enola_maven//:com_google_guava_guava",
30+
"@enola_maven//:org_jspecify_jspecify",
31+
],
32+
)
33+
34+
junit_tests(
35+
name = "tests",
36+
srcs = glob(
37+
["*Test.java"],
38+
allow_empty = True,
39+
),
40+
deps = [
41+
":struct",
42+
],
43+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.struct;
19+
20+
import com.google.errorprone.annotations.Immutable;
21+
22+
@Immutable
23+
public record CustomDatatype(int anInt, String aString) {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.struct;
19+
20+
import org.jspecify.annotations.Nullable;
21+
22+
import java.time.Instant;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Set;
26+
27+
public interface Example {
28+
29+
String text();
30+
31+
Integer number();
32+
33+
Instant instant();
34+
35+
@Nullable Example example();
36+
37+
List<Example> examplesInOrder();
38+
39+
Set<Example> examplesBag();
40+
41+
Map<String, Example> map();
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2025 The Enola <https://enola.dev> Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package dev.enola.common.struct;
19+
20+
public class ExampleIOTestFixture {}

0 commit comments

Comments
 (0)