/* * private Repeat(int minCount, int maxCount, int itemWeight, Pick item) * { super(item); weightedIndex = new * WeightedIndex(minCount).add(maxCount-minCount+1, itemWeight); } */ /* * private Repeat(int minCount, int maxCount, Object item) { this.item = * convert(item); weightedIndex = new * WeightedIndex(minCount).add(maxCount-minCount+1, 1); } */ protected internal override void AddTo(Pick.Target target) { // int count ; for (int i = weightedIndex.ToIndex(target.NextDouble()); i > 0; --i) { item.AddTo(target); } }
protected internal override void AddTo(Pick.Target target) { // get contents into separate buffer addBuffer.CopyState(target); addBuffer.Clear(); item.AddTo(addBuffer); String newValue = addBuffer.Get(); if (IBM.ICU.Charset.Pick.DEBUG) { System.Console.Out.WriteLine("Old: " + lastValue + ", New:" + newValue); } // if not first one, merge with old if (lastValue != null) { mergeBuffer.Length = 0; int lastIndex = 0; int newIndex = 0; // the new length is a random value between old and new. int newLenLimit = (int)IBM.ICU.Charset.Pick.PickMthd(target.random, lastValue.Length, newValue.Length); while (mergeBuffer.Length < newLenLimit && newIndex < newValue.Length && lastIndex < lastValue.Length) { int c = choice.ToIndex(target.NextDouble()); if (c == COPY_NEW || c == COPY_BOTH || c == SKIP) { newIndex = IBM.ICU.Charset.Pick.GetChar(newValue, newIndex, mergeBuffer, c < LEAST_SKIP); if (mergeBuffer.Length >= newLenLimit) { break; } } if (c == COPY_LAST || c == COPY_BOTH || c == SKIP) { lastIndex = IBM.ICU.Charset.Pick.GetChar(lastValue, lastIndex, mergeBuffer, c < LEAST_SKIP); } } newValue = mergeBuffer.ToString(); } lastValue = newValue; target.Append(newValue); if (IBM.ICU.Charset.Pick.DEBUG) { System.Console.Out.WriteLine("Result: " + newValue); } }
protected internal override void AddTo(Pick.Target target) { items[weightedIndex.ToIndex(target.NextDouble())].AddTo(target); }