Skip to content

Method: ReferencedListHelper(ValueConverter)

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j.list;
19:
20: import cz.cvut.kbss.ontodriver.model.Assertion;
21: import cz.cvut.kbss.ontodriver.model.LangString;
22: import cz.cvut.kbss.ontodriver.model.MultilingualString;
23: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
24: import cz.cvut.kbss.ontodriver.rdf4j.util.ValueConverter;
25: import org.eclipse.rdf4j.model.Value;
26:
27: import java.util.ArrayList;
28: import java.util.Collection;
29: import java.util.List;
30: import java.util.Map;
31:
32: class ReferencedListHelper {
33:
34: private final ValueConverter valueConverter;
35:
36: ReferencedListHelper(ValueConverter valueConverter) {this.valueConverter = valueConverter;}
37:
38: Collection<Value> toRdf4jValue(Assertion a, Object value) throws Rdf4jDriverException {
39: if (value instanceof MultilingualString) {
40: final MultilingualString mls = (MultilingualString) value;
41: final List<Value> values = new ArrayList<>(mls.getValue().size());
42: for (Map.Entry<String, String> e : mls.getValue().entrySet()) {
43: values.add(valueConverter.toRdf4jValue(a, new cz.cvut.kbss.ontodriver.model.Value<>(new LangString(e.getValue(), e.getKey()))));
44: }
45: return values;
46: }
47: return List.of(valueConverter.toRdf4jValue(a, new cz.cvut.kbss.ontodriver.model.Value<>(value)));
48: }
49: }