A few extra lines of code to support a fourth enum policy: name only.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6526 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -266,18 +266,21 @@ public abstract class Streamer
|
|||||||
|
|
||||||
// create streamers for enum types
|
// create streamers for enum types
|
||||||
if (target.isEnum()) {
|
if (target.isEnum()) {
|
||||||
// if not ORDINAL and we have a ByteEnum, stream using that
|
switch (ENUM_POLICY) {
|
||||||
if (ENUM_POLICY != EnumPolicy.ORDINAL) {
|
case NAME_WITH_BYTE_ENUM:
|
||||||
|
case ORDINAL_WITH_BYTE_ENUM:
|
||||||
if (ByteEnum.class.isAssignableFrom(target)) {
|
if (ByteEnum.class.isAssignableFrom(target)) {
|
||||||
return new ByteEnumStreamer(target);
|
return new ByteEnumStreamer(target);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// otherwise, if by name and not a ByteEnum...
|
|
||||||
if (ENUM_POLICY == EnumPolicy.NAME_WITH_BYTE_ENUM) {
|
switch (ENUM_POLICY) {
|
||||||
|
case NAME_WITH_BYTE_ENUM:
|
||||||
|
case NAME:
|
||||||
return new NameEnumStreamer(target);
|
return new NameEnumStreamer(target);
|
||||||
|
|
||||||
} else {
|
default:
|
||||||
// if ORDINAL, or ORDINAL_WITH_BYTE_ENUM and not a ByteEnum, stream by ordinal
|
|
||||||
List<?> universe = ImmutableList.copyOf(target.getEnumConstants());
|
List<?> universe = ImmutableList.copyOf(target.getEnumConstants());
|
||||||
int size = universe.size();
|
int size = universe.size();
|
||||||
if (size <= (1 << (Byte.SIZE - 1))) {
|
if (size <= (1 << (Byte.SIZE - 1))) {
|
||||||
@@ -937,7 +940,7 @@ public abstract class Streamer
|
|||||||
*/
|
*/
|
||||||
protected enum EnumPolicy
|
protected enum EnumPolicy
|
||||||
{
|
{
|
||||||
NAME_WITH_BYTE_ENUM, ORDINAL, ORDINAL_WITH_BYTE_ENUM;
|
NAME, NAME_WITH_BYTE_ENUM, ORDINAL, ORDINAL_WITH_BYTE_ENUM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the static enum policy by checking the com.threerings.io.enumPolicy system prop.
|
* Create the static enum policy by checking the com.threerings.io.enumPolicy system prop.
|
||||||
|
|||||||
Reference in New Issue
Block a user