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

com.vaadin.v7.data.util.converter.DateToLongConverter Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */

package com.vaadin.v7.data.util.converter;

import java.util.Date;
import java.util.Locale;

/**
 * A converter that converts from {@link Long} to {@link Date} and back.
 *
 * @author Vaadin Ltd
 * @since 7.0
 */
@Deprecated
public class DateToLongConverter implements Converter {

    /*
     * (non-Javadoc)
     *
     * @see
     * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
     * java.lang.Class, java.util.Locale)
     */
    @Override
    public Long convertToModel(Date value, Class targetType,
            Locale locale) {
        if (value == null) {
            return null;
        }

        return value.getTime();
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang
     * .Object, java.lang.Class, java.util.Locale)
     */
    @Override
    public Date convertToPresentation(Long value,
            Class targetType, Locale locale) {
        if (targetType != getPresentationType()) {
            throw new ConversionException(
                    "Converter only supports " + getPresentationType().getName()
                            + " (targetType was " + targetType.getName() + ")");
        }
        if (value == null) {
            return null;
        }

        return new Date(value);
    }

    /*
     * (non-Javadoc)
     *
     * @see com.vaadin.data.util.converter.Converter#getModelType()
     */
    @Override
    public Class getModelType() {
        return Long.class;
    }

    /*
     * (non-Javadoc)
     *
     * @see com.vaadin.data.util.converter.Converter#getPresentationType()
     */
    @Override
    public Class getPresentationType() {
        return Date.class;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy