
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
51 lines
894 B
Plaintext
51 lines
894 B
Plaintext
== Why is this an issue?
|
|
|
|
When all the keys of a Map are values from the same enum, the ``++Map++`` can be replaced with an ``++EnumMap++``, which can be much more efficient than other sets because the underlying data structure is a simple array.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class MyClass {
|
|
|
|
public enum COLOR {
|
|
RED, GREEN, BLUE, ORANGE;
|
|
}
|
|
|
|
public void mapMood() {
|
|
Map<COLOR, String> moodMap = new HashMap<COLOR, String> ();
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public class MyClass {
|
|
|
|
public enum COLOR {
|
|
RED, GREEN, BLUE, ORANGE;
|
|
}
|
|
|
|
public void mapMood() {
|
|
EnumMap<COLOR, String> moodMap = new EnumMap<> (COLOR.class);
|
|
}
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Convert this Map to an EnumMap.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|