private void addMetaZones ( TypeSpec . Builder type , Map < String , MetaZone > metazones ) { ClassName metazoneType = ClassName . get ( Types . PACKAGE_CLDR_DATES , "MetaZone" ) ; TypeName mapType = ParameterizedTypeName . get ( MAP , STRING , metazoneType ) ; FieldSpec . Builder field = FieldSpec . builder ( mapType , "metazones" , PROTECTED , STATIC , FINAL ) ; CodeBlock . Builder code = CodeBlock . builder ( ) ; code . beginControlFlow ( "new $T<$T, $T>() {" , HashMap . class , String . class , metazoneType ) ; for ( Map . Entry < String , MetaZone > entry : metazones . entrySet ( ) ) { String zoneId = entry . getKey ( ) ; MetaZone zone = entry . getValue ( ) ; code . beginControlFlow ( "\nput($S, new $T($S,\n new $T.Entry[] " , zoneId , metazoneType , zoneId , metazoneType ) ; int size = zone . metazones . size ( ) ; Collections . reverse ( zone . metazones ) ; for ( int i = 0 ; i < size ; i ++ ) { MetaZoneEntry meta = zone . metazones . get ( i ) ; if ( i > 0 ) { code . add ( ",\n" ) ; } code . add ( " new $T.Entry($S, " , metazoneType , meta . metazone ) ; if ( meta . from != null ) { code . add ( "/* $L */ $L, " , meta . fromString , meta . from . toEpochSecond ( ) ) ; } else { code . add ( "-1, " ) ; } if ( meta . to != null ) { code . add ( "/* $L */ $L)" , meta . toString , meta . to . toEpochSecond ( ) ) ; } else { code . add ( "-1)" ) ; } } code . endControlFlow ( "))" ) ; } code . endControlFlow ( "\n}" ) ; field . initializer ( code . build ( ) ) ; type . addField ( field . build ( ) ) ; MethodSpec . Builder method = MethodSpec . methodBuilder ( "getMetazone" ) . addModifiers ( PUBLIC , STATIC ) . addParameter ( String . class , "zoneId" ) . addParameter ( ZonedDateTime . class , "date" ) . returns ( String . class ) ; method . addStatement ( "$T zone = metazones.get(zoneId)" , metazoneType ) ; method . addStatement ( "return zone == null ? null : zone.applies(date)" ) ; type . addMethod ( method . build ( ) ) ; }
Populate the metaZone mapping .