示例#1
0
        /**
         * <summary>The addWithFlag method takes a String name and a flag as inputs. First it creates a {@link TxtWord} word, then if
         * given name is not in words {@link java.util.ArrayList} it creates new {@link TxtWord} with given name and assigns it to
         * the word and adds given flag to the word, it also add newly created word to the words {@link java.util.ArrayList}'s index
         * found by performing a binary search and return true at the end. If given name is in words {@link java.util.ArrayList},
         * it adds it the given flag to the word.</summary>
         *
         * <param name="name">String input.</param>
         * <param name="flag">String flag.</param>
         * <returns>true if given name is in words {@link java.util.ArrayList}, false otherwise.</returns>
         */
        public bool AddWithFlag(string name, string flag)
        {
            TxtWord word;

            if (GetWord(name.ToLower(new CultureInfo("tr"))) == null)
            {
                word = new TxtWord(name.ToLower(new CultureInfo("tr")));
                word.AddFlag(flag);
                var insertIndex = words.BinarySearch(word, comparator);
                if (insertIndex >= 0)
                {
                    words.Insert(insertIndex, word);
                }

                return(true);
            }

            word = (TxtWord)GetWord(name.ToLower(new CultureInfo("tr")));
            if (!word.ContainsFlag(flag))
            {
                word.AddFlag(flag);
            }

            return(false);
        }
示例#2
0
        /**
         * <summary>The loadFromText method takes a String filename as an input. It reads given file line by line and splits according to space
         * and assigns each word to the String array. Then, adds these word with their flags to the words {@link java.util.ArrayList}.
         * At the end it sorts the words {@link java.util.ArrayList}.</summary>
         *
         * <param name="stream">File stream input.</param>
         */
        private void LoadFromText(Stream stream)
        {
            var streamReader = new StreamReader(stream);
            var line         = streamReader.ReadLine();

            while (line != null)
            {
                var list = line.Split(" ");
                if (list.Length > 0)
                {
                    var currentWord = new TxtWord(list[0]);
                    int i;
                    for (i = 1; i < list.Length; i++)
                    {
                        currentWord.AddFlag(list[i]);
                    }

                    words.Add(currentWord);
                }

                line = streamReader.ReadLine();
            }

            words.Sort(comparator);
        }
示例#3
0
        /**
         * <summary>The clone method creates {@link TxtWord} type copy with name and add items of flags {@link ArrayList}  to the copy.</summary>
         *
         * <returns>TxtWord type copy.</returns>
         */
        public new TxtWord Clone()
        {
            var copy = new TxtWord(name);

            foreach (var t in flags)
            {
                copy.AddFlag(t);
            }

            return(copy);
        }