All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladmihalcea.hibernate.type.basic.internal.Iso8601MonthMonthTypeDescriptor Maven / Gradle / Ivy

There is a newer version: 2.21.1
Show newest version
package com.vladmihalcea.hibernate.type.basic.internal;

import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.AbstractClassJavaType;

import java.time.Month;
import java.util.Objects;

/**
 * @author Martin Panzer
 */
public class Iso8601MonthMonthTypeDescriptor
        extends AbstractClassJavaType {

    public static final Iso8601MonthMonthTypeDescriptor INSTANCE = new Iso8601MonthMonthTypeDescriptor();

    public Iso8601MonthMonthTypeDescriptor() {
        super(Month.class);
    }

    @Override
    public boolean areEqual(Month one, Month another) {
        return Objects.equals(one, another);
    }

    @Override
    public String toString(Month value) {
        return value.toString();
    }

    @SuppressWarnings({"unchecked"})
    @Override
    public  X unwrap(Month value, Class type, WrapperOptions options) {
        if (value == null) {
            return null;
        }
        if (Number.class.isAssignableFrom(type)) {
            return (X) (Number) value.getValue();
        }
        throw unknownUnwrap(type);
    }

    @Override
    public  Month wrap(X value, WrapperOptions options) {
        if (value == null) {
            return null;
        }
        if (value instanceof Number) {
            int numericValue = ((Number) (value)).intValue();
            return Month.of(numericValue);
        }
        throw unknownWrap(value.getClass());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy