package stexfires.io.properties;

import stexfires.util.LineSeparator;

import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.util.Objects;

/**
 * @author Mathias Kalb
 * @since 0.1
 */
public final class PropertiesFileSpec {

    public static final String DELIMITER = "=";
    public static final String COMMENT_PREFIX = "#";
    public static final String NULL_VALUE = "";

    private final Charset charset;

    private final LineSeparator lineSeparator;
    private final boolean escapeUnicode;
    private final boolean dateComment;
    private final CodingErrorAction codingErrorAction;

    public PropertiesFileSpec(Charset charset, LineSeparator lineSeparator, boolean escapeUnicode, boolean dateComment,
                              CodingErrorAction codingErrorAction) {
        Objects.requireNonNull(charset);
        Objects.requireNonNull(lineSeparator);
        Objects.requireNonNull(codingErrorAction);
        this.charset = charset;
        this.lineSeparator = lineSeparator;
        this.escapeUnicode = escapeUnicode;
        this.dateComment = dateComment;
        this.codingErrorAction = codingErrorAction;
    }

    public Charset getCharset() {
        return charset;
    }

    public LineSeparator getLineSeparator() {
        return lineSeparator;
    }

    public boolean isEscapeUnicode() {
        return escapeUnicode;
    }

    public boolean isDateComment() {
        return dateComment;
    }

    public CodingErrorAction getCodingErrorAction() {
        return codingErrorAction;
    }

}

@@ -141,16 +141,43 @@
 Action;%0A
+import java.nio.file.Path;%0A
 import j
@@ -432,16 +432,177 @@
  = %22%22;%0A%0A
+    public static final CodingErrorAction DEFAULT_CODING_ERROR_ACTION = CodingErrorAction.REPORT;%0A    public static final boolean DEFAULT_DATE_COMMENT = false;%0A%0A
     priv
@@ -628,17 +628,16 @@
 harset;%0A
-%0A
     priv
@@ -650,36 +650,45 @@
 nal 
-LineSeparator lineSeparator;
+CodingErrorAction codingErrorAction;%0A
 %0A   
@@ -786,43 +786,35 @@
 nal 
-CodingErrorAction codingErrorAction
+LineSeparator lineSeparator
 ;%0A%0A 
@@ -863,36 +863,74 @@
 et, 
-LineSeparator lineSeparator,
+CodingErrorAction codingErrorAction,%0A                             
  boo
@@ -1004,43 +1004,35 @@
     
-CodingErrorAction codingErrorAction
+LineSeparator lineSeparator
 ) %7B%0A
@@ -1103,29 +1103,33 @@
 NonNull(
-lineSeparator
+codingErrorAction
 );%0A     
@@ -1158,57 +1158,189 @@
 ull(
-codingErrorAction);%0A        this.charset = charse
+lineSeparator);%0A        this.charset = charset;%0A        this.codingErrorAction = codingErrorAction;%0A        this.escapeUnicode = escapeUnicode;%0A        this.dateComment = dateCommen
 t;%0A 
@@ -1390,138 +1390,875 @@
     
+%7D%0A%0A
     
-this.escapeUnicode = escapeUnicode
+public static PropertiesFileSpec write(Charset charset,%0A                                           boolean escapeUnicode,%0A                                           LineSeparator lineSeparator) %7B%0A        return new PropertiesFileSpec(charset, DEFAULT_CODING_ERROR_ACTION,%0A                escapeUnicode, DEFAULT_DATE_COMMENT,%0A                lineSeparator)
 ;%0A    
+%7D%0A%0A
     
-this.dateComment = dateComment;%0A        this.codingErrorAction = codingErrorAction
+public static PropertiesFileSpec write(Charset charset, CodingErrorAction codingErrorAction,%0A                                           boolean escapeUnicode, boolean dateComment,%0A                                           LineSeparator lineSeparator) %7B%0A        return new PropertiesFileSpec(charset, codingErrorAction,%0A                escapeUnicode, dateComment,%0A                lineSeparator);%0A    %7D%0A%0A    public PropertiesFile file(Path path) %7B%0A        return new PropertiesFile(path, this)
 ;%0A  
@@ -2342,38 +2342,46 @@
 lic 
-LineSeparator getLineSeparator
+CodingErrorAction getCodingErrorAction
 () %7B
@@ -2396,29 +2396,33 @@
  return 
-lineSeparator
+codingErrorAction
 ;%0A    %7D%0A
@@ -2585,46 +2585,38 @@
 lic 
-CodingErrorAction getCodingErrorAction
+LineSeparator getLineSeparator
 () %7B
@@ -2631,33 +2631,29 @@
  return 
-codingErrorAction
+lineSeparator
 ;%0A    %7D%0A

Refactor PropertiesFileSpec