Exemplo n.º 1
0
        public void AddChild(CommandNode <TSource> node)
        {
            if (node is RootCommandNode <TSource> )
            {
                throw new InvalidOperationException($"Cannot add a {nameof(RootCommandNode<TSource>)} as a child to any other {nameof(CommandNode<TSource>)}");
            }

            if (_children.TryGetValue(node.Name, out var child))
            {
                // We've found something to merge onto
                if (node.Command != null)
                {
                    child.Command = node.Command;
                }

                foreach (var grandchild in node.Children)
                {
                    child.AddChild(grandchild);
                }
            }
            else
            {
                _children.Add(node.Name, node);
                if (node is LiteralCommandNode <TSource> literalCommandNode)
                {
                    _literals.Add(node.Name, literalCommandNode);
                }
                else if (node is ArgumentCommandNode <TSource> argumentCommandNode)
                {
                    _arguments.Add(node.Name, argumentCommandNode);
                }
            }
        }
Exemplo n.º 2
0
 protected CommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
 {
     Command          = command;
     Requirement      = requirement;
     Redirect         = redirect;
     RedirectModifier = modifier;
     IsFork           = forks;
 }
Exemplo n.º 3
0
 public bool Equals(CommandNode <TSource> other)
 {
     if (other is null)
     {
         return(false);
     }
     return(ReferenceEquals(this, other) || EqualsInternal(other));
 }
Exemplo n.º 4
0
        public int CompareTo(CommandNode <TSource> o)
        {
            if (this is LiteralCommandNode <TSource> == o is LiteralCommandNode <TSource> )
            {
                return(string.Compare(SortedKey, o.SortedKey, StringComparison.Ordinal));
            }

            return((o is LiteralCommandNode <TSource>) ? 1 : -1);
        }
Exemplo n.º 5
0
 protected CommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks, string desc = "")
 {
     Command          = command;
     Requirement      = requirement;
     Redirect         = redirect;
     RedirectModifier = modifier;
     IsFork           = forks;
     Description      = desc;
 }
Exemplo n.º 6
0
        public void AddChild(CommandNode <TSource> node)
        {
            if (node is RootCommandNode <TSource> )
            {
                throw new InvalidOperationException($"Cannot add a {nameof(RootCommandNode<TSource>)} as a child to any other {nameof(CommandNode<TSource>)}");
            }

            if (_children.TryGetValue(node.Name, out var child))
            {
                // We've found something to merge onto
                if (node.Command != null)
                {
                    child.Command = node.Command;
                }

                foreach (var grandchild in node.Children)
                {
                    child.AddChild(grandchild);
                }
            }
            else
            {
                _children.Add(node.Name, node);
                if (node is LiteralCommandNode <TSource> literalCommandNode)
                {
                    _literals.Add(node.Name, literalCommandNode);
                }
                else if (node is ArgumentCommandNode <TSource> argumentCommandNode)
                {
                    _arguments.Add(node.Name, argumentCommandNode);
                }
            }

            //FIXME: What is the equivalent of this? It looks like this is sorting by entry?
            //       It's probably a performance optimization
            //children = children.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
        }
Exemplo n.º 7
0
 public LiteralCommandNode(string literal, Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
     : base(command, requirement, redirect, modifier, forks)
 {
     Literal = literal;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Provide collection initialization, same as calling AddChild
 /// </summary>
 /// <param name="node">Command nodes to add</param>
 public void Add(CommandNode <TSource> node)
 {
     AddChild(node);
 }
Exemplo n.º 9
0
 private bool EqualsInternal(CommandNode <TSource> other)
 {
     return(Equals(Children, other.Children) && Equals(Command, other.Command));
 }
Exemplo n.º 10
0
 protected ArgumentCommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
     : base(command, requirement, redirect, modifier, forks)
 {
 }