[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/Generics FixedSizeSet.cs,NONE,1.1 IS
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/Generics FixedSizeSet.cs,NONE,1.1 ISet.cs,NONE,1.1 ListSet.cs,NONE,1.1 ReadOnlySet.cs,NONE,1.1SynchronizedSet.cs,NONE,1.1 |
Date: |
Mon, 24 Feb 2003 20:19:45 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Generics
In directory subversions:/tmp/cvs-serv12481/Generics
Added Files:
FixedSizeSet.cs ISet.cs ListSet.cs ReadOnlySet.cs
SynchronizedSet.cs
Log Message:
Add set collections to the generics library.
--- NEW FILE ---
/*
* FixedSizeSet.cs - Wrap a set to make it fixed-size.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class FixedSizeSet<T> : FixedSizeCollection<T>, ISet<T>
{
// Internal state.
protected ISet<T> set;
// Constructor.
public FixedSizeSet(ISet<T> set) : base(set)
{
this.set = set;
}
// Implement the ISet<T> interface.
public void Add(T value)
{
throw new InvalidOperationException
(S._("NotSupp_FixedSizeCollection"));
}
public void Clear()
{
throw new InvalidOperationException
(S._("NotSupp_FixedSizeCollection"));
}
public bool Contains(T value)
{
return set.Contains(value);
}
public void Remove(T value)
{
throw new InvalidOperationException
(S._("NotSupp_FixedSizeCollection"));
}
public bool IsFixedSize
{
get
{
return true;
}
}
public bool IsReadOnly
{
get
{
return set.IsReadOnly;
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(set is ICloneable)
{
return new FixedSizeSet<T>
((ISet<T>)(((ICloneable)set).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class FixedSizeSet<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ISet.cs - Generic sets.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public interface ISet<T> : ICollection<T>
{
void Add(T value);
void Clear();
bool Contains(T value);
void Remove(T value);
bool IsFixedSize { get; }
bool IsReadOnly { get; }
}; // interface ISet<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ListSet.cs - Set implemented on top of a list.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public sealed class ListSet<T> : ISet<T>
{
// Internal state.
private IList<T> list;
// Constructors.
public ListSet()
{
list = new LinkedList<T>();
}
public ListSet(IList<T> list)
{
if(list == null)
{
throw new ArgumentNullException("list");
}
this.list = list;
}
// Implement the ISet<T> interface.
public void Add(T value)
{
if(!list.Contains(value))
{
list.Add(value);
}
}
public void Clear()
{
list.Clear();
}
public bool Contains(T value)
{
return list.Contains(value);
}
public void Remove(T value)
{
list.Remove(value);
}
public bool IsFixedSize
{
get
{
return list.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return list.IsReadOnly;
}
}
// Implement the ICollection<T> interface.
public void CopyTo(T[] array, int index)
{
list.CopyTo(array, index);
}
public int Count
{
get
{
return list.Count;
}
}
public bool IsSynchronized
{
get
{
return false;
}
}
public Object SyncRoot
{
get
{
return list.SyncRoot;
}
}
// Implement the IIterable<T> interface.
public IIterator<T> GetIterator()
{
return list.GetIterator();
}
}; // class ListSet<T>
}; // namespace Generics
--- NEW FILE ---
/*
* ReadOnlySet.cs - Wrap a set to make it read-only.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class ReadOnlySet<T> : ReadOnlyCollection<T>, ISet<T>
{
// Internal state.
protected ISet<T> set;
// Constructor.
public ReadOnlySet(ISet<T> set) : base(set)
{
this.set = set;
}
// Implement the ISet<T> interface.
public void Add(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public void Clear()
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool Contains(T value)
{
return set.Contains(value);
}
public void Remove(T value)
{
throw new
InvalidOperationException(S._("NotSupp_ReadOnly"));
}
public bool IsFixedSize
{
get
{
return set.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return true;
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(set is ICloneable)
{
return new ReadOnlySet<T>
((ISet<T>)(((ICloneable)set).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class ReadOnlySet<T>
}; // namespace Generics
--- NEW FILE ---
/*
* SynchronizedSet.cs - Wrap a set to make it synchronized.
*
* Copyright (c) 2003 Southern Storm Software, Pty Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Generics
{
using System;
public class SynchronizedSet<T> : SynchronizedCollection<T>, ISet<T>
{
// Internal state.
protected ISet<T> set;
// Constructor.
public SynchronizedSet(ISet<T> set) : base(set)
{
this.set = set;
}
// Implement the ISet<T> interface.
public void Add(T value)
{
lock(SyncRoot)
{
set.Add(value);
}
}
public void Clear()
{
lock(SyncRoot)
{
set.Clear();
}
}
public bool Contains(T value)
{
lock(SyncRoot)
{
return set.Contains(value);
}
}
public void Remove(T value)
{
lock(SyncRoot)
{
set.Remove(value);
}
}
public bool IsFixedSize
{
get
{
lock(SyncRoot)
{
return set.IsFixedSize;
}
}
}
public bool IsReadOnly
{
get
{
lock(SyncRoot)
{
return set.IsReadOnly;
}
}
}
// Implement the ICloneable interface.
public override Object Clone()
{
if(set is ICloneable)
{
return new SynchronizedSet<T>
((ISet<T>)(((ICloneable)set).Clone()));
}
else
{
throw new InvalidOperationException
(S._("Invalid_NotCloneable"));
}
}
}; // class SynchronizedSet<T>
}; // namespace Generics
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/Generics FixedSizeSet.cs,NONE,1.1 ISet.cs,NONE,1.1 ListSet.cs,NONE,1.1 ReadOnlySet.cs,NONE,1.1SynchronizedSet.cs,NONE,1.1,
Rhys Weatherley <address@hidden> <=