/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.imaging;

import org.apache.commons.imaging.formats.bmp.BmpImagingParameters;
import org.apache.commons.imaging.formats.gif.GifImagingParameters;
import org.apache.commons.imaging.formats.icns.IcnsImagingParameters;
import org.apache.commons.imaging.formats.ico.IcoImagingParameters;
import org.apache.commons.imaging.formats.jpeg.JpegImagingParameters;
import org.apache.commons.imaging.formats.pcx.PcxImagingParameters;
import org.apache.commons.imaging.formats.png.PngImagingParameters;
import org.apache.commons.imaging.formats.pnm.PnmImagingParameters;
import org.apache.commons.imaging.formats.psd.PsdImagingParameters;
import org.apache.commons.imaging.formats.rgbe.RgbeImagingParameters;
import org.apache.commons.imaging.formats.tiff.TiffImagingParameters;
import org.apache.commons.imaging.formats.wbmp.WbmpImagingParameters;
import org.apache.commons.imaging.formats.xbm.XbmImagingParameters;
import org.apache.commons.imaging.formats.xpm.XpmImagingParameters;

import java.util.function.Supplier;

/**
 * Enum of known image formats.
 */
public enum ImageFormats implements ImageFormat {
    UNKNOWN(null),
    BMP(BmpImagingParameters::new, "bmp", "dib"),
    DCX(PcxImagingParameters::new, "dcx"),
    GIF(GifImagingParameters::new, "gif"),
    ICNS(IcnsImagingParameters::new, "icns"),
    ICO(IcoImagingParameters::new, "ico"),
    JBIG2(null),
    JPEG(JpegImagingParameters::new, "jpg", "jpeg"),
    PAM(PnmImagingParameters::new, "pam"),
    PSD(PsdImagingParameters::new, "psd"),
    PBM(PnmImagingParameters::new, "pbm"),
    PGM(PnmImagingParameters::new, "pgm"),
    PNM(PnmImagingParameters::new, "pnm"),
    PPM(PnmImagingParameters::new, "ppm"),
    PCX(PcxImagingParameters::new, "pcx", "pcc"),
    PNG(PngImagingParameters::new, "png"),
    RGBE(RgbeImagingParameters::new, "rgbe"),
    TGA(null),
    TIFF(TiffImagingParameters::new, "tif", "tiff"),
    WBMP(WbmpImagingParameters::new, "wbmp"),
    XBM(XbmImagingParameters::new, "xbm"),
    XPM(XpmImagingParameters::new, "xpm");

    private final String[] extensions;

    ImageFormats(Supplier<? extends ImagingParameters> factory, String ...extensions) {
        this.extensions = extensions;
    }

    @Override
    public String getName() {
        return name();
    }

    @Override
    public String[] getExtensions() {
        return this.extensions.clone();
    }

    @Override
    public String getDefaultExtension() {
        return this.extensions[0];
    }
}

@@ -837,1008 +837,8 @@
 g;%0A%0A
-import org.apache.commons.imaging.formats.bmp.BmpImagingParameters;%0Aimport org.apache.commons.imaging.formats.gif.GifImagingParameters;%0Aimport org.apache.commons.imaging.formats.icns.IcnsImagingParameters;%0Aimport org.apache.commons.imaging.formats.ico.IcoImagingParameters;%0Aimport org.apache.commons.imaging.formats.jpeg.JpegImagingParameters;%0Aimport org.apache.commons.imaging.formats.pcx.PcxImagingParameters;%0Aimport org.apache.commons.imaging.formats.png.PngImagingParameters;%0Aimport org.apache.commons.imaging.formats.pnm.PnmImagingParameters;%0Aimport org.apache.commons.imaging.formats.psd.PsdImagingParameters;%0Aimport org.apache.commons.imaging.formats.rgbe.RgbeImagingParameters;%0Aimport org.apache.commons.imaging.formats.tiff.TiffImagingParameters;%0Aimport org.apache.commons.imaging.formats.wbmp.WbmpImagingParameters;%0Aimport org.apache.commons.imaging.formats.xbm.XbmImagingParameters;%0Aimport org.apache.commons.imaging.formats.xpm.XpmImagingParameters;%0A%0Aimport java.util.function.Supplier;%0A%0A
 /**%0A
@@ -935,20 +935,16 @@
 UNKNOWN(
-null
 ),%0A    B
@@ -950,217 +950,81 @@
 BMP(
-BmpImagingParameters::new, %22bmp%22, %22dib%22),%0A    DCX(PcxImagingParameters::new, %22dcx%22),%0A    GIF(GifImagingParameters::new, %22gif%22),%0A    ICNS(IcnsImagingParameters::new, %22icns%22),%0A    ICO(IcoImagingParameters::new, 
+%22bmp%22, %22dib%22),%0A    DCX(%22dcx%22),%0A    GIF(%22gif%22),%0A    ICNS(%22icns%22),%0A    ICO(
 %22ico
@@ -1037,20 +1037,16 @@
   JBIG2(
-null
 ),%0A    J
@@ -1053,440 +1053,168 @@
 PEG(
-JpegImagingParameters::new, %22jpg%22, %22jpeg%22),%0A    PAM(PnmImagingParameters::new, %22pam%22),%0A    PSD(PsdImagingParameters::new, %22psd%22),%0A    PBM(PnmImagingParameters::new, %22pbm%22),%0A    PGM(PnmImagingParameters::new, %22pgm%22),%0A    PNM(PnmImagingParameters::new, %22pnm%22),%0A    PPM(PnmImagingParameters::new, %22ppm%22),%0A    PCX(PcxImagingParameters::new, %22pcx%22, %22pcc%22),%0A    PNG(PngImagingParameters::new, %22png%22),%0A    RGBE(RgbeImagingParameters::new, 
+%22jpg%22, %22jpeg%22),%0A    PAM(%22pam%22),%0A    PSD(%22psd%22),%0A    PBM(%22pbm%22),%0A    PGM(%22pgm%22),%0A    PNM(%22pnm%22),%0A    PPM(%22ppm%22),%0A    PCX(%22pcx%22, %22pcc%22),%0A    PNG(%22png%22),%0A    RGBE(
 %22rgb
@@ -1230,12 +1230,8 @@
 TGA(
-null
 ),%0A 
@@ -1242,176 +1242,66 @@
 IFF(
-TiffImagingParameters::new, %22tif%22, %22tiff%22),%0A    WBMP(WbmpImagingParameters::new, %22wbmp%22),%0A    XBM(XbmImagingParameters::new, %22xbm%22),%0A    XPM(XpmImagingParameters::new, 
+%22tif%22, %22tiff%22),%0A    WBMP(%22wbmp%22),%0A    XBM(%22xbm%22),%0A    XPM(
 %22xpm
@@ -1366,55 +1366,8 @@
 ats(
-Supplier%3C? extends ImagingParameters%3E factory, 
 Stri
@@ -1694,11 +1694,44 @@
 ions
-%5B0%5D
+ != null ? this.extensions%5B0%5D : null
 ;%0A  

Remove unused factory, and prevent NPE (thanks @darkma773r)