Runtime populated enum-like class
<p>I have many objects using few classes (means elements visual categorization like in html+css). Classes are not known at compile-time and they are used in conditions many times.</p>

<p>To improve performance I've got one solution:</p>

<pre><code>public class ElementClass {

    private static final Map&lt;String, ElementClass&gt; classes = new HashMap&lt;&gt;();

    public final String name;
    public final String lowerName;

    public ElementClass(String name, String lowerName) {
        this.name = name;
        this.lowerName = lowerName;
    }

    public static ElementClass get(String name) {
        String lower = name.toLowerCase();
        ElementClass c = classes.get(lower);
        if (c == null) {
            c = new ElementClass(name, lower);
            classes.put(lower, c);
        }
        return c;
    }
}
</code></pre>

<p>The method <code>get</code> is used very less than comparison of <code>ElementClass</code> variables. It is in parsing configurations and for some <code>static</code> variables. I'm not sure if this is the best way to go, because I'm Java beginner.</p>

<p>The examples usage of <code>ElementClass</code>:</p>

<pre><code>// contains element styles based on it's class
Map&lt;ElementClass,ElementStyle&gt; styles;

void exampleFunction() {
    ElementClass c = ElementClass.get("special");
    for( Element e : elements ) {
        if( e.cls == c ) doSomethingSpecial();
    }
}
</code></pre>
