Skip to content

Method: addItem(Object)

1: /*
2: * JB4JSON-LD
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.jsonld.deserialization;
19:
20: import cz.cvut.kbss.jopa.model.MultilingualString;
21: import cz.cvut.kbss.jsonld.deserialization.util.LangString;
22:
23: import java.util.Map;
24:
25: public class MultilingualStringContext extends InstanceContext<MultilingualString> {
26:
27: MultilingualStringContext(MultilingualString instance, Map<String, Object> knownInstances) {
28: super(instance, knownInstances);
29: }
30:
31: @Override
32: void addItem(Object item) {
33:• assert item != null;
34:• if (item instanceof LangString) {
35: final LangString ls = (LangString) item;
36: instance.set(ls.getLanguage().orElse(null), ls.getValue());
37: } else {
38: instance.set(item.toString());
39: }
40: }
41:
42: /**
43: * Returns {@link LangString} as item type supported by this context.
44: *
45: * This is because a {@link MultilingualString} is essentially a container for a collection of translations of the
46: * same string, and it simplifies client code.
47: * @return {@code LangString} class
48: */
49: @Override
50: Class<?> getItemType() {
51: return LangString.class;
52: }
53: }