private static Map < ExpectedLabels , Integer > mapLabels ( final List < String > labels ) { final Map < ExpectedLabels , Integer > map = new EnumMap <> ( ExpectedLabels . class ) ; final List < ExpectedLabels > unusedLabels = new ArrayList <> ( Arrays . asList ( ExpectedLabels . values ( ) ) ) ; for ( int index = 0 ; index < labels . size ( ) ; index ++ ) { final String next = labels . get ( index ) ; ExpectedLabels labelValue ; try { labelValue = ExpectedLabels . valueOf ( next ) ; unusedLabels . remove ( labelValue ) ; if ( map . containsKey ( labelValue ) ) { LOGGER . warn ( "Duplicate state label: {} ({})" , next , labels ) ; } map . put ( labelValue , index ) ; } catch ( final IllegalArgumentException e ) { LOGGER . warn ( "Unexpected state label: {}" , next ) ; } } for ( final ExpectedLabels label : unusedLabels ) { LOGGER . warn ( "Unused label: {}" , label ) ; } return map ; }
Produces a mapping of label to index for use in parsing state values to the appropriate slot in the state object .