Skip to content

Commit

Permalink
-add: direct conversion method from IEnumerable<string> to
Browse files Browse the repository at this point in the history
IEnumerable<TokenWrapper>
  • Loading branch information
yas4891 committed May 4, 2012
1 parent 65c622f commit f1fafb9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
7 changes: 4 additions & 3 deletions GSTAppLogic/app/model/ComparisonModel.cs
Expand Up @@ -50,12 +50,13 @@ public ComparisonModel(IEnumerable<TokenWrapper> tokens, IEnumerable<SourceEntit
/// </summary>
public void Start()
{
var gstTokenList = Tokens.ToGSTTokenList();

int max = 0;
foreach (var data in ReferenceData)
{
var referenceTokens = data.Tokens.GetTokens().ToGSTTokenList();
// create the list here, because this way it is local to this run
// ==> more functional and separated
var gstTokenList = Tokens.ToGSTTokenList();
var referenceTokens = data.Tokens.ToGSTTokenList();
var algorithm = new GSTAlgorithm<GSTToken<TokenWrapper>>(gstTokenList, referenceTokens)
{
MinimumMatchLength = DEFAULT_MML
Expand Down
12 changes: 11 additions & 1 deletion GSTAppLogic/ext/LexerExtensions.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using CTokenizer;
using GSTLibrary.token;
using Tokenizer;

Expand All @@ -12,6 +13,15 @@ public static GSTTokenList<GSTToken<TokenWrapper>> ToGSTTokenList(this IEnumerab
return new GSTTokenList<GSTToken<TokenWrapper>>(tokens.Select(token => new GSTToken<TokenWrapper>(token)));
}


/// <summary>
/// converts the string representations of the tokens into appropriately wrapped objects
/// </summary>
/// <param name="tokens"></param>
/// <returns></returns>
public static GSTTokenList<GSTToken<TokenWrapper>> ToGSTTokenList(this IEnumerable<string> tokens)
{
var enumTokens = tokens.GetTokens();
return new GSTTokenList<GSTToken<TokenWrapper>>(enumTokens.Select(token => new GSTToken<TokenWrapper>(token)));
}
}
}
2 changes: 0 additions & 2 deletions GSTLibrary/tile/GSTAlgorithm.cs
Expand Up @@ -316,7 +316,5 @@ private int CalculateMatchLength(int offsetA, int offsetB)

return index;
}


}
}
4 changes: 2 additions & 2 deletions GSTTests.VisualState.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<VisualState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ShowCheckBoxes="true">
<TopNode>[0-1014]GSTLibrary.test.tile.GSTAlgorithmTest.MatchesTwoDifferentTiles</TopNode>
<SelectedNode>[0-1036]GSTConsole.test.GeneralHelperTest.GetStudentIdentifier</SelectedNode>
<TopNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</TopNode>
<SelectedNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</SelectedNode>
<ExcludeCategories>false</ExcludeCategories>
<Nodes>
<Node UniqueName="[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit" Expanded="true" />
Expand Down
14 changes: 1 addition & 13 deletions Tokenizer/TokenType.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tokenizer
{
Expand All @@ -13,23 +10,14 @@ public class TokenType
public Int32 Type { get; set; }


// override object.Equals
public override bool Equals(object obj)
{
//
// See the full list of guidelines at
// http://go.microsoft.com/fwlink/?LinkID=85237
// and also the guidance for operator== at
// http://go.microsoft.com/fwlink/?LinkId=85238
//

if (obj == null || GetType() != obj.GetType())
{
return false;
}

return Type == ((TokenType)obj).Type;

return Type == ((TokenType)obj).Type;
}

public override int GetHashCode()
Expand Down

0 comments on commit f1fafb9

Please sign in to comment.