// Bulk Operations
 /// <summary>This is more expensive than normal.</summary>
 public override void Clear()
 {
     // iterate over all keys in originalMap and set them to null in deltaMap
     foreach (K key in originalMap.Keys)
     {
         deltaMap[key] = ErasureUtils.UncheckedCast(removedValue);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes this ArrayCoreMap, pre-allocating arrays to hold
 /// up to capacity key,value pairs.
 /// </summary>
 /// <remarks>
 /// Initializes this ArrayCoreMap, pre-allocating arrays to hold
 /// up to capacity key,value pairs.  This array will grow if necessary.
 /// </remarks>
 /// <param name="capacity">Initial capacity of object in key,value pairs</param>
 public ArrayCoreMap(int capacity)
 {
     /*, Serializable */
     // = null;
     // = 0;
     keys   = ErasureUtils.UncheckedCast(new Type[capacity]);
     values = new object[capacity];
 }
            public override bool Equals(object o)
            {
                if (!(o is DictionaryEntry))
                {
                    return(false);
                }
                DictionaryEntry e = ErasureUtils.UncheckedCast(o);

                return(Eq(key, e.Key) && Eq(value, e.Value));
            }
Ejemplo n.º 4
0
 /* Maps */
 public static IDictionary <K, V> NewHashMap <K, V>()
 {
     try
     {
         return(ErasureUtils.UncheckedCast(System.Activator.CreateInstance(HashMapClass)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 5
0
 public static ICollection <E> NewHashSet <E>()
 {
     try
     {
         return(ErasureUtils.UncheckedCast(System.Activator.CreateInstance(HashSetClass)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 public static ICollection <E> NewHashSet <E, _T1>(ICollection <_T1> c)
     where _T1 : E
 {
     try
     {
         return(ErasureUtils.UncheckedCast(HashSetCollectionConstructor.NewInstance(c)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Reduces memory consumption to the minimum for representing the values
 /// currently stored stored in this object.
 /// </summary>
 public virtual void Compact()
 {
     if (keys.Length > size)
     {
         Type[]   newKeys   = new Type[size];
         object[] newValues = new object[size];
         System.Array.Copy(keys, 0, newKeys, 0, size);
         System.Array.Copy(values, 0, newValues, 0, size);
         keys   = ErasureUtils.UncheckedCast(newKeys);
         values = newValues;
     }
 }
Ejemplo n.º 9
0
 public static IDictionary <K, V> NewHashMap <K, V, _T2>(IDictionary <_T2> m)
     where _T2 : K
 {
     try
     {
         return(ErasureUtils.UncheckedCast(HashMapFromMapConstructor.NewInstance(m)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 10
0
 /// <summary>Returns a clone of this priority queue.</summary>
 /// <remarks>
 /// Returns a clone of this priority queue.  Modifications to one will not
 /// affect modifications to the other.
 /// </remarks>
 public Edu.Stanford.Nlp.Util.FixedPrioritiesPriorityQueue <E> Clone()
 {
     Edu.Stanford.Nlp.Util.FixedPrioritiesPriorityQueue <E> clonePQ;
     clonePQ            = ErasureUtils.UncheckedCast(base.MemberwiseClone());
     clonePQ.elements   = new List <E>(capacity);
     clonePQ.priorities = new double[capacity];
     if (Count > 0)
     {
         Sharpen.Collections.AddAll(clonePQ.elements, elements);
         System.Array.Copy(priorities, 0, clonePQ.priorities, 0, Count);
     }
     return(clonePQ);
 }
Ejemplo n.º 11
0
 public virtual void SetCapacity(int newSize)
 {
     if (size > newSize)
     {
         throw new Exception("You cannot set capacity to smaller than the current size.");
     }
     Type[]   newKeys   = new Type[newSize];
     object[] newValues = new object[newSize];
     System.Array.Copy(keys, 0, newKeys, 0, size);
     System.Array.Copy(values, 0, newValues, 0, size);
     keys   = ErasureUtils.UncheckedCast(newKeys);
     values = newValues;
 }
Ejemplo n.º 12
0
        /// <summary>Returns the current set of unique labels, sorted by their string order.</summary>
        private IList <U> SortKeys()
        {
            ICollection <U> labels = UniqueLabels();

            if (labels.Count == 0)
            {
                return(Java.Util.Collections.EmptyList());
            }
            bool comparable = true;

            foreach (U label in labels)
            {
                if (!(label is IComparable))
                {
                    comparable = false;
                    break;
                }
            }
            if (comparable)
            {
                IList <IComparable <object> > sorted = Generics.NewArrayList();
                foreach (U label_1 in labels)
                {
                    sorted.Add(ErasureUtils.UncheckedCast <IComparable <object> >(label_1));
                }
                sorted.Sort();
                IList <U> ret = Generics.NewArrayList();
                foreach (object o in sorted)
                {
                    ret.Add(ErasureUtils.UncheckedCast <U>(o));
                }
                return(ret);
            }
            else
            {
                List <string>          names  = new List <string>();
                Dictionary <string, U> lookup = new Dictionary <string, U>();
                foreach (U label_1 in labels)
                {
                    names.Add(label_1.ToString());
                    lookup[label_1.ToString()] = label_1;
                }
                names.Sort();
                List <U> ret = new List <U>();
                foreach (string name in names)
                {
                    ret.Add(lookup[name]);
                }
                return(ret);
            }
        }
        private int Compare(BinaryHeapPriorityQueue.Entry <E> entryA, BinaryHeapPriorityQueue.Entry <E> entryB)
        {
            int result = Compare(entryA.priority, entryB.priority);

            if (result != 0)
            {
                return(result);
            }
            if ((entryA.key is IComparable) && (entryB.key is IComparable))
            {
                IComparable <E> key = ErasureUtils.UncheckedCast(entryA.key);
                return(key.CompareTo(entryB.key));
            }
            return(result);
        }
Ejemplo n.º 14
0
 public static IDictionary <K, V> NewHashMap <K, V>(int initialCapacity)
 {
     if (HashMapSizeConstructor == null)
     {
         return(NewHashMap());
     }
     try
     {
         return(ErasureUtils.UncheckedCast(HashMapSizeConstructor.NewInstance(initialCapacity)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Deserialize this Object in a manner which is binary-compatible with
        /// the JDK.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private void ReadObject(ObjectInputStream s)
        {
            int    size;
            int    expectedMaxSize;
            object o;

            expectedMaxSize = s.ReadInt();
            size            = s.ReadInt();
            map             = new IdentityHashMap <E, bool>(expectedMaxSize);
            for (int i = 0; i < size; i++)
            {
                o = s.ReadObject();
                InternalAdd(ErasureUtils.UncheckedCast <E>(o));
            }
        }
Ejemplo n.º 16
0
        private static void RunRelaxingTests(string className)
        {
            BinaryHeapPriorityQueue <string> queue;

            try
            {
                queue = ErasureUtils.UncheckedCast(System.Activator.CreateInstance(Sharpen.Runtime.GetType(className)));
            }
            catch (Exception e)
            {
                Fail(e.ToString());
                return;
            }
            RunRelaxingTests(queue);
        }
Ejemplo n.º 17
0
 public static ICollection <E> NewHashSet <E>(int initialCapacity)
 {
     if (HashSetSizeConstructor == null)
     {
         return(NewHashSet());
     }
     try
     {
         return(ErasureUtils.UncheckedCast(HashSetSizeConstructor.NewInstance(initialCapacity)));
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
 }
 /// <returns>
 /// true iff o is a CollectionValuedMap, and each key maps to the a
 /// Collection of the same objects in o as it does in this
 /// CollectionValuedMap.
 /// </returns>
 public override bool Equals(object o)
 {
     if (this == o)
     {
         return(true);
     }
     if (!(o is Edu.Stanford.Nlp.Util.CollectionValuedMap <object, object>))
     {
         return(false);
     }
     Edu.Stanford.Nlp.Util.CollectionValuedMap <K, V> other = ErasureUtils.UncheckedCast(o);
     if (other.Count != Count)
     {
         return(false);
     }
     try
     {
         foreach (KeyValuePair <K, ICollection <V> > e in this)
         {
             K key = e.Key;
             ICollection <V> value = e.Value;
             if (value == null)
             {
                 if (!(other[key] == null && other.Contains(key)))
                 {
                     return(false);
                 }
             }
             else
             {
                 if (!value.Equals(other[key]))
                 {
                     return(false);
                 }
             }
         }
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 19
0
        private static void RunNotRelaxingTests(string className)
        {
            FixedPrioritiesPriorityQueue <string> pq;

            try
            {
                pq = ErasureUtils.UncheckedCast(System.Activator.CreateInstance(Sharpen.Runtime.GetType(className)));
            }
            catch (Exception e)
            {
                Fail(e.ToString());
                return;
            }
            NUnit.Framework.Assert.AreEqual("[]", pq.ToString());
            pq.Add("one", 1);
            NUnit.Framework.Assert.AreEqual("[one=1.0]", pq.ToString());
            pq.Add("three", 3);
            NUnit.Framework.Assert.AreEqual("[three=3.0, one=1.0]", pq.ToString());
            pq.Add("one", 1.1);
            NUnit.Framework.Assert.AreEqual("[three=3.0, one=1.1, one=1.0]", pq.ToString());
            pq.Add("two", 2);
            NUnit.Framework.Assert.AreEqual("[three=3.0, two=2.0, one=1.1, one=1.0]", pq.ToString());
            NUnit.Framework.Assert.AreEqual("[three=3.000, two=2.000, ...]", pq.ToString(2));
            FixedPrioritiesPriorityQueue <string> clone = pq.Clone();

            NUnit.Framework.Assert.AreEqual(3.0, clone.GetPriority());
            NUnit.Framework.Assert.AreEqual(pq.Current, clone.Current);
            NUnit.Framework.Assert.AreEqual(2.0, clone.GetPriority());
            NUnit.Framework.Assert.AreEqual(pq.Current, clone.Current);
            NUnit.Framework.Assert.AreEqual(1.1, clone.GetPriority());
            NUnit.Framework.Assert.AreEqual(pq.Current, clone.Current);
            NUnit.Framework.Assert.AreEqual(1.0, clone.GetPriority());
            NUnit.Framework.Assert.AreEqual(pq.Current, clone.Current);
            NUnit.Framework.Assert.IsFalse(clone.MoveNext());
            NUnit.Framework.Assert.IsTrue(clone.IsEmpty());
        }
 public static IComparator <T> LengthEndpointsComparator <T>()
     where T : IHasInterval <int>
 {
     return(ErasureUtils.UncheckedCast(HasIntervalConstants.LengthEndpointsComparator));
 }
Ejemplo n.º 21
0
 public static CollectionFactory <E> LinkedListFactory <E>()
 {
     return(ErasureUtils.UncheckedCast(LinkedListFactory));
 }
Ejemplo n.º 22
0
 public static CollectionFactory <E> TreeSetFactory <E>()
 {
     return(ErasureUtils.UncheckedCast(TreeSetFactory));
 }
Ejemplo n.º 23
0
 public Beam(int maxBeamSize)
     : this(maxBeamSize, ErasureUtils.UncheckedCast <IComparator <T> >(ScoredComparator.AscendingComparator))
 {
 }
Ejemplo n.º 24
0
 public static CollectionFactory <E> ArrayListFactory <E>(int size)
 {
     return(ErasureUtils.UncheckedCast(new CollectionFactory.SizedArrayListFactory(size)));
 }
 public static IToDoubleFunction <T> LengthScorer <T>()
     where T : IHasInterval <int>
 {
     return(ErasureUtils.UncheckedCast(LengthScorer));
 }