ExprTimeValue.java

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
Location : value
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:timeValueInterfaceTest()]
replaced return value with "" for org/opensearch/sql/data/model/ExprTimeValue::value → KILLED

52

1.1
Location : type
Killed by : org.opensearch.sql.data.model.ExprValueUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueUtilsTest]/[test-template:getType(org.opensearch.sql.data.model.ExprValue, org.opensearch.sql.data.type.ExprCoreType)]/[test-template-invocation:#12]
replaced return value with null for org/opensearch/sql/data/model/ExprTimeValue::type → KILLED

57

1.1
Location : timeValue
Killed by : org.opensearch.sql.data.model.ExprValueUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueUtilsTest]/[test-template:getValue(org.opensearch.sql.data.model.ExprValue, java.util.function.Function, java.lang.Object)]/[test-template-invocation:#12]
replaced return value with null for org/opensearch/sql/data/model/ExprTimeValue::timeValue → KILLED

62

1.1
Location : toString
Killed by : org.opensearch.sql.data.model.DateTimeValueTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.DateTimeValueTest]/[method:timeValueInterfaceTest()]
replaced return value with "" for org/opensearch/sql/data/model/ExprTimeValue::toString → KILLED

67

1.1
Location : compare
Killed by : org.opensearch.sql.data.model.ExprValueCompareTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueCompareTest]/[method:timeValueCompare()]
replaced int return with 0 for org/opensearch/sql/data/model/ExprTimeValue::compare → KILLED

72

1.1
Location : equal
Killed by : org.opensearch.sql.data.model.ExprValueUtilsTest.[engine:junit-jupiter]/[class:org.opensearch.sql.data.model.ExprValueUtilsTest]/[method:constructDateAndTimeValue()]
replaced boolean return with false for org/opensearch/sql/data/model/ExprTimeValue::equal → KILLED

2.2
Location : equal
Killed by : none
replaced boolean return with true for org/opensearch/sql/data/model/ExprTimeValue::equal → SURVIVED

77

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for org/opensearch/sql/data/model/ExprTimeValue::hashCode → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.9.0