|
4 | 4 |
|
5 | 5 | # enum-mapper |
6 | 6 | The main use: make sure that you always handle all available constants of an enum. An annotation processor will |
7 | | - make sure that you get a compile-time error otherwise. |
| 7 | + make sure that you get a compile-time error otherwise: see [Full Enum Mapper](#full-enum-mapper). |
| 8 | +You can also use a [Partial Mapper](#partial-enum-mapper) and it supports [Reverse Mapping](#reverse-mapping). |
8 | 9 |
|
9 | 10 | ## Build Configuration |
10 | 11 |
|
@@ -72,7 +73,7 @@ public class AppUtil { |
72 | 73 | ``` |
73 | 74 | Then the annotation processor will create a full enum-mapper for `ColorEnum` and for `BoolEnum`. |
74 | 75 |
|
75 | | -Hint: when you want a map a single enum, you don't need the curly braces (for the array-syntax) |
| 76 | +Hint: when you want to map a single enum, you don't need the curly braces (for the array-syntax) |
76 | 77 | ```java |
77 | 78 | @EnumMappers(ColorEnum.class) |
78 | 79 | public class AppUtil { |
@@ -107,6 +108,7 @@ ExtremeSeasons.getEnumOrNull("Sommer"); // returns the enum-cons |
107 | 108 | ExtremeSeasons.getEnumOrDefault("Fruehling", FALL)); // returns the enum-constant FALL |
108 | 109 | ExtremeSeasons.getEnumOrRaise("Fruehling"); // throws an IllegalArgumentException |
109 | 110 | ``` |
| 111 | +When you do a reverse mapping the mapped values should of course be unique. |
110 | 112 |
|
111 | 113 | ### Alternatives |
112 | 114 | This section mentions some alternative approaches that you can use instead of this annotation processor. |
@@ -145,6 +147,7 @@ public enum AlternativeBool { |
145 | 147 | #### IDE checks |
146 | 148 | Some IDEs allow you to activate a check that will warn you when you forget an enum constant in a switch statement: |
147 | 149 | * [Eclipse: Ensuring completeness of switch statements](http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-ensuring_switch_completeness.htm) |
| 150 | + |
148 | 151 | **Advantages** |
149 | 152 | * this approach does not need an annotation processor |
150 | 153 | * direct and immediate feedback |
|
0 commit comments