public IReadOnlyList <string> GetValuesCache(string userField, string lang) { if (_abort) { return(ReadOnlyList.Empty <string>()); } var spellcheckerField = _adapter.GetSpellcheckerFieldIn(userField, lang); IReadOnlyList <string> values; lock (_valuesCache) if (_valuesCache.TryGetValue(spellcheckerField, out values)) { return(values); } values = _adapter.IsStoredInSpellchecker(userField, lang) ? _spellchecker?.ReadAllValuesFrom(discriminant: spellcheckerField) : _reader?.Invoke1(readAllValuesFrom, spellcheckerField); if (values == null) { return(ReadOnlyList.Empty <string>()); } lock (_valuesCache) _valuesCache[spellcheckerField] = values; return(values); }
public void CountOptimizationsThroughAdapter() { var ri = new int[5].AsReadOnlyList(); ri.Skip(10).AssertReferenceEquals(ReadOnlyList.Empty <int>()); ri.Take(10).AssertReferenceEquals(ri); }
protected override IReadOnlyList <string> GetValuesCache(string userField, string lang) { if (_abort) { return(ReadOnlyList.Empty <string>()); } return(base.GetValuesCache(userField, lang)); }
public void CountCheckDoesNotOptimizeAwayWhenSizeIsVariable() { var r = 5.Range().ToList(); r.TakeLastRequire(5).AssertReferenceDoesNotEqual(r); r.SkipLastRequire(5).AssertReferenceDoesNotEqual(ReadOnlyList.Empty <int>()); r.TakeRequire(5).AssertReferenceDoesNotEqual(r); r.SkipRequire(5).AssertReferenceDoesNotEqual(ReadOnlyList.Empty <int>()); }
public void CountCheckOptimizesAwayWhenZero() { var r = 5.Range().ToList(); r.TakeLastRequire(0).AssertReferenceEquals(ReadOnlyList.Empty <int>()); r.SkipLastRequire(0).AssertReferenceEquals(r); r.TakeRequire(0).AssertReferenceEquals(ReadOnlyList.Empty <int>()); r.SkipRequire(0).AssertReferenceEquals(r); }
public void CountCheckOptimizesAwayWhenSizeIsKnown() { var r = 5.Range(); r.TakeLastRequire(5).AssertReferenceEquals(r); r.TakeRequire(5).AssertReferenceEquals(r); r.SkipLastRequire(5).AssertReferenceEquals(ReadOnlyList.Empty <int>()); r.SkipRequire(5).AssertReferenceEquals(ReadOnlyList.Empty <int>()); TestUtil.AssertThrows(() => r.TakeRequire(6)); TestUtil.AssertThrows(() => r.TakeLastRequire(6)); TestUtil.AssertThrows(() => r.SkipRequire(6)); TestUtil.AssertThrows(() => r.SkipLastRequire(6)); }
public void LinearInsertionAndDeletionTest() { var list = ReadOnlyList <int> .Empty(); for (int i = 0; i < 10; i++) { Assert.Equal(i, list.Count); list = list.Add(i); } Assert.Equal(10, list.Count); for (int i = 9; i >= 0; i--) { list = list.Remove(0); Assert.Equal(i, list.Count); } Assert.Equal(0, list.Count); }
public IReadOnlyList <string> SuggestValues(string userField, string language, string value) { if (string.IsNullOrEmpty(value)) { var cache = GetValuesCache(userField, language); return(new ListSegment <string>(cache, 0, _maxCount())); } if (_adapter.IsNumericField(userField)) { var cache = GetValuesCache(userField, language); return(getNumericallySimilarValues(cache, value).Take(_maxCount()).ToReadOnlyList()); } if (!IsLoaded) { return(ReadOnlyList.Empty <string>()); } var spellcheckerField = _adapter.GetSpellcheckerFieldIn(userField, language); return(_spellchecker.SuggestSimilar(spellcheckerField, value, _maxCount())); }
public void SkipOptimizes() { var x = new[] { ReadOnlyList.Empty <int>(), 5.Range(), new int[6], new List <int> { 1, 2 } }; // skipping none is ignored foreach (var e in x) { e.Skip(0).AssertReferenceEquals(e); e.SkipLast(0).AssertReferenceEquals(e); } // skipping all is emptied foreach (var e in x) { foreach (var i in new[] { e.Count, e.Count + 1, 100 }) { var b = !(e is List <int>); ReferenceEquals(e.Skip(i), ReadOnlyList.Empty <int>()).AssertEquals(b); ReferenceEquals(e.SkipLast(i), ReadOnlyList.Empty <int>()).AssertEquals(b); } } }
public void TakeOptimizes() { var x = new[] { ReadOnlyList.Empty <int>(), 5.Range(), new int[6], new List <int> { 1, 2 } }; // taking none is empty foreach (var e in x) { e.Take(0).AssertReferenceEquals(ReadOnlyList.Empty <int>()); e.TakeLast(0).AssertReferenceEquals(ReadOnlyList.Empty <int>()); } // taking all is ignored foreach (var e in x) { foreach (var i in new[] { e.Count, e.Count + 1, 100 }) { var b = !(e is List <int>); ReferenceEquals(e.Take(i), e).AssertEquals(b); ReferenceEquals(e.TakeLast(i), e).AssertEquals(b); } } }
public AggregateEntity() : this(Point.Origin, ReadOnlyList <Entity> .Empty()) { }
public void List_Empty() { var list = ReadOnlyList.Empty <int> (); Assert.AreEqual(0, list.Count); }
public bool ReadDrawing(string fileName, Stream fileStream, out Drawing drawing, out ViewPort viewPort) { var file = DxfFile.Load(fileStream); var layers = new ReadOnlyTree <string, Layer>(); foreach (var layer in file.Layers) { layers = layers.Insert(layer.Name, new Layer(layer.Name, color: layer.Color.ToColor(), isVisible: layer.IsLayerOn)); } foreach (var item in file.Entities) { var layer = GetOrCreateLayer(ref layers, item.Layer); // create the entity var entity = item.ToEntity(); // add the entity to the appropriate layer if (entity != null) { layer = layer.Add(entity); layers = layers.Insert(layer.Name, layer); } } foreach (var block in file.Blocks) { var layer = GetOrCreateLayer(ref layers, block.Layer); // create the aggregate entity var children = ReadOnlyList <Entity> .Empty(); foreach (var item in block.Entities) { var tempEnt = item.ToEntity(); if (tempEnt != null) { children = children.Add(tempEnt); } } // add the entity to the appropriate layer if (children.Count != 0) { layer = layer.Add(new AggregateEntity(block.BasePoint.ToPoint(), children)); layers = layers.Insert(layer.Name, layer); } } drawing = new Drawing( settings: new DrawingSettings(fileName, file.Header.UnitFormat.ToUnitFormat(), file.Header.UnitPrecision), layers: layers, currentLayerName: file.Header.CurrentLayer ?? layers.GetKeys().OrderBy(x => x).First(), author: null); drawing.Tag = file; // prefer `*ACTIVE` view port first // TODO: use `DxfFile.ActiveViewPort` when available var vp = file.ViewPorts.FirstOrDefault(v => string.Compare(v.Name, DxfViewPort.ActiveViewPortName, StringComparison.OrdinalIgnoreCase) == 0) ?? file.ViewPorts.FirstOrDefault(); if (vp != null) { viewPort = new ViewPort( vp.LowerLeft.ToPoint(), vp.ViewDirection.ToVector(), Vector.YAxis, vp.ViewHeight); } else { viewPort = null; // auto-set it later } return(true); }
public void SkipOnEmptyIList() { Assert.Equal(ReadOnlyList.Empty <int>(), Array.Empty <int>().Skip(0)); Assert.Equal(ReadOnlyList.Empty <string>(), Array.Empty <string>().Skip(-1)); Assert.Equal(ReadOnlyList.Empty <double>(), Array.Empty <double>().Skip(1)); }
public void EmptyWithIndexedSelector() { Assert.Equal(ReadOnlyList.Empty <int>(), ReadOnlyList.Empty <string>().Select((s, i) => s.Length + i)); }
public IntellisenseSuggest Suggest(string language, TextInputState input) { string query = input.Text; int caret = input.Caret; var token = new MtgTolerantTokenizer(query).GetEditedToken(caret); if (token == null || token.Type.IsAny(TokenType.ModifierValue)) { return(LuceneSpellcheckerConstants.EmptySuggest); } string userField = token.ParentField ?? string.Empty; bool isFieldInvalid = !_adapter.IsAnyField(userField) && !_adapter.IsUserField(userField); if (!_adapter.IsSuggestAnalyzedIn(userField, language)) { token = token.PhraseStart ?? token; } string valuePart = StringEscaper.Unescape(query.Substring(token.Position, caret - token.Position)); if (token.Type.IsAny(TokenType.FieldValue | TokenType.Wildcard)) { IReadOnlyList <string> valueSuggest; if (isFieldInvalid || string.IsNullOrEmpty(userField) && string.IsNullOrEmpty(valuePart)) { valueSuggest = ReadOnlyList.Empty <string>(); } else if (_adapter.IsAnyField(userField)) { valueSuggest = suggestAllFieldValues(valuePart, language); } else { valueSuggest = suggestValues(userField, language, valuePart); } if (!string.IsNullOrEmpty(userField)) { return(new IntellisenseSuggest(token, valueSuggest, _allTokensAreValues)); } var fieldSuggest = suggestFields(fieldPart: valuePart); var values = fieldSuggest.Concat(valueSuggest).ToReadOnlyList(); var types = fieldSuggest.Select(_ => TokenType.Field) .Concat(valueSuggest.Select(_ => TokenType.FieldValue)) .ToReadOnlyList(); return(new IntellisenseSuggest(token, values, types)); } if (token.Type.IsAny(TokenType.Field)) { return(new IntellisenseSuggest(token, suggestFields(fieldPart: valuePart), _allTokensAreField)); } if (token.Type.IsAny(TokenType.Boolean)) { return(new IntellisenseSuggest(token, LuceneSpellcheckerConstants.BooleanOperators, LuceneSpellcheckerConstants.AllTokensAreBoolean)); } return(LuceneSpellcheckerConstants.EmptySuggest); }
public void SingletonEmpty() { ReadOnlyList.Empty <int>().AssertReferenceEquals(ReadOnlyList.Empty <int>()); ReadOnlyList.Empty <bool>().AssertReferenceEquals(ReadOnlyList.Empty <bool>()); ReadOnlyList.Empty <int>().AssertListEquals(new int[0]); }
public void CountOptimizationsThroughEmpty() { ReadOnlyList.Empty <int>().Take(5).AssertReferenceEquals(ReadOnlyList.Empty <int>()); ReadOnlyList.Empty <int>().Skip(5).AssertReferenceEquals(ReadOnlyList.Empty <int>()); }
public void SkipExcessiveIList() { Assert.Equal(ReadOnlyList.Empty <int>(), ReadOnlyList.Range(0, 20).Skip(42)); }