1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | ||
7 | package org.opensearch.sql.data.model; | |
8 | ||
9 | import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME; | |
10 | import static org.opensearch.sql.utils.DateTimeFormatters.DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL; | |
11 | ||
12 | import java.time.Instant; | |
13 | import java.time.LocalDate; | |
14 | import java.time.LocalDateTime; | |
15 | import java.time.LocalTime; | |
16 | import java.time.ZoneId; | |
17 | import java.time.ZonedDateTime; | |
18 | import java.time.format.DateTimeParseException; | |
19 | import java.util.Objects; | |
20 | import lombok.RequiredArgsConstructor; | |
21 | import org.opensearch.sql.data.type.ExprCoreType; | |
22 | import org.opensearch.sql.data.type.ExprType; | |
23 | import org.opensearch.sql.exception.SemanticCheckException; | |
24 | ||
25 | /** | |
26 | * Expression Time Value. | |
27 | */ | |
28 | @RequiredArgsConstructor | |
29 | public class ExprTimeValue extends AbstractExprValue { | |
30 | ||
31 | private final LocalTime time; | |
32 | ||
33 | /** | |
34 | * Constructor of ExprTimeValue. | |
35 | */ | |
36 | public ExprTimeValue(String time) { | |
37 | try { | |
38 | this.time = LocalTime.parse(time, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL); | |
39 | } catch (DateTimeParseException e) { | |
40 | throw new SemanticCheckException(String.format("time:%s in unsupported format, please use " | |
41 | + "HH:mm:ss[.SSSSSSSSS]", time)); | |
42 | } | |
43 | } | |
44 | ||
45 | @Override | |
46 | public String value() { | |
47 |
1
1. value : replaced return value with "" for org/opensearch/sql/data/model/ExprTimeValue::value → KILLED |
return ISO_LOCAL_TIME.format(time); |
48 | } | |
49 | ||
50 | @Override | |
51 | public ExprType type() { | |
52 |
1
1. type : replaced return value with null for org/opensearch/sql/data/model/ExprTimeValue::type → KILLED |
return ExprCoreType.TIME; |
53 | } | |
54 | ||
55 | @Override | |
56 | public LocalTime timeValue() { | |
57 |
1
1. timeValue : replaced return value with null for org/opensearch/sql/data/model/ExprTimeValue::timeValue → KILLED |
return time; |
58 | } | |
59 | ||
60 | @Override | |
61 | public String toString() { | |
62 |
1
1. toString : replaced return value with "" for org/opensearch/sql/data/model/ExprTimeValue::toString → KILLED |
return String.format("TIME '%s'", value()); |
63 | } | |
64 | ||
65 | @Override | |
66 | public int compare(ExprValue other) { | |
67 |
1
1. compare : replaced int return with 0 for org/opensearch/sql/data/model/ExprTimeValue::compare → KILLED |
return time.compareTo(other.timeValue()); |
68 | } | |
69 | ||
70 | @Override | |
71 | public boolean equal(ExprValue other) { | |
72 |
2
1. equal : replaced boolean return with true for org/opensearch/sql/data/model/ExprTimeValue::equal → SURVIVED 2. equal : replaced boolean return with false for org/opensearch/sql/data/model/ExprTimeValue::equal → KILLED |
return time.equals(other.timeValue()); |
73 | } | |
74 | ||
75 | @Override | |
76 | public int hashCode() { | |
77 |
1
1. hashCode : replaced int return with 0 for org/opensearch/sql/data/model/ExprTimeValue::hashCode → SURVIVED |
return Objects.hashCode(time); |
78 | } | |
79 | } | |
Mutations | ||
47 |
1.1 |
|
52 |
1.1 |
|
57 |
1.1 |
|
62 |
1.1 |
|
67 |
1.1 |
|
72 |
1.1 2.2 |
|
77 |
1.1 |