Commit f1e0a0b2 authored by Nico Mack's avatar Nico Mack

SelectorWidget now allows multiple coronas with identical indices.

parent 6c3468b4
......@@ -8,10 +8,12 @@ import lu.list.itis.dkd.tui.widget.builder.SelectorWidgetBuilder;
import lu.list.itis.dkd.tui.widget.corona.SelectableCorona;
import lu.list.itis.dkd.tui.widget.state.StateManager;
import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
......@@ -35,6 +37,9 @@ public class SelectorWidget extends ValueWidget {
public static final int NONE = -1;
private static final Logger LOGGER = LoggerFactory.getLogger(SelectorWidget.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -87,17 +92,23 @@ public class SelectorWidget extends ValueWidget {
protected int getNumberOfPositions() {
List<SelectableCorona> selectableCoronas = getCoronas(SelectableCorona.class);
Multimap<Integer, SelectableCorona> alreadySeen = TreeMultimap.create();
boolean duplicateIndices = false;
for (SelectableCorona corona : selectableCoronas) {
Integer index = corona.getIndex();
if (alreadySeen.containsKey(index)) {
for (SelectableCorona identical : alreadySeen.get(index)) {
Preconditions.checkArgument(!identical.getClass().equals(corona.getClass()), "Duplicate Index detected for indexed Corona!"); //$NON-NLS-1$
duplicateIndices = identical.getClass().equals(corona.getClass());
}
}
alreadySeen.put(index, corona);
}
if (duplicateIndices) {
LOGGER.warn("Duplicate Indices detected for indexed Corona!"); //$NON-NLS-1$
}
return alreadySeen.keySet().size();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment