package stexfires.core;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;
import java.util.stream.LongStream;
import java.util.stream.Stream;

/**
 * A Record contains {@link Field}s with values.
 * <p>
 * It must be immutable and thread-safe.
 * The field index must start with 0.
 *
 * @author Mathias Kalb
 * @since 0.1
 */
public interface Record extends Serializable {

    Field[] arrayOfFields();

    List<Field> listOfFields();

    Stream<Field> streamOfFields();

    String getCategory();

    default String getCategoryOrElse(String other) {
        return getCategory() != null ? getCategory() : other;
    }

    default Optional<String> getCategoryAsOptional() {
        return Optional.ofNullable(getCategory());
    }

    default Stream<String> streamOfCategory() {
        if (getCategory() == null) {
            return Stream.empty();
        }
        return Stream.of(getCategory());
    }

    Long getRecordId();

    default Optional<Long> getRecordIdAsOptional() {
        return Optional.ofNullable(getRecordId());
    }

    default LongStream streamOfRecordId() {
        if (getRecordId() == null) {
            return LongStream.empty();
        }
        return LongStream.of(getRecordId());
    }

    int size();

    default boolean isEmpty() {
        return size() == 0;
    }

    default boolean isValidIndex(int index) {
        return (index >= 0) && (index < size());
    }

    Field getFieldAt(int index);

    default Field getFirstField() {
        return getFieldAt(0);
    }

    default Field getLastField() {
        return getFieldAt(size() - 1);
    }

    default String getValueAt(int index) {
        return isValidIndex(index) ? getFieldAt(index).getValue() : null;
    }

    default String getValueAtOrElse(int index, String other) {
        return getValueAt(index) != null ? getValueAt(index) : other;
    }

    default String getValueOfFirstField() {
        return !isEmpty() ? getFirstField().getValue() : null;
    }

    default String getValueOfLastField() {
        return !isEmpty() ? getLastField().getValue() : null;
    }

    /**
     * Compare class, category, recordId and all fields.
     */
    boolean equals(Object other);

    int hashCode();

    String toString();

}

@@ -1945,33 +1945,32 @@
 %0A        return 
-!
 isEmpty() ? getF
@@ -1960,24 +1960,31 @@
  isEmpty() ?
+ null :
  getFirstFie
@@ -1990,39 +1990,32 @@
 eld().getValue()
- : null
 ;%0A    %7D%0A%0A    def
@@ -2065,17 +2065,16 @@
  return 
-!
 isEmpty(
@@ -2076,16 +2076,23 @@
 mpty() ?
+ null :
  getLast
@@ -2101,39 +2101,32 @@
 eld().getValue()
- : null
 ;%0A    %7D%0A%0A    /**

Change method code to avoid inspection warnings