当前位置: 首页>>代码示例>>C#>>正文


C# CharArraySet.contains方法代码示例

本文整理汇总了C#中CharArraySet.contains方法的典型用法代码示例。如果您正苦于以下问题:C# CharArraySet.contains方法的具体用法?C# CharArraySet.contains怎么用?C# CharArraySet.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CharArraySet的用法示例。


在下文中一共展示了CharArraySet.contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testContainsWithNull

 /// <summary>
 /// Test for NPE
 /// </summary>
 public virtual void testContainsWithNull()
 {
     CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
     try
     {
       set.contains((char[]) null, 0, 10);
       fail("null value must raise NPE");
     }
     catch (System.NullReferenceException)
     {
     }
     try
     {
       set.contains((CharSequence) null);
       fail("null value must raise NPE");
     }
     catch (System.NullReferenceException)
     {
     }
     try
     {
       set.contains((object) null);
       fail("null value must raise NPE");
     }
     catch (System.NullReferenceException)
     {
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:31,代码来源:TestCharArraySet.cs

示例2: CheckSet

 private void CheckSet(CharArraySet wordset)
 {
     assertEquals(3, wordset.size());
     assertTrue(wordset.contains("ONE")); // case is not modified
     assertTrue(wordset.contains("two")); // surrounding whitespace is removed
     assertTrue(wordset.contains("three"));
     assertFalse(wordset.contains("four"));
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:8,代码来源:TestWordlistLoader.cs

示例3: testClear

 public virtual void testClear()
 {
     CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10,true);
     set.addAll(TEST_STOP_WORDS);
     assertEquals("Not all words added", TEST_STOP_WORDS.Length, set.size());
     set.clear();
     assertEquals("not empty", 0, set.size());
     for (int i = 0;i < TEST_STOP_WORDS.Length;i++)
     {
       assertFalse(set.contains(TEST_STOP_WORDS[i]));
     }
     set.addAll(TEST_STOP_WORDS);
     assertEquals("Not all words added", TEST_STOP_WORDS.Length, set.size());
     for (int i = 0;i < TEST_STOP_WORDS.Length;i++)
     {
       assertTrue(set.contains(TEST_STOP_WORDS[i]));
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:18,代码来源:TestCharArraySet.cs

示例4: TestStopList

        public virtual void TestStopList()
        {
            CharArraySet stopWordsSet = new CharArraySet(TEST_VERSION_CURRENT, new string[] { "good", "test", "analyzer" }, false);
            StopAnalyzer newStop = new StopAnalyzer(TEST_VERSION_CURRENT, stopWordsSet);
            TokenStream stream = newStop.TokenStream("test", "This is a good test of the english stop analyzer");
            try
            {
                assertNotNull(stream);
                ICharTermAttribute termAtt = stream.GetAttribute<ICharTermAttribute>();

                stream.Reset();
                while (stream.IncrementToken())
                {
                    string text = termAtt.ToString();
                    assertFalse(stopWordsSet.contains(text));
                }
                stream.End();
            }
            finally
            {
                IOUtils.CloseWhileHandlingException(stream);
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:23,代码来源:TestStopAnalyzer.cs

示例5: testCopyCharArraySet

        /// <summary>
        /// Test the static #copy() function with a CharArraySet as a source
        /// </summary>
        public virtual void testCopyCharArraySet()
        {
            CharArraySet setIngoreCase = new CharArraySet(TEST_VERSION_CURRENT, 10, true);
            CharArraySet setCaseSensitive = new CharArraySet(TEST_VERSION_CURRENT, 10, false);

            IList<string> stopwords = TEST_STOP_WORDS;
            IList<string> stopwordsUpper = new List<string>();
            foreach (string @string in stopwords)
            {
              stopwordsUpper.Add(@string.ToUpper(Locale.ROOT));
            }
            setIngoreCase.addAll(TEST_STOP_WORDS);
            setIngoreCase.add(Convert.ToInt32(1));
            setCaseSensitive.addAll(TEST_STOP_WORDS);
            setCaseSensitive.add(Convert.ToInt32(1));

            CharArraySet copy = CharArraySet.copy(TEST_VERSION_CURRENT, setIngoreCase);
            CharArraySet copyCaseSens = CharArraySet.copy(TEST_VERSION_CURRENT, setCaseSensitive);

            assertEquals(setIngoreCase.size(), copy.size());
            assertEquals(setCaseSensitive.size(), copy.size());

            assertTrue(copy.containsAll(stopwords));
            assertTrue(copy.containsAll(stopwordsUpper));
            assertTrue(copyCaseSens.containsAll(stopwords));
            foreach (string @string in stopwordsUpper)
            {
              assertFalse(copyCaseSens.contains(@string));
            }
            // test adding terms to the copy
            IList<string> newWords = new List<string>();
            foreach (string @string in stopwords)
            {
              newWords.Add(@string + "_1");
            }
            copy.addAll(newWords);

            assertTrue(copy.containsAll(stopwords));
            assertTrue(copy.containsAll(stopwordsUpper));
            assertTrue(copy.containsAll(newWords));
            // new added terms are not in the source set
            foreach (string @string in newWords)
            {
              assertFalse(setIngoreCase.contains(@string));
              assertFalse(setCaseSensitive.contains(@string));

            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:51,代码来源:TestCharArraySet.cs

示例6: testUnmodifiableSet

        public virtual void testUnmodifiableSet()
        {
            CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10,true);
            set.addAll(TEST_STOP_WORDS);
            set.add(Convert.ToInt32(1));
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int size = set.size();
            int size = set.size();
            set = CharArraySet.unmodifiableSet(set);
            assertEquals("Set size changed due to unmodifiableSet call", size, set.size());
            foreach (string stopword in TEST_STOP_WORDS)
            {
              assertTrue(set.contains(stopword));
            }
            assertTrue(set.contains(Convert.ToInt32(1)));
            assertTrue(set.contains("1"));
            assertTrue(set.contains(new char[]{'1'}));

            try
            {
              CharArraySet.unmodifiableSet(null);
              fail("can not make null unmodifiable");
            }
            catch (System.NullReferenceException)
            {
              // expected
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:28,代码来源:TestCharArraySet.cs

示例7: testSupplementaryCharsBWCompat

 public virtual void testSupplementaryCharsBWCompat()
 {
     string missing = "Term %s is missing in the set";
     string falsePos = "Term %s is in the set but shouldn't";
     // for reference see
     // http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[[%3ACase_Sensitive%3DTrue%3A]%26[^[\u0000-\uFFFF]]]&esc=on
     string[] upperArr = new string[] {"Abc\ud801\udc1c", "\ud801\udc1c\ud801\udc1cCDE", "A\ud801\udc1cB"};
     string[] lowerArr = new string[] {"abc\ud801\udc44", "\ud801\udc44\ud801\udc44cde", "a\ud801\udc44b"};
     CharArraySet set = new CharArraySet(Version.LUCENE_30, TEST_STOP_WORDS, true);
     foreach (string upper in upperArr)
     {
       set.add(upper);
     }
     for (int i = 0; i < upperArr.Length; i++)
     {
       assertTrue(string.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
       assertFalse(string.format(Locale.ROOT, falsePos, lowerArr[i]), set.contains(lowerArr[i]));
     }
     set = new CharArraySet(Version.LUCENE_30, TEST_STOP_WORDS, false);
     foreach (string upper in upperArr)
     {
       set.add(upper);
     }
     for (int i = 0; i < upperArr.Length; i++)
     {
       assertTrue(string.format(Locale.ROOT,missing, upperArr[i]), set.contains(upperArr[i]));
       assertFalse(string.format(Locale.ROOT, falsePos, lowerArr[i]), set.contains(lowerArr[i]));
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:29,代码来源:TestCharArraySet.cs

示例8: testSingleHighSurrogateBWComapt

        public virtual void testSingleHighSurrogateBWComapt()
        {
            string missing = "Term %s is missing in the set";
            string falsePos = "Term %s is in the set but shouldn't";
            string[] upperArr = new string[] {"ABC\uD800", "ABC\uD800EfG", "\uD800EfG", "\uD800\ud801\udc1cB"};

            string[] lowerArr = new string[] {"abc\uD800", "abc\uD800efg", "\uD800efg", "\uD800\ud801\udc44b"};
            CharArraySet set = new CharArraySet(Version.LUCENE_30, TEST_STOP_WORDS, true);
            foreach (string upper in upperArr)
            {
              set.add(upper);
            }
            for (int i = 0; i < upperArr.Length; i++)
            {
              assertTrue(string.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
              if (i == lowerArr.Length - 1)
              {
            assertFalse(string.format(Locale.ROOT, falsePos, lowerArr[i]), set.contains(lowerArr[i]));
              }
              else
              {
            assertTrue(string.format(Locale.ROOT, missing, lowerArr[i]), set.contains(lowerArr[i]));
              }
            }
            set = new CharArraySet(Version.LUCENE_30, TEST_STOP_WORDS, false);
            foreach (string upper in upperArr)
            {
              set.add(upper);
            }
            for (int i = 0; i < upperArr.Length; i++)
            {
              assertTrue(string.format(Locale.ROOT, missing, upperArr[i]), set.contains(upperArr[i]));
              assertFalse(string.format(Locale.ROOT, falsePos, lowerArr[i]), set.contains(lowerArr[i]));
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:35,代码来源:TestCharArraySet.cs

示例9: testRehash

 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testRehash() throws Exception
 public virtual void testRehash()
 {
     CharArraySet cas = new CharArraySet(TEST_VERSION_CURRENT, 0, true);
     for (int i = 0;i < TEST_STOP_WORDS.Length;i++)
     {
       cas.add(TEST_STOP_WORDS[i]);
     }
     assertEquals(TEST_STOP_WORDS.Length, cas.size());
     for (int i = 0;i < TEST_STOP_WORDS.Length;i++)
     {
       assertTrue(cas.contains(TEST_STOP_WORDS[i]));
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:15,代码来源:TestCharArraySet.cs

示例10: testObjectContains

 public virtual void testObjectContains()
 {
     CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10, true);
     int? val = Convert.ToInt32(1);
     set.add(val);
     assertTrue(set.contains(val));
     assertTrue(set.contains(new int?(1))); // another integer
     assertTrue(set.contains("1"));
     assertTrue(set.contains(new char[]{'1'}));
     // test unmodifiable
     set = CharArraySet.unmodifiableSet(set);
     assertTrue(set.contains(val));
     assertTrue(set.contains(new int?(1))); // another integer
     assertTrue(set.contains("1"));
     assertTrue(set.contains(new char[]{'1'}));
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:16,代码来源:TestCharArraySet.cs

示例11: testNonZeroOffset

        public virtual void testNonZeroOffset()
        {
            string[] words = new string[] {"Hello","World","this","is","a","test"};
            char[] findme = "xthisy".ToCharArray();
            CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10, true);
            set.addAll(words);
            assertTrue(set.contains(findme, 1, 4));
            assertTrue(set.contains(new string(findme,1,4)));

            // test unmodifiable
            set = CharArraySet.unmodifiableSet(set);
            assertTrue(set.contains(findme, 1, 4));
            assertTrue(set.contains(new string(findme,1,4)));
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:TestCharArraySet.cs

示例12: testModifyOnUnmodifiable

        public virtual void testModifyOnUnmodifiable()
        {
            CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10, true);
            set.addAll(TEST_STOP_WORDS);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int size = set.size();
            int size = set.size();
            set = CharArraySet.unmodifiableSet(set);
            assertEquals("Set size changed due to unmodifiableSet call", size, set.size());
            string NOT_IN_SET = "SirGallahad";
            assertFalse("Test String already exists in set", set.contains(NOT_IN_SET));

            try
            {
              set.add(NOT_IN_SET.ToCharArray());
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
              set.add(NOT_IN_SET);
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
              set.add(new StringBuilder(NOT_IN_SET));
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
              set.clear();
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Changed unmodifiable set", set.contains(NOT_IN_SET));
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }
            try
            {
              set.add((object) NOT_IN_SET);
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            // This test was changed in 3.1, as a contains() call on the given Collection using the "correct" iterator's
            // current key (now a char[]) on a Set<String> would not hit any element of the CAS and therefor never call
            // remove() on the iterator
            try
            {
              set.removeAll(new CharArraySet(TEST_VERSION_CURRENT, TEST_STOP_WORDS, true));
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
              set.retainAll(new CharArraySet(TEST_VERSION_CURRENT, NOT_IN_SET, true));
              fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
              // expected
              assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
              set.addAll(NOT_IN_SET);
              fail("Modified unmodifiable set");
//.........这里部分代码省略.........
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:101,代码来源:TestCharArraySet.cs

示例13: TestStopListPositions

        public virtual void TestStopListPositions()
        {
            CharArraySet stopWordsSet = new CharArraySet(TEST_VERSION_CURRENT, new string[] { "good", "test", "analyzer" }, false);
            StopAnalyzer newStop = new StopAnalyzer(TEST_VERSION_CURRENT, stopWordsSet);
            string s = "This is a good test of the english stop analyzer with positions";
            int[] expectedIncr = new int[] { 1, 1, 1, 3, 1, 1, 1, 2, 1 };
            TokenStream stream = newStop.TokenStream("test", s);
            try
            {
                assertNotNull(stream);
                int i = 0;
                ICharTermAttribute termAtt = stream.GetAttribute<ICharTermAttribute>();
                IPositionIncrementAttribute posIncrAtt = stream.AddAttribute<IPositionIncrementAttribute>();

                stream.Reset();
                while (stream.IncrementToken())
                {
                    string text = termAtt.ToString();
                    assertFalse(stopWordsSet.contains(text));
                    assertEquals(expectedIncr[i++], posIncrAtt.PositionIncrement);
                }
                stream.End();
            }
            finally
            {
                IOUtils.CloseWhileHandlingException(stream);
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:28,代码来源:TestStopAnalyzer.cs

示例14: TestSingleHighSurrogate

        public virtual void TestSingleHighSurrogate()
        {
            string missing = "Term {0} is missing in the set";
            string falsePos = "Term {0} is in the set but shouldn't";
            string[] upperArr = { "ABC\uD800", "ABC\uD800EfG", "\uD800EfG", "\uD800\ud801\udc1cB" };

            string[] lowerArr = { "abc\uD800", "abc\uD800efg", "\uD800efg", "\uD800\ud801\udc44b" };
            CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, TEST_STOP_WORDS, true);
            foreach (string upper in upperArr)
            {
                set.add(upper);
            }
            for (int i = 0; i < upperArr.Length; i++)
            {
                assertTrue(string.Format(missing, upperArr[i]), set.contains(upperArr[i]));
                assertTrue(string.Format(missing, lowerArr[i]), set.contains(lowerArr[i]));
            }
            set = new CharArraySet(TEST_VERSION_CURRENT, TEST_STOP_WORDS, false);
            foreach (string upper in upperArr)
            {
                set.add(upper);
            }
            for (int i = 0; i < upperArr.Length; i++)
            {
                assertTrue(string.Format(missing, upperArr[i]), set.contains(upperArr[i]));
                assertFalse(string.Format(falsePos, upperArr[i]), set.contains(lowerArr[i]));
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:28,代码来源:TestCharArraySet.cs

示例15: TestModifyOnUnmodifiable

        public virtual void TestModifyOnUnmodifiable()
        {
            CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 10, true);
            set.AddAll(TEST_STOP_WORDS);
            int size = set.size();
            set = CharArraySet.UnmodifiableSet(set);
            assertEquals("Set size changed due to unmodifiableSet call", size, set.size());
            string NOT_IN_SET = "SirGallahad";
            assertFalse("Test String already exists in set", set.Contains(NOT_IN_SET));

            try
            {
                set.Add(NOT_IN_SET.ToCharArray());
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
                set.add(NOT_IN_SET);
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
                set.Add(new StringBuilder(NOT_IN_SET));
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            try
            {
                set.clear();
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Changed unmodifiable set", set.contains(NOT_IN_SET));
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }
            try
            {
                set.add(NOT_IN_SET);
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertFalse("Test String has been added to unmodifiable set", set.contains(NOT_IN_SET));
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }

            // NOTE: This results in a StackOverflow exception. Since this is not a public member of CharArraySet,
            // but an extension method for the test fixture (which apparently has a bug), this test is non-critical
            //// This test was changed in 3.1, as a contains() call on the given Collection using the "correct" iterator's
            //// current key (now a char[]) on a Set<String> would not hit any element of the CAS and therefor never call
            //// remove() on the iterator
            //try
            //{
            //    set.removeAll(new CharArraySet(TEST_VERSION_CURRENT, TEST_STOP_WORDS, true));
            //    fail("Modified unmodifiable set");
            //}
            //catch (System.NotSupportedException)
            //{
            //    // expected
            //    assertEquals("Size of unmodifiable set has changed", size, set.size());
            //}

            #region Added for better .NET support
            // This test was added for .NET to check the Remove method, since the extension method
            // above fails to execute.
            try
            {
#pragma warning disable 612, 618
                set.Remove(TEST_STOP_WORDS[0]);
#pragma warning restore 612, 618
                fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException)
            {
                // expected
                assertEquals("Size of unmodifiable set has changed", size, set.size());
            }
//.........这里部分代码省略.........
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:101,代码来源:TestCharArraySet.cs


注:本文中的CharArraySet.contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。