[ https://issues.apache.org/jira/browse/LIVY-654?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleksandr Shevchenko updated LIVY-654: -------------------------------------- Description: Kind.scala, SessionState.scala and StatementState.java don't include a method for string validation. It might be very useful to verify if some string can be converted to an enum type. For example, to parse JSON string we need to write something like this (to prevent IllegalStateException): {code:java} Try { value match { case JsString(state) => SessionState(state) case _ => throw MyException } } match { case Success(state) => state case Failure(ex) => throw MyException } {code} it can be simplified to: {code:java} value match { case JsString(state) if SessionState.isValid(state) => SessionState(state) case _ => throw MyException } {code} The second problem is StatementState.java enum use Pascal naming instead of upper case [https://github.com/apache/incubator-livy/blob/412ccc8fcf96854fedbe76af8e5a6fec2c542d25/rsc/src/main/java/org/apache/livy/rsc/driver/StatementState.java#L26] For example, Waiting instead of WAITING. This isn't fit Java code style. In this case, we can't use StatementState.valueOf("waiting".toUpperCase()) as usually but StatementState.valueOf(state.toLowerCase().capitalize). Not sure if we can change it now. was: Kind.scala, SessionState.scala and StatementState.java don't include a method for string validation. It might be very useful to verify if some string can be converted to an enum type. For example, to parse JSON string we need to write something like this (to prevent IllegalStateException): {code:java} Try { value match { case JsString(state) => SessionState(state) case _ => throw MyException } } match { case Success(state) => state case Failure(ex) => throw MyException } {code} it can be simplified to: {code:java} value match { case JsString(state) if SessionState.isValid(state) => SessionState(state) case _ => throw MyException } {code} The second problem is StatementState.java enum use Pascal naming instead of upper case [https://github.com/apache/incubator-livy/blob/412ccc8fcf96854fedbe76af8e5a6fec2c542d25/rsc/src/main/java/org/apache/livy/rsc/driver/StatementState.java#L26] For example, Waiting instead of WAITING. In this case, we can't use StatementState.valueOf("waiting".toUpperCase()) as usually. Not sure if we can change it now. > Validate string state/kind of session/statement > ------------------------------------------------ > > Key: LIVY-654 > URL: https://issues.apache.org/jira/browse/LIVY-654 > Project: Livy > Issue Type: Improvement > Reporter: Oleksandr Shevchenko > Priority: Minor > > Kind.scala, SessionState.scala and StatementState.java don't include a method > for string validation. It might be very useful to verify if some string can > be converted to an enum type. > > For example, to parse JSON string we need to write something like this (to > prevent IllegalStateException): > > {code:java} > Try { > value match { > case JsString(state) => SessionState(state) > case _ => throw MyException > } > } > match { > case Success(state) => state > case Failure(ex) => throw MyException > } > {code} > it can be simplified to: > {code:java} > value match { > case JsString(state) if SessionState.isValid(state) => SessionState(state) > case _ => throw MyException > } > {code} > > The second problem is StatementState.java enum use Pascal naming instead of > upper case > > [https://github.com/apache/incubator-livy/blob/412ccc8fcf96854fedbe76af8e5a6fec2c542d25/rsc/src/main/java/org/apache/livy/rsc/driver/StatementState.java#L26] > For example, Waiting instead of WAITING. This isn't fit Java code style. > In this case, we can't use StatementState.valueOf("waiting".toUpperCase()) as > usually but > StatementState.valueOf(state.toLowerCase().capitalize). Not sure if we can > change it now. -- This message was sent by Atlassian Jira (v8.3.2#803003)