001package org.unix4j.codegen.optset.def;
002
003import java.util.LinkedHashMap;
004import java.util.Map;
005import java.util.Set;
006import java.util.SortedSet;
007import java.util.TreeSet;
008
009import org.unix4j.codegen.command.def.OptionDef;
010import org.unix4j.codegen.def.AbstractElementDef;
011import org.unix4j.codegen.optset.OptionHelper;
012
013public class ActiveSetDef extends AbstractElementDef {
014        
015        public ActiveSetDef(Map<String, OptionDef> active) {
016                this(new OptionHelper().getNameWithOptionPostfix("Active", active.values()), active.keySet());
017        }
018        public ActiveSetDef(String name, Set<String> active) {
019                this.name = name;
020                this.active.addAll(active);
021        }
022
023        public final String name;
024        public final SortedSet<String> active = new TreeSet<String>();                                                          //option (long) names
025        public final Map<String, ActiveSetDef> next = new LinkedHashMap<String, ActiveSetDef>();        //key: option (long) names (does not contain self refs)
026
027        public Set<String> getAllOptions() {
028                final Set<String> options = new TreeSet<String>();
029                options.addAll(active);
030                options.addAll(next.keySet());
031                return options;
032        }
033        @Override
034        public String toString() {
035                return "\n" + 
036                        "\tname:\t" + name + "\n" +
037                        "\tactive:\t" + active + "\n" +
038                        "\tnext:\t" + toNextString() + "\n";
039        }
040
041        private String toNextString() {
042                final Map<String, String> nextMap = new LinkedHashMap<String, String>();
043                for (final Map.Entry<String, ActiveSetDef> e : next.entrySet()) {
044                        nextMap.put(e.getKey(), e.getValue().name);
045                }
046                return nextMap.toString();
047        }
048}