예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetDistinctStringValues() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldGetDistinctStringValues()
        {
            // given
            LuceneIndexWriter writer = _index.IndexWriter;
            IDictionary <Value, MutableInt> expectedCounts = new Dictionary <Value, MutableInt>();

            for (int i = 0; i < 10_000; i++)
            {
                Value value = stringValue(Random.Next(1_000).ToString());
                writer.AddDocument(documentRepresentingProperties(i, value));
                expectedCounts.computeIfAbsent(value, v => new MutableInt(0)).increment();
            }
            _index.maybeRefreshBlocking();

            // when/then
            GatheringNodeValueClient client           = new GatheringNodeValueClient();
            NodePropertyAccessor     propertyAccessor = mock(typeof(NodePropertyAccessor));

            using (IndexReader reader = _index.IndexReader)
            {
                reader.DistinctValues(client, propertyAccessor, true);
                while (client.Progressor.next())
                {
                    Value      value         = client.Values[0];
                    MutableInt expectedCount = expectedCounts.Remove(value);
                    assertNotNull(expectedCount);
                    assertEquals(expectedCount.intValue(), client.Reference);
                }
                assertTrue(expectedCounts.Count == 0);
            }
            verifyNoMoreInteractions(propertyAccessor);
        }
예제 #2
0
        private void AddLock(ResourceType resourceType, long resourceId, bool exclusive)
        {
            LockUnit   lockUnit  = new LockUnit(resourceType, resourceId, exclusive);
            MutableInt lockCount = _locks.computeIfAbsent(lockUnit, k => new MutableInt());

            lockCount.increment();
        }
예제 #3
0
        private void StartComplexTestClick(object sender, EventArgs e)
        {
            complexTest      = true;
            testColorCounter = new MutableInt(new int[] { 0, 1, 2, 3, 4 });
            testColorCounter.OnValueChanged     += OnColorTestIterationChanged;
            testColorCounter.OnMutationComplete += OnColorTestCompleted;

            StartTest(new KhikDecisionTest(new int[] { 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
        public override int GetHashCode()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableInt h = new org.apache.commons.lang3.mutable.MutableInt();
            MutableInt h = new MutableInt();

            Each(element => h.add(( int )(element ^ ( int )(( uint )element >> 32))));
            return(h.intValue());
        }
예제 #5
0
        /// <summary>
        /// Add a key to the set with the given number of references.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="numReferences">The num references.</param>
        public void Add(K key, int numReferences)
        {
            MutableInt value;

            if (!_refSet.TryGetValue(key, out value))
            {
                _refSet[key] = new MutableInt(numReferences);
                return;
            }
            throw new ArgumentException("Value '" + key + "' already in collection");
        }
        public override long[] ToArray()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.apache.commons.lang3.mutable.MutableInt idx = new org.apache.commons.lang3.mutable.MutableInt();
            MutableInt idx = new MutableInt();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long[] array = new long[size()];
            long[] array = new long[Size()];
            Each(element => array[idx.AndIncrement] = element);
            return(array);
        }
예제 #7
0
        /* Random page */
        private Page RandomPage(int corruptionPercent, MutableInt totalNumberOfCorruptions)
        {
            int  numberOfCorruptions = 0;
            bool @internal           = _randomRule.nextBoolean();

            if (_randomRule.Next(100) < corruptionPercent)
            {
                int maxCorruptions = @internal ? _possibleCorruptionsInInternal.Count : _possibleCorruptionsInLeaf.Count;
                numberOfCorruptions = _randomRule.intBetween(1, maxCorruptions);
                totalNumberOfCorruptions.add(numberOfCorruptions);
            }
            return(@internal ? RandomInternal(numberOfCorruptions) : RandomLeaf(numberOfCorruptions));
        }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseAll()
        public virtual void ShouldCloseAll()
        {
            // given
            InstanceSelector <string> selector = SelectorFilledWithOrdinal();

            // when
            MutableInt count = new MutableInt();

            selector.Close(s => count.increment());

            // then
            assertEquals(Enum.GetValues(typeof(IndexSlot)).length, count.intValue());
        }
예제 #9
0
        private void RemoveLock(ResourceType resourceType, long resourceId, bool exclusive)
        {
            LockUnit   lockUnit  = new LockUnit(resourceType, resourceId, exclusive);
            MutableInt lockCount = _locks[lockUnit];

            if (lockCount == null)
            {
                throw new System.InvalidOperationException("Cannot release " + (exclusive ? "exclusive" : "shared") + " lock that it " + "does not hold: " + resourceType + "[" + resourceId + "].");
            }

            lockCount.decrement();

            if (lockCount.intValue() == 0)
            {
                _locks.Remove(lockUnit);
            }
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void stressInstantiationWithClose() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StressInstantiationWithClose()
        {
            // given
            StringFactory factory             = new StringFactory();
            TemporalIndexCache <string> cache = new TemporalIndexCache <string>(factory);
            Race       race = (new Race()).withRandomStartDelays();
            MutableInt instantiatedAtClose = new MutableInt();

            race.AddContestant(() =>
            {
                try
                {
                    cache.UncheckedSelect(_valueGroups[0]);
                    cache.UncheckedSelect(_valueGroups[1]);
                }
                catch (System.InvalidOperationException)
                {
                    // This exception is OK since it may have been closed
                }
            }, 1);
            race.AddContestant(() =>
            {
                cache.CloseInstantiateCloseLock();
                instantiatedAtClose.Value = count(cache);
            }, 1);

            // when
            race.Go();

            // then
            try
            {
                cache.UncheckedSelect(_valueGroups[2]);
                fail("No instantiation after closed");
            }
            catch (System.InvalidOperationException)
            {
                // good
            }
            assertEquals(instantiatedAtClose.intValue(), count(cache));
        }
예제 #11
0
 internal DirectionData(ShortestPath outerInstance, Node startNode, ICollection <long> sharedVisitedRels, MutableInt sharedFrozenDepth, MutableBoolean sharedStop, MutableInt sharedCurrentDepth, PathExpander expander)
 {
     this._outerInstance          = outerInstance;
     this.StartNode               = startNode;
     this.VisitedNodes[startNode] = new LevelData(null, 0);
     this.NextNodes.Add(startNode);
     this.SharedFrozenDepth  = sharedFrozenDepth;
     this.SharedStop         = sharedStop;
     this.SharedCurrentDepth = sharedCurrentDepth;
     this.Expander           = expander;
     this.SharedVisitedRels  = sharedVisitedRels;
     this.LastPath           = new DirectionDataPath(startNode);
     if (sharedCurrentDepth.intValue() < outerInstance.maxDepth)
     {
         PrepareNextLevel();
     }
     else
     {
         this.NextRelationships = Iterators.emptyResourceIterator();
     }
 }
예제 #12
0
        public void PassArgumentIntoThread()
        {
            // Parameters
            int nbThread    = 10;
            int expectedSum = (nbThread * (nbThread + 1)) / 2;
            // still concurent sum of integer from 1 to n but using object as parameter
            MutableInt sum    = FILL_ME_IN;
            var        summer = AboutTaskHelper.GetSumAction(sum);

            // Something weird here ?
            for (int i = 1; i <= nbThread; i++)
            {
                // the behaviour is not deterministic without a few change ...
                // hint: have a close look at the closure
                new Task(() => summer(i)).Start();
            }
            // the worst way to synchronize task ;)
            Task.Delay(5000);
            // Assert
            Assert.Equal(expectedSum, sum.Value);
        }
        public ClientViewMetadata BuildClientViewMetadata()
        {
            List <string>     allHints           = new List <string>();
            MutableInt        saveType           = new MutableInt(0);
            List <AutofillId> autofillIds        = new List <AutofillId>();
            StringBuilder     webDomainBuilder   = new StringBuilder();
            List <AutofillId> focusedAutofillIds = new List <AutofillId>();

            mClientParser.Parse(new ParseNodeProcessor()
            {
                that = this
            });
            mClientParser.Parse(new ParseWebDomainNodeProcessor()
            {
                that = this
            });
            String webDomain = webDomainBuilder.ToString();

            AutofillId[] autofillIdsArray = autofillIds.ToArray();
            AutofillId[] focusedIds       = focusedAutofillIds.ToArray();
            return(new ClientViewMetadata(allHints, saveType.Value, autofillIdsArray, focusedIds, webDomain));
        }
 private void ParseNode(AssistStructure.ViewNode root, List <String> allHints,
                        MutableInt autofillSaveType, List <AutofillId> autofillIds,
                        List <AutofillId> focusedAutofillIds)
 {
     String[] hints = root.GetAutofillHints();
     if (hints != null)
     {
         foreach (string hint in hints)
         {
             FieldTypeWithHeuristics fieldTypeWithHints = mFieldTypesByAutofillHint[hint];
             if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null)
             {
                 allHints.Add(hint);
                 autofillSaveType.Value |= fieldTypeWithHints.fieldType.GetSaveInfo();
             }
         }
     }
     if (root.IsFocused)
     {
         focusedAutofillIds.Add(root.AutofillId);
     }
     autofillIds.Add(root.AutofillId);
 }
예제 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeEntriesWhenOnlyLowestIsPresent()
        public virtual void ShouldSeeEntriesWhenOnlyLowestIsPresent()
        {
            // given
            long labelId = 0;
            IList <NodeLabelUpdate> labelUpdates = new List <NodeLabelUpdate>();

            labelUpdates.Add(NodeLabelUpdate.labelChanges(0L, new long[] {}, new long[] { labelId }));

            Start(labelUpdates);

            // when
            MutableInt count = new MutableInt();
            AllEntriesLabelScanReader nodeLabelRanges = _store.allNodeLabelRanges();

            nodeLabelRanges.forEach(nlr =>
            {
                foreach (long nodeId in nlr.nodes())
                {
                    count.add(nlr.labels(nodeId).length);
                }
            });
            assertThat(count.intValue(), @is(1));
        }
예제 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCountDistinctValues()
        public virtual void ShouldCountDistinctValues()
        {
            // given
            Value[]    strings = GenerateRandomStrings();
            DataCursor source  = new DataCursor(AsHitData(strings));
            GatheringNodeValueClient client = new GatheringNodeValueClient();

            // when
            NativeDistinctValuesProgressor <StringIndexKey, NativeIndexValue> progressor = new NativeDistinctValuesProgressor <StringIndexKey, NativeIndexValue>(source, client, new List <RawCursor <Hit <KEY, VALUE>, IOException> >(), _layout, _layout.compareValue);

            client.Initialize(null, progressor, new IndexQuery[0], IndexOrder.NONE, true);
            IDictionary <Value, MutableInt> expectedCounts = AsDistinctCounts(strings);

            // then
            int uniqueValues    = 0;
            int nonUniqueValues = 0;

            while (progressor.Next())
            {
                Value      @string       = client.Values[0];
                MutableInt expectedCount = expectedCounts.Remove(@string);
                assertNotNull(expectedCount);
                assertEquals(expectedCount.intValue(), client.Reference);

                if (expectedCount.intValue() > 1)
                {
                    nonUniqueValues++;
                }
                else
                {
                    uniqueValues++;
                }
            }
            assertTrue(expectedCounts.Count == 0);
            assertTrue(uniqueValues > 0);
            assertTrue(nonUniqueValues > 0);
        }
예제 #17
0
        private IEnumerable <Path> InternalPaths(Node start, Node end, bool stopAsap)
        {
            _lastMetadata = new Metadata();
            if (start.Equals(end))
            {
                return(FilterPaths(Collections.singletonList(PathImpl.singular(start))));
            }
            Hits hits = new Hits();
            ICollection <long> sharedVisitedRels  = new HashSet <long>();
            MutableInt         sharedFrozenDepth  = new MutableInt(Null);        // ShortestPathLengthSoFar
            MutableBoolean     sharedStop         = new MutableBoolean();
            MutableInt         sharedCurrentDepth = new MutableInt(0);

            using (DirectionData startData = new DirectionData(this, start, sharedVisitedRels, sharedFrozenDepth, sharedStop, sharedCurrentDepth, _expander), DirectionData endData = new DirectionData(this, end, sharedVisitedRels, sharedFrozenDepth, sharedStop, sharedCurrentDepth, _expander.reverse()))
            {
                while (startData.MoveNext() || endData.MoveNext())
                {
                    GoOneStep(startData, endData, hits, startData, stopAsap);
                    GoOneStep(endData, startData, hits, startData, stopAsap);
                }
                ICollection <Hit> least = hits.Least();
                return(least != null?FilterPaths(HitsToPaths( least, start, end, stopAsap, _maxResultCount )) : Collections.emptyList());
            }
        }
예제 #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCleanLargeFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCleanLargeFile()
        {
            // GIVEN
            int        numberOfPages            = _randomRule.intBetween(1_000, 10_000);
            int        corruptionPercent        = _randomRule.Next(90);
            MutableInt totalNumberOfCorruptions = new MutableInt(0);

            Page[] pages = new Page[numberOfPages];
            for (int i = 0; i < numberOfPages; i++)
            {
                Page page = RandomPage(corruptionPercent, totalNumberOfCorruptions);
                pages[i] = page;
            }
            InitializeFile(_pagedFile, pages);

            // WHEN
            SimpleCleanupMonitor monitor = new SimpleCleanupMonitor();

            CrashGenerationCleaner(_pagedFile, 0, numberOfPages, monitor).clean(_executor);

            // THEN
            AssertPagesVisited(monitor, numberOfPages);
            AssertCleanedCrashPointers(monitor, totalNumberOfCorruptions.Value);
        }
예제 #19
0
 public Long(MutableInt radixShift)
 {
     this.RadixShift = radixShift;
 }
예제 #20
0
 public Long()
 {
     this.RadixShift         = new MutableInt();
     this.CalculatorConflict = new RadixCalculator.Long(RadixShift);
 }
예제 #21
0
 internal CountingPathExpander(TestShortestPath outerInstance, PathExpander @delegate)
 {
     this._outerInstance = outerInstance;
     NodesVisited        = new MutableInt(0);
     this.Delegate       = @delegate;
 }
        private void StartComplexTestClick(object sender, EventArgs e)
        {
            complexTest = true;
            testColorCounter = new MutableInt(new int[] { 0, 1, 2, 3, 4 });
            testColorCounter.OnValueChanged += OnColorTestIterationChanged;
            testColorCounter.OnMutationComplete += OnColorTestCompleted;

            StartTest(new KhikDecisionTest(new int[] { 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
예제 #23
0
 internal CountingPathExpander(TestShortestPath outerInstance, PathExpander @delegate, MutableInt nodesVisited) : this(outerInstance, @delegate)
 {
     this._outerInstance = outerInstance;
     this.NodesVisited   = nodesVisited;
 }