package ahlers.phantom.embedded;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import de.flapdoodle.embed.process.distribution.IVersion;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumSet;

/**
 * Defines supported PhantomJS versions.
 *
 * @author [[mailto:michael@ahlers.consulting Michael Ahlers]]
 */
public enum PhantomVersion
        implements IVersion {

    V211("2.1.1");

    public static final PhantomVersion LATEST = V211;

    private final String label;

    PhantomVersion(final String label) {
        this.label = label;
    }

    @Nonnull
    public String getLabel() {
        return label;
    }

    @Override
    public String asInDownloadPath() {
        return getLabel();
    }

    @Override
    public String toString() {
        return getLabel();
    }

    public static PhantomVersion byLabel(final String label) {
        for (final PhantomVersion version : values()) {
            if (label.equals(version.getLabel())) {
                return version;
            }
        }

        final Iterable<String> labels = Iterables.transform(EnumSet.allOf(PhantomVersion.class), new Function<PhantomVersion, String>() {
            @Nullable
            @Override
            public String apply(@Nullable final PhantomVersion input) {
                return input.getLabel();
            }
        });

        throw new IllegalArgumentException(String.format("No version matching \"%s\" (must be among: %s).", label, StringUtils.join(labels)));
    }

}

@@ -662,24 +662,88 @@
 bel;%0A    %7D%0A%0A
+    /**%0A     * @return A human-readable version number.%0A     */%0A
     @Nonnull
@@ -795,32 +795,93 @@
 n label;%0A    %7D%0A%0A
+    /**%0A     * @return Value of %7B@link #getLabel()%7D.%0A     */%0A
     @Override%0A  
@@ -1026,24 +1026,213 @@
 l();%0A    %7D%0A%0A
+    /**%0A     * @param label Lookup value for a version.%0A     * @return A matching %7B@link PhantomVersion%7D.%0A     * @throws IllegalArgumentException If the %7B@code label%7D is not known.%0A     */%0A
     public s
@@ -1486,16 +1486,32 @@
 labels =
+%0A               
  Iterabl
@@ -1613,16 +1613,24 @@
         
+ 
+       
 @Nullabl
@@ -1639,24 +1639,32 @@
             
+     
+   
 @Override%0A  
@@ -1657,24 +1657,32 @@
   @Override%0A
+        
             
@@ -1753,24 +1753,32 @@
             
+ 
+       
 return input
@@ -1794,34 +1794,50 @@
 ();%0A            
-%7D%0A
+        %7D%0A        
         %7D);%0A%0A   

Add docs