Skip to content

Package: LocalTimeConverter

LocalTimeConverter

nameinstructionbranchcomplexitylinemethod
LocalTimeConverter()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
convertToAttribute(Object)
M: 12 C: 28
70%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 0 C: 7
100%
M: 0 C: 1
100%
convertToAxiomValue(LocalTime)
M: 4 C: 6
60%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
supportsAxiomValueType(Class)
M: 0 C: 12
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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.jopa.oom.converter.datetime;
19:
20: import cz.cvut.kbss.jopa.datatype.DateTimeUtil;
21: import cz.cvut.kbss.jopa.datatype.xsd.XsdTimeMapper;
22: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
23: import cz.cvut.kbss.jopa.vocabulary.XSD;
24: import cz.cvut.kbss.ontodriver.model.Literal;
25:
26: import java.time.LocalTime;
27: import java.time.OffsetTime;
28:
29: /**
30: * Converts between Java 8 {@link LocalTime} and a supported xsd:time representation.
31: * <p>
32: * This converter supports {@link OffsetTime} and {@link cz.cvut.kbss.ontodriver.model.Literal} as date time.
33: */
34: public class LocalTimeConverter implements ConverterWrapper<LocalTime, Object> {
35:
36: @Override
37: public Object convertToAxiomValue(LocalTime value) {
38:• assert value != null;
39: return DateTimeUtil.toTime(value);
40: }
41:
42: @Override
43: public LocalTime convertToAttribute(Object value) {
44:• assert value != null;
45:• if (value instanceof OffsetTime) {
46: return ((OffsetTime) value).toLocalTime();
47: } else {
48:• assert value instanceof Literal;
49: final Literal literal = (Literal) value;
50:• assert XSD.TIME.equals(literal.getDatatype());
51: return (XsdTimeMapper.map(literal.getLexicalForm())).toLocalTime();
52: }
53: }
54:
55: @Override
56: public boolean supportsAxiomValueType(Class<?> type) {
57:• return OffsetTime.class.isAssignableFrom(type) || Literal.class.isAssignableFrom(type);
58: }
59: }