Ejemplo n.º 1
0
        public CatalogCode NewChild(CatalogCode code)
        {
            CatalogEntry ce = Get(code);

            if (ce == null || ce.children.Count == 0)
            {
                return(new CatalogCode(code + (code.Equals(CatalogCode.current) ? "" : ".") + "0"));
            }

            int max      = ce.children.Max(c => c.codePrefix.Youngest());
            int addition = 0;

            if (max + 1 == ce.children.Count)
            {
                addition = max + 1;
            }
            else
            {
                List <CatalogEntry> children = ce.children;
                if (children[0].codePrefix.Youngest() != 0)
                {
                    addition = 0;
                }
                else
                {
                    CatalogCode prev = children[0].codePrefix;
                    int         pos  = 1;
                    while (pos < children.Count)
                    {
                        CatalogCode comp = children[pos].codePrefix;
                        if (comp.Youngest() - prev.Youngest() != 1)
                        {
                            addition = prev.Youngest() + 1;
                            break;
                        }

                        prev = comp;
                        pos++;
                    }
                }
            }

            if (code.Equals(CatalogCode.current))
            {
                return(new CatalogCode(addition.ToString()));
            }
            return(new CatalogCode(code + $".{addition}"));
        }
Ejemplo n.º 2
0
        public bool Contains(CodeRange range)
        {
            if (range == null)
            {
                return(false);
            }

            CatalogCode counter = range.fromCode;

            while (counter.Youngest() <= range.toCode.Youngest())
            {
                if (Get(counter) != null)
                {
                    return(true);
                }
                counter = counter.Increment();
            }

            return(false);
        }
Ejemplo n.º 3
0
        public bool Contains(CodeRange range, CodeRange usingCodeRange, int offset)
        {
            if (range == null)
            {
                return(false);
            }

            CatalogCode counter1 = range.fromCode;
            CatalogCode counter2 = usingCodeRange.fromCode + offset;

            while (counter1.Youngest() <= range.toCode.Youngest())
            {
                if (Contains(counter2) && Contains(counter1))
                {
                    return(true);
                }
                counter1 = counter1.Increment();
                counter2 = counter2.Increment();
            }

            return(false);
        }