package io.vertx.ext.web.templ.handlebars.impl;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.Set;
import com.github.jknack.handlebars.ValueResolver;
import io.vertx.core.json.JsonArray;
public class JsonArrayValueResolver implements ValueResolver {
public static final ValueResolver INSTANCE = new JsonArrayValueResolver();
@Override
public Object resolve(final Object context) {
if (context instanceof JsonArray) {
return context;
}
return UNRESOLVED;
}
@Override
public Object resolve(Object context, String name) {
if (context instanceof JsonArray) {
JsonArray jsonArray = ((JsonArray) context);
if ("length".equals(name) || "size".equals(name)) {
return jsonArray.size();
}
Object value = jsonArray.getValue(Integer.valueOf(name));
if (value != null) {
return value;
}
}
return UNRESOLVED;
}
@Override
public Set<Entry<String, Object>> propertySet(final Object context) {
return Collections.emptySet();
}
}