示例#1
0
        /// <summary>
        /// Finds memes by tags
        /// </summary>
        /// <param name="tagsString">Tags separated by a space</param>
        /// <returns>If an empty string is passed, it will return all memes.
        ///          Otherwise, it will return memes that have at least one required tag</returns>
        public List <Meme> FindByTags(string tagsString)
        {
            string[] requiredTags = tagsString.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            var      result       = new List <Meme>();

            if (requiredTags.Length == 0)
            {
                return(Memes);
            }

            foreach (string tag in requiredTags)
            {
                if (MemesWithTags.ContainsKey(tag))
                {
                    foreach (Meme meme in MemesWithTags[tag])
                    {
                        if (!(result.Contains(meme)))
                        {
                            result.Add(meme);
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
 public void UpdateDictionary(Meme meme)
 {
     string[] tags = meme.Tags.Split();
     foreach (string tag in tags)
     {
         if (!(MemesWithTags.ContainsKey(tag)))
         {
             MemesWithTags.Add(tag, new List <Meme>());
         }
         MemesWithTags[tag].Add(meme);
     }
 }