/// <summary>For internal debugging purposes only.</summary> public static void Main(string[] args) { string[] test = new string[] { "a", "b", "c" }; IList <string> l = Arrays.AsList(test); System.Console.Out.WriteLine(AsArrayList(l.GetEnumerator())); System.Console.Out.WriteLine(AsHashSet(l.GetEnumerator())); System.Console.Out.WriteLine(AsCollection(l.GetEnumerator(), CollectionFactory.HashSetFactory <string>())); List <string> al = new List <string>(); al.Add("d"); System.Console.Out.WriteLine(AddAll(l.GetEnumerator(), al)); }
/// <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); } } }
/// <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()); } }
/// <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; }
/// <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) { }
/// <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) { }
/// <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) { }
// Utils for loading and saving Collections to/from text files /// <param name="filename">The path to the file to load the List from</param> /// <param name="c"> /// The Class to instantiate each member of the List. Must have a /// String constructor. /// </param> /// <exception cref="System.Exception"/> public static ICollection <T> LoadCollection <T>(string filename, CollectionFactory <T> cf) { System.Type c = typeof(T); return(LoadCollection(new File(filename), c, cf)); }
/// <summary>Adds the value to the collection given by map.get(key).</summary> /// <remarks>Adds the value to the collection given by map.get(key). A new collection is created using the supplied CollectionFactory.</remarks> public static void PutIntoValueCollection <K, V, C>(IDictionary <K, C> map, K key, V value, CollectionFactory <V> cf) where C : ICollection <V> { C c = map[key]; if (c == null) { c = ErasureUtils.UncheckedCast <C>(cf.NewCollection()); map[key] = c; } c.Add(value); }
/// <summary>Adds the value to the ArrayList given by map.get(key), creating a new ArrayList if needed.</summary> public static void PutIntoValueArrayList <K, V>(IDictionary <K, IList <V> > map, K key, V value) { CollectionFactory <V> factory = CollectionFactory.ArrayListFactory(); PutIntoValueCollection(map, key, value, factory); }
/// <summary>Adds the value to the HashSet given by map.get(key), creating a new HashMap if needed.</summary> public static void PutIntoValueHashSet <K, V>(IDictionary <K, ICollection <V> > map, K key, V value) { CollectionFactory <V> factory = CollectionFactory.HashSetFactory(); PutIntoValueCollection(map, key, value, factory); }
/// <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 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) { }