private static TechReportPlacement processPlaceLabels ( GraphContext graphContext , Set < String > tagNames ) { TagGraphService tagService = new TagGraphService ( graphContext ) ; if ( tagNames . size ( ) < 3 ) throw new WindupException ( "There should always be exactly 3 placement labels - row, sector, column/box. It was: " + tagNames ) ; if ( tagNames . size ( ) > 3 ) LOG . severe ( "There should always be exactly 3 placement labels - row, sector, column/box. It was: " + tagNames ) ; TechReportPlacement placement = new TechReportPlacement ( ) ; final TagModel placeSectorsTag = tagService . getTagByName ( "techReport:placeSectors" ) ; final TagModel placeBoxesTag = tagService . getTagByName ( "techReport:placeBoxes" ) ; final TagModel placeRowsTag = tagService . getTagByName ( "techReport:placeRows" ) ; Set < String > unknownTags = new HashSet <> ( ) ; for ( String name : tagNames ) { final TagModel tag = tagService . getTagByName ( name ) ; if ( null == tag ) continue ; if ( TagGraphService . isTagUnderTagOrSame ( tag , placeSectorsTag ) ) { placement . sector = tag ; } else if ( TagGraphService . isTagUnderTagOrSame ( tag , placeBoxesTag ) ) { placement . box = tag ; } else if ( TagGraphService . isTagUnderTagOrSame ( tag , placeRowsTag ) ) { placement . row = tag ; } else { unknownTags . add ( name ) ; } } placement . unknown = unknownTags ; LOG . fine ( String . format ( "\t\tLabels %s identified as: sector: %s, box: %s, row: %s" , tagNames , placement . sector , placement . box , placement . row ) ) ; if ( placement . box == null || placement . row == null ) { LOG . severe ( String . format ( "There should always be exactly 3 placement labels - row, sector, column/box. Found: %s, of which box: %s, row: %s" , tagNames , placement . box , placement . row ) ) ; } return placement ; }
From three tagNames if one is under sectorTag and one under rowTag returns the remaining one which is supposedly the a box label . Otherwise returns null .