blob: cd9189d3b7a85d29ff99a4d2a035f8f468653414 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
<<<<<<< HEAD
* Pierre Allard - initial API and implementation
* Regent L'Archeveque
*
=======
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
>>>>>>> refs/heads/eclipse_pa
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.databinding.converters;
import java.text.NumberFormat;
import java.text.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StringToLongConverter extends AbstractNumberConverter {
private static final Logger Logger = LoggerFactory.getLogger(StringToLongConverter.class);
public StringToLongConverter() {
super(String.class, Long.class);
}
public StringToLongConverter(NumberFormat numberFormat) {
super(String.class, Long.class);
setNumberFormat(numberFormat);
}
@Override
public Object convert(Object fromObject) {
if (getNumberFormat() != null) {
try {
return new Long(getNumberFormat().parse((String) fromObject).longValue());
} catch (ParseException e) {
Logger.error(e.getMessage(), e);
}
}
return new Long((String) fromObject);
}
}