Skip to content

Package: InstantConverter

InstantConverter

nameinstructionbranchcomplexitylinemethod
InstantConverter()
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(Instant)
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%
offsetDateTimeToInstant(OffsetDateTime)
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%
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) 2023 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.XsdDateTimeMapper;
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.Instant;
27: import java.time.OffsetDateTime;
28:
29: /**
30: * Converts between Java 8 {@link Instant} and a supported xsd:dateTime representation.
31: * <p>
32: * This converter supports {@link OffsetDateTime} and {@link cz.cvut.kbss.ontodriver.model.Literal} as date time.
33: */
34: public class InstantConverter implements ConverterWrapper<Instant, Object> {
35:
36: @Override
37: public Object convertToAxiomValue(Instant value) {
38:• assert value != null;
39: return DateTimeUtil.toDateTime(value);
40: }
41:
42: @Override
43: public Instant convertToAttribute(Object value) {
44:• assert value != null;
45:• if (value instanceof OffsetDateTime) {
46: return offsetDateTimeToInstant((OffsetDateTime) value);
47: } else {
48:• assert value instanceof Literal;
49: final Literal literal = (Literal) value;
50:• assert XSD.DATETIME.equals(literal.getDatatype());
51: return offsetDateTimeToInstant(XsdDateTimeMapper.map(literal.getLexicalForm()));
52: }
53: }
54:
55: private static Instant offsetDateTimeToInstant(OffsetDateTime value) {
56: return value.toInstant();
57: }
58:
59: @Override
60: public boolean supportsAxiomValueType(Class<?> type) {
61:• return OffsetDateTime.class.isAssignableFrom(type) || Literal.class.isAssignableFrom(type);
62: }
63: }