001package org.itsallcode.jdbc.resultset.generic;
002
003/**
004 * Represents a generic column value.
005 * 
006 * @param type  column type
007 * @param value column value
008 */
009public record ColumnValue(ColumnType type, Object value) {
010
011    /**
012     * Get the column value cast to the given type.
013     * 
014     * @param type expected type
015     * @param <T>  result type
016     * @return value of the given type
017     */
018    public <T> T getValue(final Class<T> type) {
019        return cast(type);
020    }
021
022    /**
023     * Get the column value as an object.
024     * 
025     * @return column value
026     */
027    public Object getValue() {
028        return value;
029    }
030
031    /**
032     * Get the column value as a string.
033     * 
034     * @return column value as string
035     */
036    public String getString() {
037        return cast(String.class);
038    }
039
040    private <T> T cast(final Class<T> type) {
041        return type.cast(this.value);
042    }
043}