001package Torello.Browser.JsonAST; 002 003import Torello.Java.ReadOnly.ReadOnlyList; 004import Torello.Java.ReadOnly.ReadOnlyArrayList; 005 006import Torello.Java.Additional.Ret4; 007 008import Torello.JSON.ReadJSON; 009import Torello.JSON.ReadBoxedJSON; 010import Torello.JSON.RJArrIntoStream; 011import Torello.JSON.JFlag; 012 013import javax.json.JsonObject; 014import javax.json.JsonArray; 015 016/** 017 * Contains three helper functions, which help construct the nodes of an AST Tree. 018 * To see these features, make sure to click the "View Hilited Source" button, and review the 019 * code for this class. 020 */ 021@Torello.JavaDoc.Annotations.StaticFunctional 022@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="CONSTRUCTOR_JDHBI") 023public class Helper$Misc 024{ 025 private Helper$Misc() { } 026 027 static ReadOnlyList<PropName> getPropNames(final JsonObject jo) 028 { 029 // The complete list of Json-Properties contained by this object (at the top level) 030 final java.util.Set<String> propNamesSet = jo.keySet(); 031 032 return new ReadOnlyArrayList<>( 033 propNamesSet, 034 (String name) -> PropName.valueOf(name.toUpperCase()), 035 propNamesSet.size() 036 ); 037 } 038 039 static 040 Ret4<String, Boolean, Boolean, Boolean> 041 getDescAndFlags 042 (final JsonObject jo) 043 { 044 // getString(JsonObject jo, String propertyName, boolean isOptional, boolean throwOnNull) 045 final String tempDescStr = ReadJSON.getString(jo, "description", true, true); 046 final String description = (tempDescStr == null) ? "-" : tempDescStr; 047 048 final int f = JFlag.RETURN_DEFVAL_ON_MISSING; 049 050 // getBoolean(JsonObject jo, String propertyName, int FLAGS, boolean defaultValue) 051 final boolean optional = ReadBoxedJSON.getBoolean(jo, "optional", f, false); 052 final boolean experimental = ReadBoxedJSON.getBoolean(jo, "experimental", f, false); 053 final boolean deprecated = ReadBoxedJSON.getBoolean(jo, "deprecated", f, false); 054 055 return new Ret4<>(description, optional, experimental, deprecated); 056 } 057 058 059 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 060 // Possible 'dependencies' String-Array (they are domain names) 061 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 062 // 063 // getJsonArray 064 // (JsonObject jo, String propertyName, boolean isOptional, boolean throwOnNull) 065 066 static ReadOnlyList<String> depAsStrs(final JsonObject jo) 067 { 068 final JsonArray depJsonArray = 069 ReadJSON.getJsonArray(jo, "dependencies", true, true); 070 071 return (depJsonArray == null) 072 073 ? ReadOnlyArrayList.emptyROAL() 074 075 // strArr(JsonArray ja, String defaultValue, int FLAGS) 076 : RJArrIntoStream 077 .strArr(depJsonArray, null, 0) 078 .sorted(String::compareTo) 079 .collect(ReadOnlyArrayList.streamCollector()); 080 } 081}