1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Add Set.cs from daddy cs2j

This commit is contained in:
Kevin Glynn 2011-01-07 16:10:05 +01:00
parent f9aedc1607
commit a5912958f3
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,67 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace RusticiSoftware.Translator.Utils
{
public class Set<T> : IEnumerable
{
///
/// Provides the storage for elements in the Set, stored as the key-set
/// of a Dictionary object.
///
protected Dictionary<T, object> setD = null;
private readonly static object PlaceholderObject = new object();
public Set()
{
setD = new Dictionary<T,object>();
}
public IEnumerator GetEnumerator()
{
return setD.Keys.GetEnumerator();
}
///
/// The placeholder object used as the value for the Dictionary object.
///
/// There is a single instance of this object globally, used for all Sets.
///
protected object Placeholder
{
get { return PlaceholderObject; }
}
///
/// Adds the specified element to this set if it is not already present.
/// o: The object to add to the set.
/// returns true if the object was added, false if it was already present.
public bool Add(T s)
{
if (setD.ContainsKey(s))
return false;
else
{
//The object we are adding is just a placeholder. The thing we are
//really concerned with is 'o', the key.
setD[s] = PlaceholderObject;
return true;
}
}
public T[] AsArray()
{
ICollection keys = setD.Keys;
T[] retArr = new T[keys.Count];
keys.CopyTo(retArr, 0);
return retArr;
}
}
}

View File

@ -39,7 +39,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Commandlineparameters> -translator-timestamp-files=false -translator-keep-parens=false -netdir=/Users/keving/gitrepos/cs2j/CS2JLibrary/NetFramework/ -dumpxmls -xmldir=/Users/keving/tmp/xml/se -odir=/Users/keving/tmp/java/se/src /Users/keving/svnrepos/ScormEngineNet/src/app/ScormEngine.Core/Logic/Integration/ExternalId.cs</Commandlineparameters>
<Commandlineparameters> -translator-timestamp-files=false -translator-keep-parens=false -netdir=/Users/keving/gitrepos/cs2j/CS2JLibrary/NetFramework/ -dumpxmls -xmldir=/Users/keving/tmp/xml/se -odir=/Users/keving/tmp/java/se/src /Users/keving/svnrepos/ScormEngineNet/src/app/ScormEngine.Core/Logic/Integration/ExternalConfiguration.cs</Commandlineparameters>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -70,6 +70,7 @@
<Compile Include="CSharp\JavaPrettyPrint.cs" />
<Compile Include="CSharp\NetMaker.cs" />
<Compile Include="CSharp\Templates.cs" />
<Compile Include="Utils\Set.cs" />
</ItemGroup>
<ItemGroup>
<None Include="CSharp\csCrawl.g" />