com.googlecode.objectify.impl.translate.NullSafeTranslator Maven / Gradle / Ivy
Show all versions of objectify Show documentation
package com.googlecode.objectify.impl.translate;
import com.googlecode.objectify.impl.Path;
/**
* Handles null checking so we don't have to do it everywhere.
*
* @author Jeff Schnitzer
*/
abstract public class NullSafeTranslator implements Translator
{
@Override
final public P load(D node, LoadContext ctx, Path path) throws SkipException {
if (node == null)
return null;
else
return loadSafe(node, ctx, path);
}
@Override
final public D save(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException {
if (pojo == null)
return null;
else
return saveSafe(pojo, index, ctx, path);
}
/**
* Implement this, returning a proper translated value
* @param node will never be null
*/
abstract protected P loadSafe(D node, LoadContext ctx, Path path) throws SkipException;
/**
* Implement this, returning a proper translated value
* @param pojo will never be null
*/
abstract protected D saveSafe(P pojo, boolean index, SaveContext ctx, Path path) throws SkipException;
}