Skip to content

Commit 3ac2aac

Browse files
authored
Make static ParsedFile.Queue<IParsedLine> ParseFile() private (#169)
1 parent 806b9ff commit 3ac2aac

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

src/FileParser/Implementations/ParsedFile.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public ParsedFile(string path, char[] existingSeparator, bool ignoreEmptyItems =
4444
/// <param name="existingSeparator">Word separator (space by default)</param>
4545
/// <param name="ignoreEmptyItems"></param>
4646
public ParsedFile(string path, string? existingSeparator = null, bool ignoreEmptyItems = true)
47-
#pragma warning disable CS0618 // Type or member is obsolete - will keep it as private
48-
: base(ParseFile(path, existingSeparator, ignoreEmptyItems))
49-
#pragma warning restore CS0618 // Type or member is obsolete
47+
: base(ParseFile(path, ignoreEmptyItems, existingSeparator))
5048
{
5149
}
5250

@@ -76,7 +74,7 @@ public IParsedLine LastLine()
7674

7775
public List<T> ToList<T>(string? lineSeparatorToAdd = null)
7876
{
79-
List<T> list = new();
77+
List<T> list = [];
8078

8179
if (!string.IsNullOrEmpty(lineSeparatorToAdd))
8280
{
@@ -132,7 +130,7 @@ public static List<List<string>> ReadAllGroupsOfLines(string path)
132130
{
133131
if (currentGroup.Count != 0)
134132
{
135-
currentGroup = new List<string>();
133+
currentGroup = [];
136134
result.Add(currentGroup);
137135
}
138136
}
@@ -182,7 +180,7 @@ public static List<List<T>> ReadAllGroupsOfLines<T>(string path)
182180
{
183181
if (currentGroup.Count != 0)
184182
{
185-
currentGroup = new List<T>();
183+
currentGroup = [];
186184
result.Add(currentGroup);
187185
}
188186
}
@@ -208,16 +206,15 @@ public static List<List<T>> ReadAllGroupsOfLines<T>(string path)
208206
/// Queue&lt;IParsedLine&gt; ~~ Queues of 'words' inside of a queue of lines
209207
/// </summary>
210208
/// <param name="path"></param>
211-
/// <param name="existingSeparator">Word separator</param>
212209
/// <param name="ignoreEmptyItems"></param>
210+
/// <param name="existingSeparator">Word separator</param>
213211
/// <exception cref="FileNotFoundException"></exception>
214212
/// <exception cref="DirectoryNotFoundException"></exception>
215213
/// <exception cref="IOException"></exception>
216214
/// <exception cref="ArgumentException"></exception>
217215
/// <exception cref="ArgumentNullException"></exception>
218216
/// <returns></returns>
219-
[Obsolete("This method exposes internal functionality and was made public accidentally. It will be removed in next major release, please used ParsedFile constructor instead.")]
220-
public static Queue<IParsedLine> ParseFile(string path, string? existingSeparator = null, bool ignoreEmptyItems = true)
217+
private static Queue<IParsedLine> ParseFile(string path, bool ignoreEmptyItems, string? existingSeparator = null)
221218
{
222219
Queue<IParsedLine> parsedFile = new();
223220

src/FileParser/Implementations/ParsedLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public T LastElement<T>()
6262

6363
public List<T> ToList<T>()
6464
{
65-
List<T> list = new();
65+
List<T> list = [];
6666

6767
while (!Empty)
6868
{

src/FileParser/Utils/TypeValidator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ internal static class TypeValidator
55
/// <summary>
66
/// Supported parsing conversions
77
/// </summary>
8-
private static HashSet<Type> SupportedTypes { get; } = new HashSet<Type>()
9-
{
8+
private static HashSet<Type> SupportedTypes { get; } =
9+
[
1010
typeof(bool),
1111
typeof(char),
1212
typeof(string),
@@ -18,13 +18,13 @@ internal static class TypeValidator
1818
typeof(long),
1919
typeof(double),
2020
typeof(object)
21-
};
21+
];
2222

2323
internal static void ValidateSupportedType<T>()
2424
{
2525
if (!SupportedTypes.Contains(typeof(T)))
2626
{
27-
throw new NotSupportedException("Parsing to " + typeof(T).ToString() + "is not supported yet");
27+
throw new NotSupportedException("Parsing to " + typeof(T) + "is not supported yet");
2828
}
2929
}
3030
}

tests/FileParser.Test/ParsedFileTest/ExtractTests.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void CustomLineParse()
1111
const string fileName = "CustomLineParse.txt";
1212
const string sampleContent = " 3 1154 508 100 vegetable ";
1313

14-
List<long> expectedList = new() { 1154, 508, 100 };
14+
List<long> expectedList = [1154, 508, 100];
1515
const string expectedString = "vegetable";
1616

1717
using (StreamWriter writer = new(fileName))
@@ -54,8 +54,8 @@ public void ExtractChar()
5454
writer.WriteLine(line2);
5555
}
5656

57-
IParsedFile file = new ParsedFile(fileName);
58-
IParsedLine firstParsedLine = file.NextLine();
57+
var file = new ParsedFile(fileName);
58+
var firstParsedLine = file.NextLine();
5959
int nLines = Convert.ToInt32(Math.Floor(firstParsedLine.NextElement<double>())) - 1;
6060
for (int iLine = 0; iLine < nLines; ++iLine)
6161
{
@@ -89,7 +89,7 @@ public void MultipleCharWordSeparator()
8989
writer.WriteLine(line2);
9090
}
9191

92-
IParsedFile file = new ParsedFile(fileName, "||");
92+
var file = new ParsedFile(fileName, "||");
9393

9494
int index = 0;
9595
var line = file.NextLine();
@@ -122,7 +122,7 @@ public void ParseCsvFileIntoStrings()
122122
writer.WriteLine(line4);
123123
}
124124

125-
IParsedFile file = new ParsedFile(fileName, ",", ignoreEmptyItems: false);
125+
var file = new ParsedFile(fileName, ",", ignoreEmptyItems: false);
126126

127127
var headerLine = file.NextLine();
128128
var buckets = new List<List<string>>(headerLine.ToList<string>().Select(header => new List<string>(1000) { ModifyString(header) }));
@@ -138,10 +138,17 @@ public void ParseCsvFileIntoStrings()
138138

139139
static string ModifyString(string str) => str.ToLowerInvariant();
140140

141-
Assert.Equal(new[] { "firstname", "john", "cthulhu", "bugs" }, buckets[0]);
142-
Assert.Equal(new[] { "lastname", "doe", "", "bunny" }, buckets[1]);
143-
Assert.Equal(new[] { "age", "66", "1000", "33" }, buckets[2]);
144-
Assert.Equal(new[] { "eyecolor", "brown", "black", "white" }, buckets[3]);
141+
string[] expected = ["firstname", "john", "cthulhu", "bugs"];
142+
Assert.Equal(expected, buckets[0]);
143+
144+
string[] expected1 = ["lastname", "doe", "", "bunny"];
145+
Assert.Equal(expected1, buckets[1]);
146+
147+
string[] expected2 = ["age", "66", "1000", "33"];
148+
Assert.Equal(expected2, buckets[2]);
149+
150+
string[] expected3 = ["eyecolor", "brown", "black", "white"];
151+
Assert.Equal(expected3, buckets[3]);
145152
}
146153

147154
[Fact]
@@ -161,7 +168,7 @@ public void ParseCsvFile()
161168
writer.WriteLine(line4);
162169
}
163170

164-
IParsedFile file = new ParsedFile(fileName, ",", ignoreEmptyItems: false);
171+
var file = new ParsedFile(fileName, ",", ignoreEmptyItems: false);
165172

166173
file.NextLine();
167174

0 commit comments

Comments
 (0)