class PresetUtils {

    private List<PreviewPreset> presets;

    public void savePreset(PreviewPreset preset) {<FILL_FUNCTION_BODY>}

    public PreviewPreset[] getPresets() {
        if (presets == null) {
            presets = new ArrayList<>();
            loadPresets();
        }
        return presets.toArray(new PreviewPreset[0]);
    }

    private void loadPresets() {
        FileObject folder = FileUtil.getConfigFile("previewpresets");
        if (folder != null) {
            for (FileObject child : folder.getChildren()) {
                if (child.isValid() && child.hasExt("xml")) {
                    try (InputStream stream = child.getInputStream()) {
                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder = factory.newDocumentBuilder();
                        Document document = builder.parse(stream);
                        PreviewPreset preset = readXML(document);
                        addPreset(preset);
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
        }
    }

    private void writeXML(Document doc, PreviewPreset preset) {
        Element presetE = doc.createElement("previewpreset");
        presetE.setAttribute("name", preset.getName());
        presetE.setAttribute("version", "0.8.1");

        for (Entry<String, Object> entry : preset.getProperties().entrySet()) {
            String propertyName = entry.getKey();
            try {
                Object propertyValue = entry.getValue();
                if (propertyValue != null) {
                    String serialized = PreviewProperties.getValueAsText(propertyValue);
                    if (serialized != null) {
                        Element propertyE = doc.createElement("previewproperty");
                        propertyE.setAttribute("name", propertyName);
                        propertyE.setAttribute("class", propertyValue.getClass().getName());
                        propertyE.setTextContent(serialized);
                        presetE.appendChild(propertyE);
                    }
                }
            } catch (Exception ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        doc.appendChild(presetE);
    }

    private PreviewPreset readXML(Document document) {
        DefaultPreset defaultPreset =
            new DefaultPreset();//For retrieving property class if it is not in the xml (old serialization)

        Element presetE = document.getDocumentElement();
        Map<String, Object> propertiesMap = new HashMap<>();
        String presetName = presetE.getAttribute("name");

        NodeList propertyList = presetE.getElementsByTagName("previewproperty");
        for (int i = 0; i < propertyList.getLength(); i++) {
            Node n = propertyList.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                Element propertyE = (Element) n;
                String name = propertyE.getAttribute("name");
                String valueClassName = propertyE.hasAttribute(name) ? propertyE.getAttribute("class") : null;
                String stringValue = propertyE.getTextContent();
                Class valueClass = null;
                if (valueClassName != null) {
                    try {
                        valueClass = Class.forName(valueClassName);
                    } catch (ClassNotFoundException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                } else {
                    Object defaultValue = defaultPreset.getProperties().get(name);
                    if (defaultValue != null) {
                        valueClass = defaultValue.getClass();
                    }
                }
                if (valueClass != null) {
                    Object value = PreviewProperties.readValueFromText(stringValue, valueClass);
                    if (value != null) {
                        propertiesMap.put(name, value);
                    }
                }
            }
        }
        return new PreviewPreset(presetName, propertiesMap);
    }

    protected void addPreset(PreviewPreset preset) {
        presets.add(preset);
    }
}

        int exist = -1;
        for (int i = 0; i < presets.size(); i++) {
            PreviewPreset p = presets.get(i);
            if (p.getName().equals(preset.getName())) {
                exist = i;
                break;
            }
        }
        if (exist == -1) {
            addPreset(preset);
        } else {
            presets.set(exist, preset);
        }

        try {
            //Create file if dont exist
            FileObject folder = FileUtil.getConfigFile("previewpresets");
            if (folder == null) {
                folder = FileUtil.getConfigRoot().createFolder("previewpresets");
            }

            String filename = DigestUtils.sha1Hex(preset.getName());//Safe filename

            FileObject presetFile = folder.getFileObject(filename, "xml");
            if (presetFile == null) {
                presetFile = folder.createData(filename, "xml");
            }

            //Create doc
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = factory.newDocumentBuilder();
            final Document document = documentBuilder.newDocument();
            document.setXmlVersion("1.0");
            document.setXmlStandalone(true);

            //Write doc
            writeXML(document, preset);

            //Write XML file
            try (OutputStream outputStream = presetFile.getOutputStream()) {
                Source source = new DOMSource(document);
                Result result = new StreamResult(outputStream);
                Transformer transformer = TransformerFactory.newInstance().newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.transform(source, result);
            }
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }
    
<no_super_class>