Merge pull request #65 from TouchInstinct/enum_converter

enum converter with default value
This commit is contained in:
Gavriil 2017-07-05 15:03:40 +03:00 committed by GitHub
commit f1bbb5ee6f
1 changed files with 10 additions and 0 deletions

View File

@ -35,10 +35,17 @@ public class LoganSquareEnumConverter<T extends Enum & LoganSquareEnum> extends
@NonNull
private final T[] enumValues;
@Nullable
private final T defaultValue;
public LoganSquareEnumConverter(@NonNull final T[] enumValues) {
this(enumValues, null);
}
public LoganSquareEnumConverter(@NonNull final T[] enumValues, @Nullable final T defaultValue) {
super();
this.enumValues = enumValues;
this.defaultValue = defaultValue;
}
@Nullable
@ -52,6 +59,9 @@ public class LoganSquareEnumConverter<T extends Enum & LoganSquareEnum> extends
return value;
}
}
if (defaultValue != null) {
return defaultValue;
}
throw new ShouldNotHappenException();
}