package uk.ac.ebi.quickgo.common.converter;

import java.util.Collections;
import java.util.List;

import static java.util.Objects.nonNull;

/**
 * A flat field representing a {@link String} value. These are stored
 * within a (possibly nested) list of {@link FlatField}s inside the
 * {@link FlatFieldBuilder} class.
 *
 * Created 26/11/15
 * @author Edd
 */
public class FlatFieldLeaf extends FlatField {
    private static final String PRINTED_NULL_STRING = " ";

    private String value;
    private final static List<FlatField> EMPTY_LIST = Collections.unmodifiableList(Collections.emptyList());

    private FlatFieldLeaf(String value) {
        if (nonNull(value) && !value.trim().isEmpty()) {
            this.value = value;
        } else {
            this.value = PRINTED_NULL_STRING;
        }
    }

    public static FlatFieldLeaf newFlatFieldLeaf(String value) {
        return new FlatFieldLeaf(value);
    }

    public static FlatFieldLeaf newFlatFieldLeaf() {
        return new FlatFieldLeaf(PRINTED_NULL_STRING);
    }

    @Override public List<FlatField> getFields() {
        return EMPTY_LIST;
    }

    @Override public String buildString() {
        return this.value;
    }

    @Override public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        FlatFieldLeaf that = (FlatFieldLeaf) o;

        return !(value != null ? !value.equals(that.value) : that.value != null);
    }

    @Override public int hashCode() {
        return value != null ? value.hashCode() : 0;
    }

    @Override public String toString() {
        return "FlatFieldLeaf{" +
                "value='" + value + '\'' +
                '}';
    }
}

@@ -384,14 +384,17 @@
 eaf 
-extend
+implement
 s Fl
@@ -505,20 +505,20 @@
 ate 
-final 
 static
+ final
  Lis
@@ -529,16 +529,50 @@
 atField%3E
+ EMPTY_LIST;%0A%0A    static %7B%0A       
  EMPTY_L
@@ -631,16 +631,22 @@
 List());
+%0A    %7D
 %0A%0A    pr

format and change variable modifier order to be consistent with standards