Exemplo n.º 1
0
Arquivo: Box.cs Projeto: p0k0/t-tn
        public void Add(string pattern)
        {
            if (pattern == string.Empty)
            {
                return;
            }

            var chainFactory = new ChainFactory();
            var newChainHead = chainFactory.Create(pattern);

            if (_heads.Contains(newChainHead))
            {
                var head             = _heads.Single(x => x.Data == pattern.First());
                var traversePathHead = newChainHead.SubNodes.Single();
                var enumerator       = new EnumeratorTraversingSpecifiedPath(head, traversePathHead);

                while (enumerator.MoveNext())
                {
                }

                if (!enumerator.IsDestinationReached &&
                    !enumerator.LastTraversedNode.SubNodes.Contains(enumerator.TraverseRemainder))
                {
                    enumerator.LastTraversedNode.AppendSub(enumerator.TraverseRemainder);
                }
            }
            else
            {
                _heads.Add(newChainHead);
            }
        }
Exemplo n.º 2
0
Arquivo: Box.cs Projeto: p0k0/t-tn
        public IEnumerable <string> Find(string searchPattern)
        {
            var factory = new ChainFactory();

            var targetNode = factory.Create(searchPattern);

            if (!_heads.Contains(targetNode))
            {
                return(Enumerable.Empty <string>());
            }

            var searchHead = _heads.SingleOrDefault(x => x.Data.Equals(searchPattern.First()));

            var accumulator = new PathAccumulator();
            var enumerator  = new EnumeratorAccumulatingBranches(searchHead, accumulator);

            while (enumerator.MoveNext())
            {
            }

            var pathEnumerator = new EnumeratorTraversingSpecifiedPath(searchHead, targetNode.SubNodes.LastOrDefault());

            while (pathEnumerator.MoveNext())
            {
            }

            IEnumerable <string> result = accumulator.Paths;

            if (pathEnumerator.IsDestinationReached)
            {
                result = result.Concat(new string[] { searchPattern });
            }

            return(result);
        }