-
-
Notifications
You must be signed in to change notification settings - Fork 87
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Overview
Modernize date handling code in DateUtils.java and BinaryTypes.java using Java 21 pattern matching switch expressions.
Part of Epic #2968
Goals
- 43% reduction in cyclomatic complexity
- 23% code reduction with improved clarity
- 100% explicit null safety with pattern matching
- Replace verbose if-else chains with exhaustive switch expressions
- Migrate from wildcard to explicit imports
Files to Change
DateUtils.java
Location: engine/src/main/java/com/arcadedb/utility/DateUtils.java
Methods to modernize:
getNanos(Object obj)getMicros(Object obj)getMillis(Object obj)getSeconds(Object obj)precisionFromDateType(byte type)dateTypeToPrecision(ChronoUnit precision)
BinaryTypes.java
Location: engine/src/main/java/com/arcadedb/serializer/BinaryTypes.java
Methods to modernize:
precisionFromDateType(byte type)
Implementation Pattern
// Before: verbose if-else chain
public static int getNanos(final Object obj) {
if (obj == null)
throw new IllegalArgumentException("Object is null");
else if (obj instanceof LocalDateTime time)
return time.getNano();
else if (obj instanceof ZonedDateTime time)
return time.getNano();
// ...
}
// After: clean pattern-matching switch
public static int getNanos(final Object obj) {
return switch (obj) {
case null -> throw new IllegalArgumentException("Object is null");
case LocalDateTime time -> time.getNano();
case ZonedDateTime time -> time.getNano();
case Instant instant -> instant.getNano();
default -> throw new IllegalArgumentException("Cannot extract nanos from object of type '" + obj.getClass() + "'");
};
}Validation
# Compile
mvn compile -pl engine
# Run unit tests
mvn test -pl engine -Dtest=*DateUtils*
mvn test -pl engine -Dtest=*Binary*
# Run integration test that depends on these changes
mvn test -pl server -Dtest=RemoteDateITSuccess Criteria
- No compilation errors
- All DateUtils unit tests pass
- All BinaryTypes tests pass
- RemoteDateIT passes (after bug fix in separate issue)
- Code follows Java 21 patterns
- Explicit imports replace wildcards
Time Estimate
50 minutes total
- DateUtils.java: 30 minutes
- BinaryTypes.java: 20 minutes
Risk Level
LOW - Straightforward refactoring with good test coverage
Documentation
See PORTING_PLAN_IT_TEST_IMPROVEMENTS.md - Phase 2 for detailed instructions.
Related Issues
Part of Epic: #2968
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request