Skip to content

Commit d297c47

Browse files
authored
Merge pull request #153 from filip26/feat/tree-a
Replace Q lambdas with Tree I/O
2 parents e11bccc + efadd8b commit d297c47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+397
-943
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Fork and clone the project repository.
199199

200200
```bash
201201
> cd iridium-cbor-ld
202-
> mvn clean package
202+
> mvn package
203203
```
204204

205205
## Resources

pom.xml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.apicatalog</groupId>
99
<artifactId>iridium-cbor-ld</artifactId>
10-
<version>0.7.3</version>
10+
<version>0.8.0-SNAPSHOT</version>
1111

1212
<packaging>jar</packaging>
1313
<name>Iridium CBOR-LD</name>
@@ -56,12 +56,11 @@
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5858

59+
<tree.version>0.7.5</tree.version>
5960
<jakarta.json.version>2.0.1</jakarta.json.version>
6061

6162
<copper-multibase>4.1.0</copper-multibase>
6263

63-
<cbor-java.version>0.9</cbor-java.version>
64-
6564
<argLine>-Dfile.encoding=UTF-8</argLine>
6665

6766
<!-- test resources -->
@@ -78,19 +77,31 @@
7877
<version>${titanium.version}</version>
7978
</dependency>
8079

80+
<dependency>
81+
<groupId>com.apicatalog</groupId>
82+
<artifactId>tree-io-api</artifactId>
83+
<version>${tree.version}</version>
84+
</dependency>
85+
86+
<dependency>
87+
<groupId>com.apicatalog</groupId>
88+
<artifactId>tree-io-jakarta</artifactId>
89+
<version>${tree.version}</version>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>com.apicatalog</groupId>
94+
<artifactId>tree-io-cbor</artifactId>
95+
<version>${tree.version}</version>
96+
</dependency>
97+
8198
<dependency>
8299
<groupId>jakarta.json</groupId>
83100
<artifactId>jakarta.json-api</artifactId>
84101
<version>${jakarta.json.version}</version>
85102
<scope>provided</scope>
86103
</dependency>
87104

88-
<dependency>
89-
<groupId>co.nstant.in</groupId>
90-
<artifactId>cbor</artifactId>
91-
<version>${cbor-java.version}</version>
92-
</dependency>
93-
94105
<dependency>
95106
<groupId>com.apicatalog</groupId>
96107
<artifactId>copper-multibase</artifactId>

src/main/java/com/apicatalog/cborld/config/ConfigV1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ConfigV1 implements EncoderConfig, DecoderConfig {
4949

5050
Collection<ValueEncoder> valueEncoders = new ArrayList<>();
5151

52-
// term driven
52+
// property driven
5353
valueEncoders.add(new ContextValueEncoder());
5454

5555
// type driven
@@ -71,7 +71,7 @@ public class ConfigV1 implements EncoderConfig, DecoderConfig {
7171
static final Collection<ValueDecoder> VALUE_DECODERS = new ArrayList<>();
7272

7373
static {
74-
// term driven
74+
// property driven
7575
VALUE_DECODERS.add(new ContextValueDecoder());
7676

7777
// type driven

src/main/java/com/apicatalog/cborld/config/LegacyConfigV05.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LegacyConfigV05 implements EncoderConfig, DecoderConfig {
4040
static final Collection<ValueEncoder> VALUE_ENCODERS = new ArrayList<>();
4141

4242
static {
43-
// term driven
43+
// property driven
4444
VALUE_ENCODERS.add(new ContextValueEncoder());
4545

4646
// type driven
@@ -58,7 +58,7 @@ public class LegacyConfigV05 implements EncoderConfig, DecoderConfig {
5858
static final Collection<ValueDecoder> VALUE_DECODERS = new ArrayList<>();
5959

6060
static {
61-
// term driven
61+
// property driven
6262
VALUE_DECODERS.add(new ContextValueDecoder());
6363

6464
// type driven

src/main/java/com/apicatalog/cborld/config/LegacyConfigV06.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class LegacyConfigV06 implements EncoderConfig, DecoderConfig {
4545
static final Collection<ValueEncoder> VALUE_ENCODERS = new ArrayList<>();
4646

4747
static {
48-
// term driven
48+
// property driven
4949
VALUE_ENCODERS.add(new ContextValueEncoder());
5050

5151
// type driven
@@ -65,7 +65,7 @@ public class LegacyConfigV06 implements EncoderConfig, DecoderConfig {
6565
static final Collection<ValueDecoder> VALUE_DECODERS = new ArrayList<>();
6666

6767
static {
68-
// term driven
68+
// property driven
6969
VALUE_DECODERS.add(new ContextValueDecoder());
7070

7171
// type driven

src/main/java/com/apicatalog/cborld/context/ArrayExpansion.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import com.apicatalog.jsonld.JsonLdError;
2424
import com.apicatalog.jsonld.context.ActiveContext;
2525
import com.apicatalog.jsonld.json.JsonUtils;
26-
import com.apicatalog.lq.Data;
27-
import com.apicatalog.lq.Q;
26+
import com.apicatalog.tree.io.NodeAdapter;
2827

2928
import jakarta.json.Json;
3029
import jakarta.json.JsonArray;
@@ -35,21 +34,24 @@ final class ArrayExpansion {
3534

3635
// mandatory
3736
private ActiveContext activeContext;
38-
private Data element;
3937
private String activeProperty;
4038
private URI baseUrl;
4139

40+
private final Object element;
41+
private final NodeAdapter adapter;
42+
4243
private final Consumer<Collection<String>> appliedContexts;
4344
private final TypeKeyNameMapper typeMapper;
4445

4546
// optional
4647
private boolean ordered;
4748
private boolean fromMap;
4849

49-
private ArrayExpansion(final ActiveContext activeContext, final Data element, final String activeProperty,
50+
private ArrayExpansion(final ActiveContext activeContext, final Object element, NodeAdapter adapter, final String activeProperty,
5051
final URI baseUrl, Consumer<Collection<String>> appliedContexts, TypeKeyNameMapper typeMapper) {
5152
this.activeContext = activeContext;
5253
this.element = element;
54+
this.adapter = adapter;
5355
this.activeProperty = activeProperty;
5456
this.baseUrl = baseUrl;
5557

@@ -61,9 +63,15 @@ private ArrayExpansion(final ActiveContext activeContext, final Data element, fi
6163
this.fromMap = false;
6264
}
6365

64-
public static final ArrayExpansion with(final ActiveContext activeContext, final Data element,
65-
final String activeProperty, final URI baseUrl, Consumer<Collection<String>> appliedContexts, TypeKeyNameMapper typeMapper) {
66-
return new ArrayExpansion(activeContext, element, activeProperty, baseUrl, appliedContexts, typeMapper);
66+
public static final ArrayExpansion with(
67+
final ActiveContext activeContext,
68+
final Object element,
69+
final NodeAdapter adapter,
70+
final String activeProperty,
71+
final URI baseUrl,
72+
final Consumer<Collection<String>> appliedContexts,
73+
final TypeKeyNameMapper typeMapper) {
74+
return new ArrayExpansion(activeContext, element, adapter, activeProperty, baseUrl, appliedContexts, typeMapper);
6775
}
6876

6977
public ArrayExpansion ordered(boolean value) {
@@ -78,18 +86,18 @@ public ArrayExpansion fromMap(boolean value) {
7886

7987
public JsonArray expand() throws JsonLdError {
8088

81-
if (Q.isEmpty(element)) {
89+
if (adapter.isEmpty(element)) {
8290
return JsonValue.EMPTY_JSON_ARRAY;
8391
}
8492

8593
final JsonArrayBuilder result = Json.createArrayBuilder();
8694

8795
// 5.2.
88-
for (final Data item : Q.iterable(element)) {
96+
for (final Object item : adapter.iterable(element)) {
8997

9098
// 5.2.1
9199
JsonValue expanded = Expansion
92-
.with(activeContext, item, activeProperty, baseUrl, appliedContexts, typeMapper)
100+
.with(activeContext, item, adapter, activeProperty, baseUrl, appliedContexts, typeMapper)
93101
.ordered(ordered)
94102
.fromMap(fromMap)
95103
.compute();

src/main/java/com/apicatalog/cborld/context/Context.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.apicatalog.jsonld.context.ActiveContext;
1313
import com.apicatalog.jsonld.loader.DocumentLoader;
1414
import com.apicatalog.jsonld.processor.ProcessingRuntime;
15-
import com.apicatalog.lq.Data;
15+
import com.apicatalog.tree.io.NodeAdapter;
1616

1717
public class Context {
1818

@@ -24,7 +24,7 @@ protected Context(TypeMap typeMapping, Collection<Collection<String>> appliedCon
2424
this.appliedContextKeys = appliedContextKeys;
2525
}
2626

27-
public static Context from(Data document, URI base, DocumentLoader loader) throws JsonLdError {
27+
public static Context from(Object document, NodeAdapter adapter, URI base, DocumentLoader loader) throws JsonLdError {
2828

2929
final JsonLdOptions options = new JsonLdOptions();
3030
options.setOrdered(false);
@@ -38,7 +38,9 @@ public static Context from(Data document, URI base, DocumentLoader loader) throw
3838
final TypeMap typeMapping = Expansion.with(
3939
activeContext,
4040
document,
41-
null, base,
41+
adapter,
42+
null,
43+
base,
4244
appliedContextKeys::add,
4345
null)
4446
.typeMapping();
@@ -47,7 +49,9 @@ public static Context from(Data document, URI base, DocumentLoader loader) throw
4749

4850
}
4951

50-
public static Context from(Data document,
52+
public static Context from(
53+
Object document,
54+
NodeAdapter adapter,
5155
URI base,
5256
DocumentLoader loader,
5357
Consumer<Collection<String>> appliedContexts,
@@ -65,7 +69,9 @@ public static Context from(Data document,
6569
final TypeMap typeMapping = Expansion.with(
6670
activeContext,
6771
document,
68-
null, base,
72+
adapter,
73+
null,
74+
base,
6975
appliedContexts.andThen(appliedContextKeys::add),
7076
typeMapper)
7177
.typeMapping();

src/main/java/com/apicatalog/cborld/context/Expansion.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,33 @@
2525
import com.apicatalog.jsonld.context.ActiveContext;
2626
import com.apicatalog.jsonld.context.TermDefinition;
2727
import com.apicatalog.jsonld.json.JsonUtils;
28-
import com.apicatalog.lq.Data;
29-
import com.apicatalog.lq.DataType;
30-
import com.apicatalog.lq.Q;
28+
import com.apicatalog.tree.io.NodeAdapter;
29+
import com.apicatalog.tree.io.NodeType;
3130

3231
import jakarta.json.JsonValue;
3332

3433
final class Expansion {
3534

3635
// mandatory
3736
private ActiveContext activeContext;
38-
private Data element;
3937
private String activeProperty;
4038
private URI baseUrl;
4139

40+
private Object element;
41+
private final NodeAdapter adapter;
42+
4243
// optional
4344
private boolean ordered;
4445
private boolean fromMap;
4546

4647
private Consumer<Collection<String>> appliedContexts;
4748
private TypeKeyNameMapper typeMapper;
4849

49-
private Expansion(final ActiveContext activeContext, final Data element, final String activeProperty,
50+
private Expansion(final ActiveContext activeContext, final Object element, final NodeAdapter adapter, final String activeProperty,
5051
final URI baseUrl, Consumer<Collection<String>> appliedContexts, TypeKeyNameMapper typeMapper) {
5152
this.activeContext = activeContext;
5253
this.element = element;
54+
this.adapter = adapter;
5355
this.activeProperty = activeProperty;
5456
this.baseUrl = baseUrl;
5557

@@ -61,9 +63,15 @@ private Expansion(final ActiveContext activeContext, final Data element, final S
6163
this.fromMap = false;
6264
}
6365

64-
public static final Expansion with(final ActiveContext activeContext, final Data element, final String activeProperty, final URI baseUrl, Consumer<Collection<String>> appliedContexts,
65-
TypeKeyNameMapper typeMapper) {
66-
return new Expansion(activeContext, element, activeProperty, baseUrl, appliedContexts, typeMapper);
66+
public static final Expansion with(
67+
final ActiveContext activeContext,
68+
final Object element,
69+
final NodeAdapter adapter,
70+
final String activeProperty,
71+
final URI baseUrl, Consumer<Collection<String>> appliedContexts,
72+
final TypeKeyNameMapper typeMapper) {
73+
74+
return new Expansion(activeContext, element, adapter, activeProperty, baseUrl, appliedContexts, typeMapper);
6775
}
6876

6977
public Expansion ordered(boolean value) {
@@ -83,13 +91,13 @@ protected JsonValue compute() throws JsonLdError {
8391
return JsonValue.NULL;
8492
}
8593

86-
final DataType dataType = Q.type(element);
94+
final NodeType dataType = adapter.type(element);
8795

8896
// 5. If element is an array,
89-
if (DataType.ARRAY == dataType) {
97+
if (NodeType.COLLECTION == dataType) {
9098

9199
return ArrayExpansion
92-
.with(activeContext, element, activeProperty, baseUrl, appliedContexts, typeMapper)
100+
.with(activeContext, element, adapter, activeProperty, baseUrl, appliedContexts, typeMapper)
93101
.ordered(ordered)
94102
.fromMap(fromMap)
95103
.expand();
@@ -109,15 +117,15 @@ protected JsonValue compute() throws JsonLdError {
109117
}
110118

111119
// 4. If element is a scalar
112-
if (Q.isScalar(dataType)) {
120+
if (dataType.isScalar()) {
113121
return ScalarExpansion
114-
.with(activeContext, propertyContext, element, activeProperty, appliedContexts)
122+
.with(activeContext, propertyContext, element, adapter, activeProperty, appliedContexts)
115123
.expand();
116124
}
117125

118126
// 6. Otherwise element is a map
119127
return ObjectExpansion
120-
.with(activeContext, propertyContext, element, activeProperty, baseUrl, appliedContexts, typeMapper)
128+
.with(activeContext, propertyContext, element, adapter, activeProperty, baseUrl, appliedContexts, typeMapper)
121129
.ordered(ordered)
122130
.fromMap(fromMap)
123131
.expand();

0 commit comments

Comments
 (0)