/** * A flexible alternative to determine a RandomKind from a string. * @param s the string to read (can be null) * @return null if it matched an unknown kind, or a RandomKind otherwise */ public static RandomKind whichValue( String s ) { RandomKind result = null; for( RandomKind rk : RandomKind.values()) { if( rk.toString().equalsIgnoreCase( s )) { result = rk; break; } } return result; } }
/** * @return the randomKind */ public RandomKind getRandomKind() { return RandomKind.whichValue( this.rawKind ); }
@Test public void tetstRandomKind_whichValue() { Assert.assertNull( RandomKind.whichValue( null )); Assert.assertNull( RandomKind.whichValue( "" )); Assert.assertEquals( RandomKind.PORT, RandomKind.whichValue( "port" )); Assert.assertEquals( RandomKind.PORT, RandomKind.whichValue( "pOrt" )); } }