package com.talentcard.server.business; import java.sql.Date; import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public final class DatabaseRows { private DatabaseRows() { } public static List> normalize(List> rows) { return rows.stream().map(DatabaseRows::normalize).toList(); } public static Map normalize(Map row) { Map result = new LinkedHashMap<>(); row.forEach((key, value) -> result.put(toCamelCase(key), normalizeValue(value))); return result; } private static Object normalizeValue(Object value) { if (value instanceof Timestamp timestamp) { return timestamp.toLocalDateTime(); } if (value instanceof Date date) { return date.toLocalDate(); } if (value instanceof LocalDateTime || value instanceof LocalDate) { return value; } return value; } private static String toCamelCase(String value) { StringBuilder builder = new StringBuilder(); boolean upperNext = false; for (char c : value.toCharArray()) { if (c == '_') { upperNext = true; continue; } builder.append(upperNext ? Character.toUpperCase(c) : c); upperNext = false; } return builder.toString(); } }