Skip to content

Commit

Permalink
Lists used instead of dictionaries for ToolCollection, CategoryCollec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
lxgreen committed Aug 17, 2015
1 parent facf416 commit cc79aaa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 49 deletions.
19 changes: 4 additions & 15 deletions DefragEngine/DefragEngine/CategoryCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@

namespace DefragEngine
{
public class CategoryCollection : Dictionary<Guid, ToolCategory>
public class CategoryCollection : List<ToolCategory>
{
public void Add(ToolCategory category)
{
Add(category.ID, category);
}

public bool Remove(ToolCategory tool)
{
return Remove(tool.ID);
}


public void Add(params ToolCategory[] tools)
{
foreach (var tool in tools)
{
Add(tool);
}
AddRange(tools);
}

public IEnumerable<ToolCategory> this[string name]
{
get
{
return from category in this.Values
return from category in this
where category.Name == name
select category;
}
Expand Down
25 changes: 12 additions & 13 deletions DefragEngine/DefragEngine/ClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="DefragEngine.Tool">
<Position X="3.5" Y="3.5" Width="1.5" />
<Position X="3.75" Y="3.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AEgAAAAAAAAAAAAAAAAAACAAAAAAAAAgAABAAAACCAA=</HashCode>
<HashCode>AEgAAAAAAAAAEAAAAAAAACAAAAAAAAAgAABAAAACAAA=</HashCode>
<FileName>Tool.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="Category" />
<Property Name="Properties" />
</ShowAsAssociation>
</Class>
<Class Name="DefragEngine.ToolCategory">
<Position X="6.25" Y="3.5" Width="1.5" />
<Position X="6.25" Y="3.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAA=</HashCode>
<FileName>ToolCategory.cs</FileName>
Expand All @@ -22,37 +21,37 @@
</ShowAsAssociation>
</Class>
<Class Name="DefragEngine.ToolCollection">
<Position X="7" Y="6.5" Width="1.75" />
<Position X="6.75" Y="6.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAIAAAAAAAAAAAAACAAABAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAIAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>ToolCollection.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DefragEngine.ToolBundle">
<Position X="8.5" Y="3.5" Width="1.5" />
<Position X="9.25" Y="3.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAAgAAAAAAAAQAAAAAAAAAAAAAAAEAAAAAAAAAAAAAQ=</HashCode>
<FileName>ToolBundle.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="Categories" />
</ShowAsAssociation>
</Class>
<Class Name="DefragEngine.DefragEngineBaseUnit">
<Position X="6" Y="0.5" Width="2" />
<Position X="6" Y="0.5" Width="2.75" />
<TypeIdentifier>
<HashCode>IAAAAAAAAAAggAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>DefragEngineBaseUnit.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DefragEngine.CategoryCollection" Collapsed="true">
<Position X="9.25" Y="2" Width="2" />
<Class Name="DefragEngine.CategoryCollection">
<Position X="12.5" Y="4.25" Width="1.75" />
<TypeIdentifier>
<HashCode>AAIAAAAAAAAAAAAACAAABAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAIAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>CategoryCollection.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DefragEngine.PropertyCollection" Collapsed="true">
<Class Name="DefragEngine.PropertyCollection">
<Position X="0.75" Y="4.5" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
Expand Down
4 changes: 2 additions & 2 deletions DefragEngine/DefragEngine/ToolBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public string ToXML()
new XAttribute("Name", Name),
new XAttribute("Version", Version),
new XElement("Description", Description),
new XElement("Categories", from category in Categories.Values select
new XElement("Categories", from category in Categories select
new XElement("Category",
new XAttribute("ID", category.ID),
new XAttribute("Name", category.Name),
new XAttribute("Version", category.Version),
new XElement("Description", category.Description),
new XElement("Tools", from tool in category.Tools.Values select
new XElement("Tools", from tool in category.Tools select
new XElement("Tool",
new XAttribute("ID", tool.ID),
new XAttribute("Name", tool.Name),
Expand Down
21 changes: 4 additions & 17 deletions DefragEngine/DefragEngine/ToolCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@

namespace DefragEngine
{
public class ToolCollection : Dictionary<Guid, Tool>
{
public void Add(Tool tool)
{
Add(tool.ID, tool);
}

public bool Remove(Tool tool)
{
return Remove(tool.ID);
}

public class ToolCollection : List<Tool>
{
public void Add(params Tool[] tools)
{
foreach (var tool in tools)
{
Add(tool);
}
AddRange(tools);
}

public IEnumerable<Tool> this[string name]
{
get
{
return from tool in this.Values
return from tool in this
where tool.Name == name
select tool;
}
Expand Down
4 changes: 2 additions & 2 deletions DefragEngine/DefragEngineTests/BundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void BundleSerializationTest()
Assert.AreEqual(serializedBundle.Version, deserializedBundle.Version);
Assert.AreEqual(serializedBundle.Description, deserializedBundle.Description);

foreach (var category in serializedBundle.Categories.Values)
foreach (var category in serializedBundle.Categories)
{
var deserializedCategory = deserializedBundle.Categories[category.Name].First();

Expand All @@ -191,7 +191,7 @@ public void BundleSerializationTest()
Assert.AreEqual(deserializedCategory.Version, category.Version);
Assert.AreEqual(deserializedCategory.Description, category.Description);

foreach (var tool in category.Tools.Values)
foreach (var tool in category.Tools)
{
var deserializedTool = deserializedCategory.Tools[tool.Name].First();

Expand Down

0 comments on commit cc79aaa

Please sign in to comment.