public static TagModel getSingleParent ( TagModel tag ) { final Iterator < TagModel > parents = tag . getDesignatedByTags ( ) . iterator ( ) ; if ( ! parents . hasNext ( ) ) throw new WindupException ( "Tag is not designated by any tags: " + tag ) ; final TagModel maybeOnlyParent = parents . next ( ) ; if ( parents . hasNext ( ) ) { StringBuilder sb = new StringBuilder ( ) ; tag . getDesignatedByTags ( ) . iterator ( ) . forEachRemaining ( x -> sb . append ( x ) . append ( ", " ) ) ; throw new WindupException ( String . format ( "Tag %s is designated by multiple tags: %s" , tag , sb . toString ( ) ) ) ; } return maybeOnlyParent ; }
Returns a single parent of the given tag . If there are multiple parents throws a WindupException .