下面列出了com.fasterxml.jackson.databind.node.BooleanNode#FALSE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Preparation Step: create a node for a schema representing the given method's associated return type.
*
* @param method method to populate the schema node for
* @param isNullable whether the method's return value may be null
* @param forceInlineDefinition whether to generate an inline definition without registering it in this context
* @param ignoredDefinitionProvider first custom definition provider to ignore
* @return schema node representing the given method's return type
*/
private JsonNode createMethodSchema(MethodScope method, boolean isNullable, boolean forceInlineDefinition,
CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider) {
if (method.isVoid()) {
return BooleanNode.FALSE;
}
ObjectNode subSchema = this.generatorConfig.createObjectNode();
ObjectNode methodAttributes = AttributeCollector.collectMethodAttributes(method, this);
this.populateMemberSchema(method, subSchema, isNullable, forceInlineDefinition, methodAttributes, ignoredDefinitionProvider);
return subSchema;
}
public JsonNode call(JsonNode input, JsonNode[] arguments) {
// if data is missing then it doesn't match, end of story
if (arguments[0].isNull())
return BooleanNode.FALSE;
String string = NodeUtils.toString(arguments[0], false);
String regexp = NodeUtils.toString(arguments[1], true);
if (regexp == null)
throw new JsltException("test() can't test null regexp");
Pattern p = getRegexp(regexp);
java.util.regex.Matcher m = p.matcher(string);
return NodeUtils.toJson(m.find(0));
}
public JsonNode call(JsonNode input, JsonNode[] arguments) {
JsonNode value = arguments[0];
if (value.isNull())
return value;
else if (!value.isArray())
throw new JsltException("all() requires an array, not " + value);
for (int ix = 0; ix < value.size(); ix++) {
JsonNode node = value.get(ix);
if (!NodeUtils.isTrue(node))
return BooleanNode.FALSE;
}
return BooleanNode.TRUE;
}
public JsonNode call(JsonNode input, JsonNode[] arguments) {
JsonNode value = arguments[0];
if (value.isNull())
return value;
else if (!value.isArray())
throw new JsltException("any() requires an array, not " + value);
for (int ix = 0; ix < value.size(); ix++) {
JsonNode node = value.get(ix);
if (NodeUtils.isTrue(node))
return BooleanNode.TRUE;
}
return BooleanNode.FALSE;
}
public JsonNode call(JsonNode input, JsonNode[] arguments) {
if (arguments[1].isNull())
return BooleanNode.FALSE; // nothing is contained in null
else if (arguments[1].isArray()) {
for (int ix = 0; ix < arguments[1].size(); ix++)
if (arguments[1].get(ix).equals(arguments[0]))
return BooleanNode.TRUE;
} else if (arguments[1].isObject()) {
String key = NodeUtils.toString(arguments[0], true);
if (key == null)
return BooleanNode.FALSE;
return NodeUtils.toJson(arguments[1].has(key));
} else if (arguments[1].isTextual()) {
String sub = NodeUtils.toString(arguments[0], true);
if (sub == null)
return BooleanNode.FALSE;
String str = arguments[1].asText();
return NodeUtils.toJson(str.indexOf(sub) != -1);
} else
throw new JsltException("Contains cannot operate on " + arguments[1]);
return BooleanNode.FALSE;
}
public JsonNode apply(Scope scope, JsonNode input) {
boolean v1 = NodeUtils.isTrue(left.apply(scope, input));
if (!v1)
return BooleanNode.FALSE;
boolean v2 = NodeUtils.isTrue(right.apply(scope, input));
return NodeUtils.toJson(v1 && v2);
}
public static boolean isTrue(JsonNode value) {
return value != BooleanNode.FALSE &&
!(value.isObject() && value.size() == 0) &&
!(value.isTextual() && value.asText().length() == 0) &&
!(value.isArray() && value.size() == 0) &&
!(value.isNumber() && value.doubleValue() == 0.0) &&
!value.isNull();
}
public JsonNode convert(Object node) {
if (node == null)
return NullNode.instance;
else if ((Boolean) node)
return BooleanNode.TRUE;
else
return BooleanNode.FALSE;
}
@Override
public BooleanNode parseValue(Object input) {
if (input instanceof Boolean) {
return (Boolean) input ? BooleanNode.TRUE : BooleanNode.FALSE;
}
if (input instanceof BooleanNode) {
return (BooleanNode) input;
}
throw valueParsingException(input, Boolean.class, BooleanNode.class);
}
@Override
public ObjectNode toJson(JsonProperty jsonProperty) {
Function<Object,JsonNode> nodeCreator = value -> ((Boolean) value) ? BooleanNode.TRUE
: BooleanNode.FALSE;
return primitiveJsonPropertyBuilder.forProperty(jsonProperty)
.withType("boolean")
.withDefaultValue(BooleanNode.FALSE)
.withDefaultAndAllowedValues(nodeCreator).build();
}
public JsonNode call(JsonNode input, JsonNode[] arguments) {
if (values.contains(arguments[0]))
return BooleanNode.TRUE;
else
return BooleanNode.FALSE;
}
public static JsonNode toJson(boolean value) {
if (value)
return BooleanNode.TRUE;
else
return BooleanNode.FALSE;
}
@Override
public BooleanNode parseLiteral(Object input) {
return literalOrException(input, BooleanValue.class).isValue() ? BooleanNode.TRUE : BooleanNode.FALSE;
}