001package io.jstach.jstachio.context; 002 003import java.util.Iterator; 004import java.util.Map; 005 006import org.eclipse.jdt.annotation.Nullable; 007 008import io.jstach.jstache.JStache; 009import io.jstach.jstachio.context.Internal.ObjectContextNode; 010 011/** 012 * Extend this class to make {@link JStache} model act like JSON object or a 013 * java.util.Map. 014 * 015 * @see ContextNode 016 * @author agentgt 017 */ 018public non-sealed abstract class ObjectContext implements ObjectContextNode { 019 020 /** 021 * Do nothing constructor 022 */ 023 protected ObjectContext() { 024 } 025 026 /** 027 * Get a value by key. This is analagous to {@link Map#get(Object)}. 028 * @param key not null 029 * @return value mapped to key. 030 */ 031 @Override 032 public abstract @Nullable Object getValue(String key); 033 034 @Override 035 public final Object object() { 036 return this; 037 } 038 039 @Override 040 public final @Nullable ContextNode get(String field) { 041 return ObjectContextNode.super.get(field); 042 } 043 044 @Override 045 public final @Nullable ContextNode find(String field) { 046 return ObjectContextNode.super.find(field); 047 } 048 049 @Override 050 public final @Nullable ContextNode parent() { 051 return null; 052 } 053 054 @SuppressWarnings("exports") 055 @Override 056 public final Iterator<@Nullable ContextNode> iterator() { 057 return ObjectContextNode.super.iterator(); 058 } 059 060 @Override 061 public final boolean isFalsey() { 062 return ObjectContextNode.super.isFalsey(); 063 } 064 065}