package org.cobbzilla.wizard.model;

import java.util.Collection;
import java.util.Comparator;
import java.util.stream.Collectors;

import static org.cobbzilla.util.daemon.ZillaRuntime.empty;

public interface NamedEntity {

    int NAME_MAXLEN = 100;
    String[] NAME_FIELD_ARRAY = {"name"};

    String getName ();
    default boolean hasName () { return !empty(getName()); }

    Comparator<? extends NamedEntity> NAME_COMPARATOR
            = (Comparator<NamedEntity>) (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName());

    static String names (Collection<? extends NamedEntity> c) {
        return empty(c) ? "(empty)" : c.stream().map(NamedEntity::getName).collect(Collectors.joining(", "));
    }

}

@@ -47,26 +47,17 @@
 va.util.
-Collection
+*
 ;%0Aimport
@@ -67,26 +67,33 @@
 va.util.
-Comparator
+function.Function
 ;%0Aimport
@@ -707,10 +707,274 @@
 %0A    %7D%0A%0A
+    static %3CE extends NamedEntity%3E Map%3CString, E%3E nameMap (Collection%3CE%3E things) %7B%0A        return empty(things)%0A                ? Collections.emptyMap()%0A                : things.stream().collect(Collectors.toMap(NamedEntity::getName, Function.identity()));%0A    %7D%0A%0A
 %7D%0A

add nameMap utility