package uk.gov.register.presentation;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

public enum Cardinality {
    ONE("1"),MANY("n");

    private final String id;

    Cardinality(String id) {
        this.id = id;
    }

    private static final Map<String,Cardinality> cardinalityMap = ImmutableMap.of(
            ONE.getId(),  ONE,
            MANY.getId(), MANY
    );

    /**
     * this method shouldn't be needed -- the @JsonValue annotation has a special case for enums that
     * means it can be used for both serialization and deserialization -- but there's a bug.
     * See <a href="https://github.com/dropwizard/dropwizard/issues/699">dropwizard issue #699</a>
     */
    @JsonCreator
    public static Cardinality fromId(String id) {
        return cardinalityMap.get(id);
    }

    @JsonValue
    public String getId() {
        return id;
    }
}

@@ -139,55 +139,8 @@
 lue;
-%0Aimport com.google.common.collect.ImmutableMap;
 %0A%0Aim
@@ -154,19 +154,29 @@
 va.util.
-Map
+stream.Stream
 ;%0A%0Apubli
@@ -313,161 +313,8 @@
  %7D%0A%0A
-    private static final Map%3CString,Cardinality%3E cardinalityMap = ImmutableMap.of(%0A            ONE.getId(),  ONE,%0A            MANY.getId(), MANY%0A    );%0A%0A
     
@@ -705,29 +705,112 @@
 urn 
-cardinalityMap
+Stream.of(values())%0A                .filter(x -%3E x.getId().equals(id))%0A                .findFirst()
 .get(
-id
 );%0A 

remove duplication of Cardinality values