public Optional<Boolean> maybeGetBoolean(int index) { return maybeGet(index).map(e -> e.asBoolean()); }
default Optional<Boolean> maybeGetBoolean(String...labels) { return maybeGet(labels).map(e -> e.asBoolean()); }
default Optional<Boolean> maybeGetBoolean(String...labels) { return getJsonObject().maybeGet(labels).map(e -> e.asBoolean()); }
/** * @param field * name of the field * @param defaultValue * default value that is returned if the field has no value * @return value of the field as a boolean */ default boolean get(@Nonnull String field, boolean defaultValue) { JsonElement e = get(field); if (e == null) { return defaultValue; } else { if (e.isBoolean()) { return e.asBoolean(); } else if (e.isNumber()) { return e.asInt() > 0; } else if (e.isPrimitive()) { return Boolean.valueOf(e.asString()); } else { throw new JsonTypeMismatchException("expected primitive value but was " + e.type()); } } }
/** * Get a value at a particular path in an object structure. * * @param labels * one or more text labels * @return value or null if it doesn't exist at the specified path */ default Boolean getBoolean(final String... labels) { JsonElement jsonElement = get(labels); if (jsonElement == null || jsonElement.isNull()) { return null; } else { if (jsonElement.isBoolean()) { return jsonElement.asBoolean(); } else if (jsonElement.isNumber()) { return jsonElement.asInt() > 0; } else if (jsonElement.isPrimitive()) { return Boolean.valueOf(jsonElement.asString()); } else { throw new JsonTypeMismatchException("expected primitive value but was " + jsonElement.type()); } } }
break; case bool: yaml.writeBoolean(e.asBoolean()); break; case number: