SetWrapper.cs :  » GIS » DeepEarth » Iesi_NTS » Collections » Generic » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » Iesi_NTS » Collections » Generic » SetWrapper.cs
using System;
using System.Collections;
using System.Collections.Generic;

namespace Iesi_NTS.Collections.Generic{
    /// <summary>
    /// A wrapper that can wrap a ISet as a generic ISet&lt;T&gt; 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <remarks>
    /// In most operations, there is no copying of collections. The wrapper just delegate the function to the wrapped.
    /// The following functions' implementation may involve collection copying:
    /// Union, Intersect, Minus, ExclusiveOr, ContainsAll, AddAll, RemoveAll, RetainAll
    /// </remarks>
    /// <exception cref="InvalidCastException">
    /// If the wrapped has any item that is not of Type T, InvalidCastException could be thrown at any time
    /// </exception>
    public sealed class SetWrapper<T> : ISet<T>
    {
        private ISet innerSet;
        
        
        private SetWrapper(){}
        
        public SetWrapper(ISet toWrap)
        {
            if (toWrap == null)
                throw new ArgumentNullException();
            this.innerSet = toWrap;
            
        }
        
        #region ISet<T> Members

        #region Operators
        
        public ISet<T> Union(ISet<T> a)
        {
            return getSetCopy().Union(a);
        }

        public ISet<T> Intersect(ISet<T> a)
        {
            return getSetCopy().Intersect(a);  
        }

        public ISet<T> Minus(ISet<T> a)
        {
            return getSetCopy().Minus(a);
        }

        public ISet<T> ExclusiveOr(ISet<T> a)
        {
            return getSetCopy().ExclusiveOr(a);
        } 
        
        #endregion

        public bool Contains(T o)
        {
            return innerSet.Contains(o);
        }

        public bool ContainsAll(ICollection<T> c)
        {
            return innerSet.ContainsAll(getSetCopy(c));
        }

        public bool IsEmpty
        {
            get { return innerSet.IsEmpty; }
        }
        
        public bool Add(T o)
        {
            return innerSet.Add(o);
        }

        public bool AddAll(ICollection<T> c)
        {
            return innerSet.AddAll(getSetCopy(c));
        }

        public bool Remove(T o)
        {
            return innerSet.Remove(o);
        }

        public bool RemoveAll(ICollection<T> c)
        {
            return innerSet.RemoveAll(getSetCopy(c));
        }

        public bool RetainAll(ICollection<T> c)
        {
            return innerSet.RemoveAll(getSetCopy(c));
        }

        public void Clear()
        {
            innerSet.Clear();
        }

        public ISet<T> Clone()
        {
            return new SetWrapper<T>((ISet)innerSet.Clone());
        }

        public int Count
        {
            get {
                return innerSet.Count;
            }
        }

    
        #endregion

        #region ICollection<T> Members

        void ICollection<T>.Add(T item)
        {
            Add(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            innerSet.CopyTo(array, arrayIndex);
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return new EnumeratorWrapper<T>(innerSet.GetEnumerator());
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return innerSet.GetEnumerator();
        }

        #endregion

        #region ICloneable Members

        object ICloneable.Clone()
        {
            return Clone();
        }

        #endregion

        #region private methods
        private Set<T> getSetCopy(ICollection<T> c)
        {
            return new HashedSet<T>(c);
        }
        private Set<T> getSetCopy(ICollection c)
        {
            Set<T> retVal = new HashedSet<T>();
            ((ISet)retVal).AddAll(c);
            return retVal;
        }
        private Set<T> getSetCopy()
        {
            return getSetCopy(innerSet);
        } 
        #endregion
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.