/// <summary>Creates a new CollectionValuedMap with all of the mappings from cvm.</summary> /// <param name="cvm">The CollectionValueMap to copy as this object.</param> public CollectionValuedMap(Edu.Stanford.Nlp.Util.CollectionValuedMap <K, V> cvm) { this.mf = cvm.mf; this.cf = cvm.cf; this.treatCollectionsAsImmutable = cvm.treatCollectionsAsImmutable; this.emptyValue = cvm.emptyValue; map = Java.Util.Collections.SynchronizedMap(mf.NewMap()); foreach (KeyValuePair <K, ICollection <V> > entry in cvm.map) { K key = entry.Key; ICollection <V> c = entry.Value; foreach (V value in c) { Add(key, value); } } }
/// <exception cref="System.TypeLoadException"/> /// <exception cref="System.MissingMethodException"/> /// <exception cref="System.MemberAccessException"/> /// <exception cref="System.Reflection.TargetInvocationException"/> /// <exception cref="Java.Lang.InstantiationException"/> public static IDictionary <K, V> GetMapFromString <K, V>(string s, MapFactory <K, V> mapFactory) { System.Type keyClass = typeof(K); System.Type valueClass = typeof(V); Constructor <K> keyC = keyClass.GetConstructor(new Type[] { typeof(string) }); Constructor <V> valueC = valueClass.GetConstructor(new Type[] { typeof(string) }); if (s[0] != '{') { throw new Exception(string.Empty); } s = Sharpen.Runtime.Substring(s, 1); // get rid of first brace string[] fields = s.Split("\\s+"); IDictionary <K, V> m = mapFactory.NewMap(); // populate m for (int i = 0; i < fields.Length; i++) { // log.info("Parsing " + fields[i]); fields[i] = Sharpen.Runtime.Substring(fields[i], 0, fields[i].Length - 1); // get rid of // following // comma or // brace string[] a = fields[i].Split("="); K key = keyC.NewInstance(a[0]); V value; if (a.Length > 1) { value = valueC.NewInstance(a[1]); } else { value = valueC.NewInstance(string.Empty); } m[key] = value; } return(m); }
/// <summary>Creates a new CollectionValuedMap.</summary> /// <param name="mf">A MapFactory which will be used to generate the underlying Map</param> /// <param name="cf"> /// A CollectionFactory which will be used to generate the Collections /// in each mapping /// </param> /// <param name="treatCollectionsAsImmutable"> /// If true, forces this Map to create new a Collection every time a /// new value is added to or deleted from the Collection a mapping. /// </param> /// <param name="map"> /// An existing map to use rather than initializing one with mf. If this is non-null it is /// used to initialize the map rather than mf. /// </param> private CollectionValuedMap(MapFactory <K, ICollection <V> > mf, CollectionFactory <V> cf, bool treatCollectionsAsImmutable, IDictionary <K, ICollection <V> > map) { if (cf == null) { throw new ArgumentException(); } if (mf == null && map == null) { throw new ArgumentException(); } this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; this.emptyValue = cf.NewEmptyCollection(); if (map != null) { this.map = map; } else { this.map = Java.Util.Collections.SynchronizedMap(mf.NewMap()); } }
public virtual void TestTreeMapIterator() { TwoDimensionalMap <string, string, string> map = new TwoDimensionalMap <string, string, string>(MapFactory.TreeMapFactory <string, IDictionary <string, string> >(), MapFactory.TreeMapFactory <string, string>()); map.Put("A", "B", "C"); map.Put("Z", "Y", "X"); map.Put("Z", "B", "C"); map.Put("A", "Y", "X"); map.Put("D", "D", "D"); map.Put("D", "F", "E"); map.Put("K", "G", "B"); map.Put("G", "F", "E"); map.Put("D", "D", "E"); // sneaky overwritten entry NUnit.Framework.Assert.AreEqual(8, map.Size()); IEnumerator <TwoDimensionalMap.Entry <string, string, string> > mapIterator = map.GetEnumerator(); TwoDimensionalMap.Entry <string, string, string> entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("A", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("B", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("C", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("A", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("Y", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("X", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("D", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("D", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("E", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("D", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("F", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("E", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("G", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("F", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("E", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("K", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("G", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("B", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("Z", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("B", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("C", entry.GetValue()); entry = mapIterator.Current; NUnit.Framework.Assert.AreEqual("Z", entry.GetFirstKey()); NUnit.Framework.Assert.AreEqual("Y", entry.GetSecondKey()); NUnit.Framework.Assert.AreEqual("X", entry.GetValue()); NUnit.Framework.Assert.IsFalse(mapIterator.MoveNext()); IEnumerator <string> valueIterator = map.ValueIterator(); NUnit.Framework.Assert.IsTrue(valueIterator.MoveNext()); NUnit.Framework.Assert.AreEqual("C", valueIterator.Current); NUnit.Framework.Assert.AreEqual("X", valueIterator.Current); NUnit.Framework.Assert.AreEqual("E", valueIterator.Current); NUnit.Framework.Assert.AreEqual("E", valueIterator.Current); NUnit.Framework.Assert.AreEqual("E", valueIterator.Current); NUnit.Framework.Assert.AreEqual("B", valueIterator.Current); NUnit.Framework.Assert.AreEqual("C", valueIterator.Current); NUnit.Framework.Assert.AreEqual("X", valueIterator.Current); NUnit.Framework.Assert.IsFalse(valueIterator.MoveNext()); }
public virtual void TestMapFactory() { TwoDimensionalMap <string, string, string> map = new TwoDimensionalMap <string, string, string>(MapFactory.IdentityHashMapFactory <string, IDictionary <string, string> >(), MapFactory.IdentityHashMapFactory <string, string>()); map.Put(new string("A"), "B", "C"); map.Put(new string("A"), "B", "C"); NUnit.Framework.Assert.AreEqual(2, map.Size()); }
public BinaryHeapPriorityQueue(MapFactory <E, BinaryHeapPriorityQueue.Entry <E> > mapFactory, int initCapacity) { indexToEntry = new List <BinaryHeapPriorityQueue.Entry <E> >(initCapacity); keyToEntry = mapFactory.NewMap(initCapacity); }
public BinaryHeapPriorityQueue(MapFactory <E, BinaryHeapPriorityQueue.Entry <E> > mapFactory) { indexToEntry = new List <BinaryHeapPriorityQueue.Entry <E> >(); keyToEntry = mapFactory.NewMap(); }
/// <summary>This is very cheap.</summary> /// <param name="originalMap">will serve as the basis for this DeltaMap</param> public DeltaMap(IDictionary <K, V> originalMap, MapFactory <K, V> mf) { this.originalMap = Java.Util.Collections.UnmodifiableMap(originalMap); // unmodifiable for debugging only this.deltaMap = mf.NewMap(); }
/// <summary>Creates a new empty TwoDimensionalCollectionValuedMap.</summary> /// <remarks> /// Creates a new empty TwoDimensionalCollectionValuedMap. /// Does not treat Collections as immutable. /// </remarks> /// <param name="mf">a MapFactory which will be used to generate the underlying Map</param> /// <param name="cf">a CollectionFactory which will be used to generate the Collections in each mapping</param> public TwoDimensionalCollectionValuedMap(MapFactory <K2, ICollection <V> > mf, CollectionFactory <V> cf) : this(mf, cf, false) { }
public static Edu.Stanford.Nlp.Util.TwoDimensionalMap <K1, K2, V> IdentityHashMap <K1, K2, V>() { return(new Edu.Stanford.Nlp.Util.TwoDimensionalMap <K1, K2, V>(MapFactory.IdentityHashMapFactory <K1, IDictionary <K2, V> >(), MapFactory.IdentityHashMapFactory <K2, V>())); }
public TwoDimensionalMap(MapFactory <K1, IDictionary <K2, V> > mf1, MapFactory <K2, V> mf2) { this.mf1 = mf1; this.mf2 = mf2; this.map = mf1.NewMap(); }
public TwoDimensionalMap() : this(MapFactory.HashMapFactory <K1, IDictionary <K2, V> >(), MapFactory.HashMapFactory <K2, V>()) { }
/// <summary> /// Creates a new empty CollectionValuedMap which uses a HashMap as the /// underlying Map. /// </summary> /// <remarks> /// Creates a new empty CollectionValuedMap which uses a HashMap as the /// underlying Map. Does not treat Collections as immutable. /// </remarks> /// <param name="cf"> /// A CollectionFactory which will be used to generate the Collections /// in each mapping /// </param> public CollectionValuedMap(CollectionFactory <V> cf) : this(MapFactory.HashMapFactory(), cf, false) { }
/// <summary> /// Creates a new empty CollectionValuedMap which uses a HashMap as the /// underlying Map, and HashSets as the Collections in each mapping. /// </summary> /// <remarks> /// Creates a new empty CollectionValuedMap which uses a HashMap as the /// underlying Map, and HashSets as the Collections in each mapping. Does not /// treat Collections as immutable. /// </remarks> public CollectionValuedMap() : this(MapFactory.HashMapFactory(), CollectionFactory.HashSetFactory(), false) { }
/// <summary> /// Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the /// underlying Map, and HashSets as the Collections in each mapping. /// </summary> /// <remarks> /// Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the /// underlying Map, and HashSets as the Collections in each mapping. Does not /// treat Collections as immutable. /// </remarks> public TwoDimensionalCollectionValuedMap() : this(MapFactory.HashMapFactory <K2, ICollection <V> >(), CollectionFactory.HashSetFactory <V>(), false) { }
public virtual BinaryHeapPriorityQueue <E> DeepCopy() { return(DeepCopy(MapFactory.HashMapFactory <E, BinaryHeapPriorityQueue.Entry <E> >())); }
/// <summary> /// Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the /// underlying Map. /// </summary> /// <remarks> /// Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the /// underlying Map. Does not treat Collections as immutable. /// </remarks> /// <param name="cf"> /// a CollectionFactory which will be used to generate the /// Collections in each mapping /// </param> public TwoDimensionalCollectionValuedMap(CollectionFactory <V> cf) : this(MapFactory.HashMapFactory <K2, ICollection <V> >(), cf, false) { }
public BinaryHeapPriorityQueue() : this(MapFactory.HashMapFactory <E, BinaryHeapPriorityQueue.Entry <E> >()) { }
/// <summary>Creates a new empty TwoDimensionalCollectionValuedMap.</summary> /// <param name="mf">a MapFactory which will be used to generate the underlying Map</param> /// <param name="cf">a CollectionFactory which will be used to generate the Collections in each mapping</param> /// <param name="treatCollectionsAsImmutable"> /// if true, forces this Map to create new a Collection everytime /// a new value is added to or deleted from the Collection a mapping. /// </param> public TwoDimensionalCollectionValuedMap(MapFactory <K2, ICollection <V> > mf, CollectionFactory <V> cf, bool treatCollectionsAsImmutable) { this.mf = mf; this.cf = cf; this.treatCollectionsAsImmutable = treatCollectionsAsImmutable; }
public BinaryHeapPriorityQueue(int initCapacity) : this(MapFactory.HashMapFactory <E, BinaryHeapPriorityQueue.Entry <E> >(), initCapacity) { }
public DeltaMap(IDictionary <K, V> originalMap) : this(originalMap, MapFactory.HashMapFactory()) { }
/// <summary>Creates a new empty CollectionValuedMap.</summary> /// <param name="mf">A MapFactory which will be used to generate the underlying Map</param> /// <param name="cf"> /// A CollectionFactory which will be used to generate the Collections /// in each mapping /// </param> /// <param name="treatCollectionsAsImmutable"> /// If true, forces this Map to create new a Collection every time a /// new value is added to or deleted from the Collection a mapping. /// </param> public CollectionValuedMap(MapFactory <K, ICollection <V> > mf, CollectionFactory <V> cf, bool treatCollectionsAsImmutable) : this(mf, cf, treatCollectionsAsImmutable, null) { }