mirror of
https://github.com/chylex/Code-Statistics.git
synced 2025-05-24 15:34:08 +02:00
Add a Node collection object to Core
This commit is contained in:
parent
85168862ca
commit
c53f0a7eda
CodeStatisticsCore
@ -41,6 +41,7 @@
|
||||
<Compile Include="Collections\CharacterRangeSet.cs" />
|
||||
<Compile Include="Collections\CounterDictionary.cs" />
|
||||
<Compile Include="Collections\EnumDictionary.cs" />
|
||||
<Compile Include="Collections\Node.cs" />
|
||||
<Compile Include="Collections\TopElementList.cs" />
|
||||
<Compile Include="Handling\Files\AbstractFileHandler.cs" />
|
||||
<Compile Include="Handling\Files\AbstractLanguageFileHandler.cs" />
|
||||
|
62
CodeStatisticsCore/Collections/Node.cs
Normal file
62
CodeStatisticsCore/Collections/Node.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CodeStatisticsCore.Collections{
|
||||
public sealed class Node{
|
||||
public string Text{
|
||||
get{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Node> Children{
|
||||
get{
|
||||
return children ?? Enumerable.Empty<Node>();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string text;
|
||||
private List<Node> children;
|
||||
|
||||
public Node(string text){
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
private void PrepareChildList(){
|
||||
if (children == null){
|
||||
children = new List<Node>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Node node){
|
||||
PrepareChildList();
|
||||
children.Add(node);
|
||||
}
|
||||
|
||||
public void Add(string nodeText){
|
||||
PrepareChildList();
|
||||
children.Add(new Node(nodeText));
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<Node> nodes){
|
||||
PrepareChildList();
|
||||
children.AddRange(nodes);
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<string> nodeTexts){
|
||||
PrepareChildList();
|
||||
children.AddRange(nodeTexts.Select(text => new Node(text)));
|
||||
}
|
||||
|
||||
public void AddRangeAsStrings(IEnumerable<object> objects){
|
||||
PrepareChildList();
|
||||
children.AddRange(objects.Select(obj => new Node(obj.ToString())));
|
||||
}
|
||||
|
||||
public void AddRangeAsStrings(IEnumerable objects){
|
||||
PrepareChildList();
|
||||
children.AddRange(objects.Cast<object>().Select(obj => new Node(obj.ToString())));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user