001package Torello.Browser.JsonAST; 002 003import Torello.JSON.ReadJSON; 004 005import Torello.Java.ReadOnly.ROArrayListBuilder; 006import Torello.Java.ReadOnly.ReadOnlyList; 007 008import javax.json.JsonArray; 009import javax.json.JsonObject; 010 011/** 012 * Invokes the {@link PPR} constructor on every instance of a {@link JsonArray}. The array to 013 * parse is named by the input {@link WhichPPR} parameter. 014 */ 015@Torello.JavaDoc.Annotations.StaticFunctional 016@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="CONSTRUCTOR_JDHBI") 017public class Helper$GetPPRLists 018{ 019 private Helper$GetPPRLists() { } 020 021 static ReadOnlyList<PPR> get( 022 final TCE THIS, 023 final JsonObject jo, 024 final WhichPPR which 025 ) 026 { 027 // getJsonArray(jo, propertyName, boolean isOptional, boolean throwOnNull) 028 final JsonArray arr = ReadJSON.getJsonArray(jo, which.propName, true, true); 029 030 if (arr == null) return null; 031 032 if (arr.size() == 0) THIS.verifyThrow( 033 "This TCE's JSON Definition had an 'array' property named [" + which.propName + "], but " + 034 "unfortunately, that array had zero elements." 035 ); 036 037 final ROArrayListBuilder<PPR> roalb = new ROArrayListBuilder<>(arr.size()); 038 039 for (int i=0; i < arr.size(); i++) 040 041 roalb.add( 042 new PPR( 043 THIS, 044 arr.getJsonObject(i), 045 which, 046 i 047 )); 048 049 // roalb.sort((PPR a, PPR b) -> a.name.compareTo(b.name)); 050 return roalb.build(); 051 } 052 053}