From 187c6528a99c52f1588df074c975f19b57f2eb14 Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Wed, 13 Apr 2011 15:58:32 +0200 Subject: [PATCH] Add CollectionSupport class to turn a java collection into a c# collection --- .../Collections/Generic/Dictionary'2.xml | 6 +- .../Collections/Generic/IDictionary'2.xml | 8 +- .../Collections/Generic/KeyCollection'1.xml | 5 +- .../Generic/CollectionSupport.java | 176 ++++++++++++++++++ 4 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 CS2JLibrary/src/CS2JNet/JavaSupport/Collections/Generic/CollectionSupport.java diff --git a/CS2JLibrary/NetFramework/System/Collections/Generic/Dictionary'2.xml b/CS2JLibrary/NetFramework/System/Collections/Generic/Dictionary'2.xml index a133a92..4d549a0 100644 --- a/CS2JLibrary/NetFramework/System/Collections/Generic/Dictionary'2.xml +++ b/CS2JLibrary/NetFramework/System/Collections/Generic/Dictionary'2.xml @@ -98,10 +98,12 @@ ${this:16}.size() - + + CS2JNet.JavaSupport.Collections.Generic.CollectionSupport + System.Collections.Generic.KeyCollection*[K]* Keys - ${this:16}.keySet() + CollectionSupport.mk(${this:16}.keySet()) diff --git a/CS2JLibrary/NetFramework/System/Collections/Generic/IDictionary'2.xml b/CS2JLibrary/NetFramework/System/Collections/Generic/IDictionary'2.xml index b80085e..5987e54 100644 --- a/CS2JLibrary/NetFramework/System/Collections/Generic/IDictionary'2.xml +++ b/CS2JLibrary/NetFramework/System/Collections/Generic/IDictionary'2.xml @@ -1,4 +1,4 @@ - + + CS2JNet.JavaSupport.Collections.Generic.CollectionSupport - Set*[${T}]* + CollectionSupport*[${T}]* System.Collections.Generic.KeyCollection @@ -28,7 +29,7 @@ CS2JNet.System.Collections.Generic.KeyCollectionSupport - KeyCollectionSupport.CopyTo(${this}, ${array}, ${index}) + ${this:16}.CopyTo(${array}, ${index}) T[] diff --git a/CS2JLibrary/src/CS2JNet/JavaSupport/Collections/Generic/CollectionSupport.java b/CS2JLibrary/src/CS2JNet/JavaSupport/Collections/Generic/CollectionSupport.java new file mode 100644 index 0000000..c44afae --- /dev/null +++ b/CS2JLibrary/src/CS2JNet/JavaSupport/Collections/Generic/CollectionSupport.java @@ -0,0 +1,176 @@ +/* + Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Author(s): + + Kevin Glynn (kevin.glynn@twigletsoftware.com) +*/ +package CS2JNet.JavaSupport.Collections.Generic; + +import java.util.Collection; +import java.util.Iterator; + +import org.apache.commons.lang.NullArgumentException; + +import CS2JNet.JavaSupport.CS2JRunTimeException; +import CS2JNet.System.ArgumentException; +import CS2JNet.System.Collections.Generic.ICollectionSupport; +import CS2JNet.System.Collections.Generic.IEnumeratorSupport; + +/** + * A concrete implementation of .Net's ICollection that wraps a Collection + * + * @author keving + * + * @param + */ +public class CollectionSupport implements ICollectionSupport { + + private Collection myCollection = null; + + public CollectionSupport(Collection inColl) { + myCollection = inColl; + } + + public static CollectionSupport mk(Collection inColl) { + return new CollectionSupport(inColl); + } + + + public Iterator iterator() { + return myCollection.iterator(); + } + + + @Override + public boolean add(T arg0) { + return myCollection.add(arg0); + } + + + @Override + public boolean addAll(Collection arg0) { + return myCollection.addAll(arg0); + } + + + @Override + public void clear() { + myCollection.clear(); + } + + + @Override + public boolean contains(Object arg0) { + return myCollection.contains(arg0); + } + + + @Override + public boolean containsAll(Collection arg0) { + return myCollection.containsAll(arg0); + } + + + @Override + public boolean isEmpty() { + return myCollection.isEmpty(); + } + + + @Override + public boolean remove(Object arg0) { + return myCollection.remove(arg0); + } + + + @Override + public boolean removeAll(Collection arg0) { + return myCollection.removeAll(arg0); + } + + + @Override + public boolean retainAll(Collection arg0) { + return myCollection.retainAll(arg0); + } + + + @Override + public int size() { + return myCollection.size(); + } + + + @Override + public Object[] toArray() { + return myCollection.toArray(); + } + + + @Override + public S[] toArray(S[] arg0) { + return myCollection.toArray(arg0); + } + + + @Override + public boolean Contains(T x) throws Exception { + return myCollection.contains(x); + } + + + @Override + public void Add(T x) throws Exception { + myCollection.add(x); + + } + + + @Override + public boolean Remove(T x) throws Exception { + return myCollection.remove(x); + } + + + @Override + public void Clear() throws Exception { + myCollection.clear(); + + } + + + @Override + public IEnumeratorSupport GetEnumerator() throws Exception { + return new EnumeratorSupport(myCollection.iterator()); + } + + + @Override + public void CopyTo(T[] arr, int i) throws Exception { + if (arr == null) { + throw new NullArgumentException("arr"); + } + if (i < 0 || i + myCollection.size() > arr.length) { + throw new ArgumentException("i"); + } + int idx = 0; + for (T e : this) { + arr[i+idx] = e; + } + + } + +}