/*******************************************************************************
 * Copyright 2019 2Fi Business Solutions Ltd.
 *
 * This code is part of the Core project.
 *
 * This code is copyrighted. Under no circumstances should any party, people,
 * or organization should redistribute any portions of this code in any form,
 * either verbatim or through electronic media, to any third parties, unless
 * under explicit written permission by 2Fi Business Solutions Ltd.
 ******************************************************************************/
package com.ffii.core.support;

import java.beans.PropertyEditorSupport;

import com.ffii.core.utils.NumberUtils;
import com.ffii.core.utils.StringUtils;

/**
 * Property Editor for Double (Defaults to <code>null</code> if cannot be parsed, never throw an Exception)
 *
 * @see NumberUtils#toDouble(String, Double)
 *
 * @author Patrick
 */
public class SimpleDoubleEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String value) throws IllegalArgumentException {
		setValue(NumberUtils.toDouble(value, null));
	}

	@Override
	public String getAsText() {
		return (getValue() == null ? StringUtils.EMPTY : getValue().toString());
	}

}
