コード例 #1
0
        private HashSet <String> Relax(T unit, ref HashSet <String> strictNames)
        {
            var result = this.BuildNames(unit);

            var doCancel = false;

            this.OnRelaxing(unit, ref doCancel);
            if (doCancel)
            {
                return(result);
            }

            result = NameDatabase <T, TKey> .Relax(result);

            this.OnRelaxed(unit, result, ref strictNames);
            foreach (var name in strictNames)
            {
                result.Add(name);
            }

            return(result);
        } // relax(...)
コード例 #2
0
        } // try_find(...)

        public Boolean Add(T unit)
        {
            var doCancel = false;

            this.OnLoading(unit, ref doCancel);
            if (doCancel)
            {
                return(false);
            }

            var key          = this.BuildKey(unit);
            var names        = this.BuildNames(unit); // Names for logging purposes.
            var strictNames  = new HashSet <String>();
            var treeNames    = this.Relax(unit, ref strictNames);
            var treeSynonyms = NameDatabase <T, TKey> .Relax(strictNames);

            if (this.database.ContainsKey(key))
            {
                App.Warnings.Push($"Unit with id ({key}) already exists.");
                return(false);
            } // if (...)
            else if (this.nameTree.ContainsAny(treeNames))
            {
                App.Warnings.Push($"Unit with a similar name ({String.Join(", ", names)}) already exists.");
                return(false);
            } // if (...)
            else
            {
                this.database.Add(key, unit);
                this.nameTree.TryAddMany(key, treeNames);
                foreach (var explicitSynonym in treeSynonyms)
                {
                    this.nameTree.AddSynonym(key, explicitSynonym);
                }
                this.OnLoaded(unit);
                return(true);
            } // if (...)
        }     // add(...)