switch (token) { case VALUE_NULL: return ValueFactory.newNil(); case VALUE_TRUE: return ValueFactory.newBoolean(true);
@Override public ImmutableNilValue immutableValue() { return ValueFactory.newNil(); }
@Override public Value getOrNilValue(int index) { List<Value> l = list(); if (l.size() < index && index >= 0) { return ValueFactory.newNil(); } return l.get(index); }
Value visited = visit(newPath, v); newValue.add(i++, jsonColumn.getTailNameValue()); newValue.add(i++, visited == null ? ValueFactory.newNil() : visited); Value visited = visit(newPath, v); newValue.add(i++, jsonColumn.getTailNameValue()); newValue.add(i++, visited == null ? ValueFactory.newNil() : visited);
public JsonColumn(String path, Type type, Value defaultValue, String src) { Path compiledPath = PathCompiler.compile(path); Path compiledSrc = src == null ? compiledPath : PathCompiler.compile(src); RootPathToken compiledRoot = (RootPathToken) compiledPath.getRoot(); RootPathToken compiledSrcRoot = (RootPathToken) compiledSrc.getRoot(); this.path = compiledPath.toString(); this.type = type; this.defaultValue = (defaultValue == null ? ValueFactory.newNil() : defaultValue); this.src = compiledSrc.toString(); this.pathValue = ValueFactory.newString(path); this.parentPath = compiledPath.getParentPath(); this.tailIndex = getTailIndex(compiledRoot); this.parentPathValue = ValueFactory.newString(parentPath); String tailName = getTailName(compiledRoot); this.tailNameValue = tailName == null ? ValueFactory.newNil() : ValueFactory.newString(tailName); this.srcValue = ValueFactory.newString(this.src); this.srcParentPath = compiledSrc.getParentPath(); this.srcTailIndex = getTailIndex(compiledSrcRoot); this.srcParentPathValue = ValueFactory.newString(this.srcParentPath); String srcTailName = getTailName(compiledSrcRoot); this.srcTailNameValue = srcTailName == null ? ValueFactory.newNil() : ValueFactory.newString(srcTailName); if (!srcParentPath.equals(parentPath)) { throw new ConfigException(String.format("The branch (parent path) of src \"%s\" must be same with of name \"%s\" yet", src, path)); } }
static Value getDefault(PluginTask task, String name, Type type, ColumnConfig columnConfig) { Object defaultValue = ColumnVisitorImpl.getDefault(task, name, type, columnConfig); if (defaultValue == null) { return ValueFactory.newNil(); } if (type instanceof BooleanType) { return ValueFactory.newBoolean((Boolean) defaultValue); } else if (type instanceof LongType) { return ValueFactory.newInteger((Long) defaultValue); } else if (type instanceof DoubleType) { return ValueFactory.newFloat((Double) defaultValue); } else if (type instanceof StringType) { return ValueFactory.newString((String) defaultValue.toString()); } else if (type instanceof JsonType) { return (Value) defaultValue; } else if (type instanceof TimestampType) { throw new ConfigException("type: timestamp is not available in json path"); } else { throw new ConfigException(String.format("type: '%s' is not supported", type)); } }
return ValueFactory.newNil();
@Test public void getTailNameValue() { assertEquals(ValueFactory.newString("baz"), new JsonColumn("$['foo'].bar.baz", Types.BOOLEAN).getTailNameValue()); assertEquals(ValueFactory.newString("bar"), new JsonColumn("$.foo.bar", Types.BOOLEAN).getTailNameValue()); assertEquals(ValueFactory.newString("foo"), new JsonColumn("$.foo", Types.BOOLEAN).getTailNameValue()); assertEquals(ValueFactory.newNil(), new JsonColumn("$.foo[0][1]", Types.BOOLEAN).getTailNameValue()); assertEquals(ValueFactory.newNil(), new JsonColumn("$.foo[0]", Types.BOOLEAN).getTailNameValue()); assertEquals(ValueFactory.newNil(), new JsonColumn("$[0]", Types.BOOLEAN).getTailNameValue()); }
@Test public void initialize() { try { JsonColumn column = new JsonColumn("$.foo.bar", Types.BOOLEAN); assertEquals("$['foo']['bar']", column.getSrc()); assertEquals(ValueFactory.newNil(), column.getDefaultValue()); } catch (Exception e) { fail(); } try { Value defaultValue = ValueFactory.newBoolean(true); JsonColumn column = new JsonColumn("$['foo']['bar']", Types.BOOLEAN, defaultValue); assertEquals("$['foo']['bar']", column.getSrc()); assertEquals(defaultValue, column.getDefaultValue()); } catch (Exception e) { fail(); } }
case NIL: readByte(); return ValueFactory.newNil(); case BOOLEAN: return ValueFactory.newBoolean(unpackBoolean());