public static Optional < Integer > toInteger ( Object arg ) { if ( arg instanceof Number ) { return Optional . of ( ( ( Number ) arg ) . intValue ( ) ) ; } else if ( arg instanceof String ) { Optional < ? extends Number > optional = toNumber ( arg ) ; if ( optional . isPresent ( ) ) { return Optional . of ( optional . get ( ) . intValue ( ) ) ; } else { return Optional . empty ( ) ; } } else { return Optional . empty ( ) ; } }
Returns int value of argument if possible wrapped in Optional Interprets String as Number