com.github.fedy2.weather.binding.adapter.PressureUnitAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yahoo-weather-java-api Show documentation
Show all versions of yahoo-weather-java-api Show documentation
A Java library for the yahoo weather RSS feed service
The newest version!
/**
*
*/
package com.github.fedy2.weather.binding.adapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.fedy2.weather.data.unit.PressureUnit;
/**
* Units of barometric pressure adapter, in for pounds per square inch or mb for millibars.
* @author "Federico De Faveri [email protected]"
*
*/
public class PressureUnitAdapter extends XmlAdapter {
private static final String MB = "mb";
private static final String IN = "in";
private Logger logger = LoggerFactory.getLogger(PressureUnitAdapter.class);
/**
* {@inheritDoc}
*/
@Override
public PressureUnit unmarshal(String v) throws Exception {
if (IN.equalsIgnoreCase(v)) return PressureUnit.IN;
if (MB.equalsIgnoreCase(v)) return PressureUnit.MB;
logger.warn("Unknown pressure unit \"{}\"", v);
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String marshal(PressureUnit v) throws Exception {
switch (v) {
case IN: return IN;
case MB: return MB;
default: return "";
}
}
}