You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UNREAD, READ, UNKNOWN;
/**
* <p>
* Returns the enumerated value for the specified integer. If the value is
* out of range, UNKOWN is returned.
* <ul>
* <li>0 - {@code UNREAD}
* <li>1 - {@code READ}
* </ul>
*
* @param in
* @return the enumeration
*/
public static ReadStatus forInt(int in) {
switch (in) {
case 0:
return UNREAD;
case 1:
return READ;
}
return UNKNOWN;
}
/**
* /**
* <p>
* Returns the enumerated value for the specified integer. If the value is
* out of range, UNKOWN is returned.
* <ul>
* <li>"UNREAD" - {@code UNREAD}
* <li>"READ" - {@code READ}
* </ul>
*
* @param in
* @return the enumeration
*/
public static ReadStatus forString(String in) {
if ("READ".equalsIgnoreCase(in))
return READ;
if ("UNREAD".equalsIgnoreCase(in))
return UNREAD;
return UNKNOWN;
}
/**
* Returns an integer representation of the enumeration
*
* @return an integer representation of the enumeration
*/
public int toInt() {
switch (this) {
case UNREAD:
return 0;
case READ:
return 1;
default:
return -1;
}
}
/**
* Returns an string representation of the enumeration
*
* @return an string representation of the enumeration
*/
@Override
public String toString() {
switch (this) {
case UNREAD:
return "UNREAD";
case READ:
return "READ";
default:
return null;
}
}
public class TheTable {
private ReadFlag status;
}
With the appropriate SQL inserts doing a "toInt()" or "toString()" and the appropriate cursor reads doing the "Enumeration.forInt()" or "Enumeration.forString()" calls.
What do you think? Sorry, I'm just really fond of enumerations.
Was thinking of offering some code. But in the current Code Generator's construction, do you think this would be incredibly difficult or just a bit trivial?
The text was updated successfully, but these errors were encountered:
I'd like the ability to add "enum" classes and refer to them in a field definition. And specify in the field definition to store a string or an int.
Could create something like:
"enums": [
{
"enum_name": "ReadFlag",
"enum_values": [
{
"value": "UNREAD",
"intvalue": "0",
"string_value": "UNREAD"
},
{
"value": "READ",
"intvalue": "1",
"string_value": "READ"
},
{
"value": "UNSPECIFIED",
"intvalue": "-1",
"string_value": "UNSPECIFIED"
},
]
},
and then the resulting class would be:
public enum ReadStatus {
}
Then a reference something like:
"tables": [
{
"table_name": "TheTable",
"fields": [
{
"name": "status",
"type": "int",
"enumeration": "ReadFlag"
},
The resulting table class would be:
public class TheTable {
private ReadFlag status;
}
With the appropriate SQL inserts doing a "toInt()" or "toString()" and the appropriate cursor reads doing the "Enumeration.forInt()" or "Enumeration.forString()" calls.
What do you think? Sorry, I'm just really fond of enumerations.
Was thinking of offering some code. But in the current Code Generator's construction, do you think this would be incredibly difficult or just a bit trivial?
The text was updated successfully, but these errors were encountered: