![JAR search and dependency download from the Maven repository](/logo.png)
org.loom.appengine.converter.GeoPtConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of loom-appengine Show documentation
Show all versions of loom-appengine Show documentation
Uploads all artifacts belonging to configuration ':archives'.
The newest version!
package org.loom.appengine.converter;
import javax.inject.Singleton;
import org.loom.converter.AbstractSimpleConverter;
import org.loom.i18n.MessagesRepository;
import org.loom.util.StringUtils;
import com.google.appengine.api.datastore.GeoPt;
@Singleton
public class GeoPtConverter extends AbstractSimpleConverter {
/** the character used as separator */
public static final String separator = ":";
public GeoPtConverter() {
super(GeoPt.class);
}
@Override
public Object getAsObject(String value) {
try {
if (StringUtils.isEmpty(value)) {
return null;
}
String[] parts = StringUtils.split(value, separator);
if (parts.length != 2) {
throw new NumberFormatException();
}
return new GeoPt(Float.parseFloat(parts[0]), Float.parseFloat(parts[1]));
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Malformed String that cannot be converted to GeoPt: " + value, e);
}
}
@Override
protected String getAsTextImpl(Object value, MessagesRepository repository) {
GeoPt point = (GeoPt) value;
return point.getLatitude() + separator + point.getLongitude();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy