Exemplo n.º 1
0
        public void IgnoresCase()
        {
            CaseInsensitiveHashtable st = new CaseInsensitiveHashtable();

            st.Add("key", "value");
            Assert.AreEqual("value", st["KEY"]);
            st["KeY"] = "value2";
            Assert.AreEqual(1, st.Count);
            Assert.AreEqual("value2", st["key"]);

            try
            {
                st.Add("KEY", "value2");
                Assert.Fail();
            }
            catch (ArgumentException)
            { }

            Hashtable ht = new Hashtable();

            ht.Add("key", "value");
            ht.Add("KEY", "value");
            try
            {
                st = new CaseInsensitiveHashtable(ht, CultureInfo.InvariantCulture);
                Assert.Fail();
            }
            catch (ArgumentException)
            { }
        }
Exemplo n.º 2
0
        public void ComparePerformance()
        {
            const int runs  = 30000000;
            StopWatch watch = new StopWatch();

            Hashtable ht = CollectionsUtil.CreateCaseInsensitiveHashtable();

            for (int i = 0; i < 1000000; i++)
            {
                ht.Add(Guid.NewGuid().ToString(), "val");                               // gen. higher number of elements results in OOM exception????
            }
            CaseInsensitiveHashtable ciht = new CaseInsensitiveHashtable(ht, CultureInfo.InvariantCulture);

            using (watch.Start("Duration: {0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    object v = ht["somekey"];
                }
            }

            using (watch.Start("Duration: {0}"))
            {
                for (int i = 0; i < runs; i++)
                {
                    object v = ciht["somekey"];
                }
            }
        }
Exemplo n.º 3
0
        public void AcceptsNonStringKeys()
        {
            CaseInsensitiveHashtable st = new CaseInsensitiveHashtable();

            object key = new object();

            st.Add(key, "value");
            Assert.AreEqual(1, st.Count);
            Assert.AreEqual("value", st[key]);
            Assert.IsNull(st[new object()]);
        }
Exemplo n.º 4
0
        public void IsSerializable()
        {
            CaseInsensitiveHashtable storiginal = new CaseInsensitiveHashtable();

            storiginal.Add("key", "value");
            CaseInsensitiveHashtable st = (CaseInsensitiveHashtable)SerializeDeserializeObject(storiginal);

            Assert.AreNotSame(storiginal, st);
            Assert.AreEqual("value", st["KEY"]);
            Assert.AreEqual(1, st.Count);
        }
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Factory.Support.DefaultListableObjectFactory"/> class.
 /// </summary>
 /// <param name="caseSensitive">Flag specifying whether to make this object factory case sensitive or not.</param>
 /// <param name="parentFactory">The parent object factory.</param>
 public DefaultListableObjectFactory(bool caseSensitive, IObjectFactory parentFactory)
     : base(caseSensitive, parentFactory)
 {
     if (caseSensitive)
     {
         objectDefinitionMap = new Hashtable();
     }
     else
     {
         objectDefinitionMap = new CaseInsensitiveHashtable(); //CollectionsUtil.CreateCaseInsensitiveHashtable();
     }
 }
Exemplo n.º 6
0
        public void InitializeFromOtherCopiesValues()
        {
            Hashtable ht = new Hashtable();

            ht["key"]  = "value";
            ht["key2"] = "value2";

            CaseInsensitiveHashtable st = new CaseInsensitiveHashtable(ht, CultureInfo.InvariantCulture);

            Assert.AreEqual(2, st.Count);
            ht.Remove("key");
            Assert.AreEqual(1, ht.Count);
            Assert.AreEqual(2, st.Count);
        }
        /// <devdoc>
        ///     Recursive routine that creates a resource hashtable
        ///     populated with resources for culture and all parent
        ///     cultures.
        /// </devdoc>
        private Hashtable FillResources(CultureInfo culture, out ResourceSet resourceSet)
        {
            Hashtable   hashtable;
            ResourceSet parentResourceSet = null;

            // Traverse parents first, so we always replace more
            // specific culture values with less specific.
            //
            CultureInfo parent = culture.Parent;

            if (parent != culture)
            {
                hashtable = FillResources(parent, out parentResourceSet);
            }
            else
            {
                // We're at the bottom, so create the hashtable
                //
                if (IgnoreCase)
                {
                    hashtable = new CaseInsensitiveHashtable();
                }
                else
                {
                    hashtable = new Hashtable();
                }
            }

            // Now walk culture's resource set.  Another thing we
            // do here is ask ResourceManager to traverse up the
            // parent chain.  We do NOT want to do this because
            // we are trawling up the parent chain ourselves, but by
            // passing in true for the second parameter the resource
            // manager will cache the culture it did find, so when we
            // do recurse all missing resources will be filled in
            // so we are very fast.  That's why we remember what our
            // parent resource set's instance was -- if they are the
            // same, we're looking at a cache we've already applied.
            //
            resourceSet = GetResourceSet(culture, true, true);
            if (resourceSet != null && !object.ReferenceEquals(resourceSet, parentResourceSet))
            {
                foreach (DictionaryEntry de in resourceSet)
                {
                    hashtable[de.Key] = de.Value;
                }
            }

            return(hashtable);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns a redirect url string that points to the
        /// <see cref="Spring.Web.Support.Result.TargetPage"/> defined by this
        /// result.
        /// </summary>
        /// <param name="context">
        /// A redirect url string.
        /// </param>
        public virtual string GetRedirectUri(object context)
        {
            string path = GetResolvedTargetPage(context);

            IDictionary resolvedParameters = null;

            if (this.Parameters != null && this.Parameters.Count > 0)
            {
                resolvedParameters = new CaseInsensitiveHashtable();
                foreach (DictionaryEntry entry in this.Parameters)
                {
                    object key   = ResolveValueIfNecessary(context, entry.Key.ToString());
                    object value = ResolveValueIfNecessary(context, entry.Value.ToString());
                    resolvedParameters[key] = value;
                }
            }

            return(BuildUrl(path, resolvedParameters));
        }
Exemplo n.º 9
0
        public static int Main(string[] args)
        {
            // Create a class
            ManagementClass dummyClass = new ManagementClass("root/default", "", null);

            dummyClass.SystemProperties["__CLASS"].Value = "TestDelClassSync";
            PropertySet mykeyprop = dummyClass.Properties;

            mykeyprop.Add("MydelKey", "delHello");
            dummyClass.Put();

// Get the Class TestDelClassSync
            ManagementClass dummyDeleteCheck = new ManagementClass("root/default", "TestDelClassSync", null);

            dummyDeleteCheck.Get();

// Set the Delete Options on the Class TestDelClassSync
            //int Capacity = 8;
            CaseInsensitiveHashtable MyHash  = new CaseInsensitiveHashtable();
            DeleteOptions            Options = new DeleteOptions(MyHash);

            dummyDeleteCheck.Delete(Options);
            return(0);
        }
Exemplo n.º 10
0
        //template.frm:

        //            frml _DJRD log(qJealw) = -log(dtqjeal) + log(fXal)
        //                         + e11*log(pqjeal/pxal/dtqjeal)
        //                         + e12*log(pqjoal/pxal/dtqjoal) + k1 $
        //frml _DJRD log(qJoalw) = -log(dtqjoal) + log(fXal)
        //                         + e12*bshal*log(pqjeal/pxal/dtqjeal)
        //                         + e22*log(pqjoal/pxal/dtqjoal)
        //                         + gradk2*log(graddag)  + k2 $
        //frml _DJRD log(qJoalw) = -log(dtqjoal) + log(fXal)
        //                         + e12*bshal*log(pqjeal/pxal/dtqjeal)
        //                         + (-e12*bshal+e11+e12)*log(pqjoal/pxal/dtqjoal)
        //                         + gradk2*log(graddag) + k2 $
        //frml _SJRD Dlog(qJeal) = v1*dlog(qJealw) + c1*log(qJealw(-1)/qJeal(-1)) $
        //frml _SJRD Dlog(qJoal) = v2*dlog(qJoalw) + c2*log(qJoalw(-1)/qJoal(-1))
        //                         + (1-v2)*gradk2*Dlog(graddag) $

        //combine with .out file from tsp.

        public static void tspUtility(String dataFile, String templateFile, String frmOutputFile)
        {
            CaseInsensitiveHashtable ht      = new CaseInsensitiveHashtable();
            CaseInsensitiveHashtable htConst = new CaseInsensitiveHashtable();
            List <string>            al      = new List <string>(5000);
            List <string>            alType  = new List <string>(5000);
            List <string>            al1     = new List <string>(5000); //contains output

            Program.tokensFromFileToArrayList(dataFile, true, false, al, alType);
            List <string> aaName  = new List <string>();
            List <string> aaValue = new List <string>();

            bool constFlag         = false;
            bool constFlagVars     = true;
            bool constFlagData     = false;
            bool constFlagNegative = false;
            bool lsqFlag1          = false;
            bool lsqFlag2          = false;

            for (int i = 0; i < al.Count - Globals.extra; i++)
            {
                if (i >= 4 && al[i - 4] == "CONSTANTS" && al[i - 3] == ":" && al[i - 2] == "\r\n" && al[i - 1] == "\r\n")
                {
                    constFlag = true;
                }
                if (al[i] == "Log" && al[i + 1] == "likelihood")
                {
                    lsqFlag1 = true;
                }
                if (lsqFlag1 && al[i] == "Parameter" &&
                    al[i + 1] == "Estimate" &&
                    al[i + 2] == "Error" &&
                    al[i + 3] == "t" &&
                    al[i + 4] == "-" &&
                    al[i + 5] == "statistic" &&
                    al[i + 6] == "P" &&
                    al[i + 7] == "-" &&
                    al[i + 8] == "value")
                {
                    i       += 9;
                    lsqFlag2 = true;
                }

                if (constFlag)
                {
                    //bool VALUEencountered = false;
                    if (constFlagVars)
                    {
                        for (int iii = i; iii < int.MaxValue; iii++)
                        {
                            if (al[iii] == "\r\n")
                            {
                                if (al[iii + 1] != "VALUE")
                                {
                                    constFlag = false;
                                }
                                break;
                            }
                        }
                        if (constFlag)
                        {
                            if (alType[i] == "Word")
                            {
                                aaName.Add(al[i]);
                            }
                            else if (al[i] == "\r\n")
                            {
                                constFlagVars = false;
                                constFlagData = true;
                                //i++;  //so that consFlagData part starts at the right place
                                continue;  //with i
                            }
                            else
                            {
                                G.Writeln("*** ERROR in TSP utility");
                            }
                        }
                    }
                    if (constFlagData)
                    {
                        if (al[i] == "-" && alType[i + 1] == "Number")
                        {
                            i++;  //jump to number
                            constFlagNegative = true;
                        }
                        if (alType[i] == "Word")
                        {
                            if (al[i] == "VALUE")
                            {
                                //ok!
                                //i++; //to jump to first data
                                continue; //with i
                            }
                            else
                            {
                                G.Writeln("*** ERROR in TSP utility");
                            }
                        }
                        if (alType[i] == "Number")
                        {
                            if (constFlagNegative)
                            {
                                aaValue.Add("-" + al[i]);
                            }
                            else
                            {
                                aaValue.Add(al[i]);
                            }
                            constFlagNegative = false;
                        }
                        else if (al[i] == "\r\n")
                        {
                            constFlagVars = true;
                            constFlagData = false;

                            for (int iii = i; iii < int.MaxValue; iii++)
                            {
                                if (al[iii] != "\r\n")
                                {
                                    i = iii - 1;  //to jump past line breaks, to first non-line break
                                    break;
                                }
                            }
                        }
                        else if (al[i] == "-")
                        {
                            //ok
                        }
                        else
                        {
                            G.Writeln("*** ERROR in TSP utility");
                        }
                    }
                }
                if (lsqFlag2)
                {
                    if (al[i] == "Standard" && al[i + 1] == "Errors" && al[i + 2] == "computed")
                    {
                        lsqFlag1 = false;
                        lsqFlag2 = false;
                    }
                    else if (alType[i] == "Word")
                    {
                        String par = (string)al[i];
                        String val = "";
                        if (al[i + 1] == "-")
                        {
                            val = "-" + al[i + 2];
                        }
                        else
                        {
                            val = (string)al[i + 1];
                        }
                        if (ht.ContainsKey(par))
                        {
                            ht.Remove(par);
                        }
                        ht.Add(par, val);
                    }
                }
            }

            for (int i = 0; i < aaName.Count; i++)
            {
                if (htConst.ContainsKey(aaName[i]))
                {
                    htConst.Remove(aaName[i]);
                }
                htConst.Add(aaName[i], aaValue[i]);
            }

            al     = new List <string>(5000);
            alType = new List <string>(5000);

            Program.tokensFromFileToArrayList(templateFile, false, false, al, alType);

            //----------------------------------------------------
            //
            int  allCounter   = 0;
            int  constCounter = 0;
            bool skipOne      = false;

            for (int i = 0; i < al.Count - Globals.extra; i++)
            {
                if (G.TspUtilityFindType(al, alType, i, 0) == "Symbol" && G.TspUtilityFindType(al, alType, i, +1) == "Word")
                {
                    String varName = G.TspUtilityFindToken(al, alType, i, +1);
                    Object value1  = ht[varName];
                    Object value2  = htConst[varName];
                    Object value   = value1;
                    if (value1 == null && value2 != null)
                    {
                        value = value2;
                        constCounter++;
                    }
                    if (value != null)
                    {
                        allCounter++;
                        //found in hash table, i.e. the value of this varName should be substituted in
                        skipOne = true;
                        //It would be strange to have a variable being a number as the first item in the template, so therefore i>=1 is ok.
                        //Even if so, the code should work fine.
                        if (i >= 1 && ((String)value).StartsWith("-"))
                        {
                            if (G.TspUtilityFindToken(al, alType, i, 0) == "+")
                            {
                                //... + a1 + ... ---> ... -0.1234 + ...
                                al1.Add(G.Add0Ifmissing((String)value));
                            }
                            else if (G.TspUtilityFindToken(al, alType, i, 0) == "=" || G.TspUtilityFindToken(al, alType, i, 0) == "(")
                            {
                                //... = a1 + ... ---> ... = -0.1234 + ...
                                //... ( a1 + ... ---> ... ( -0.1234 + ...
                                al1.Add(al[i]);
                                al1.Add(G.Add0Ifmissing((String)value));
                            }
                            else
                            {
                                //... * a1 + ... ---> ... * (-0.1234) + ...
                                al1.Add(al[i]);
                                al1.Add("(");
                                al1.Add(G.Add0Ifmissing((String)value));
                                al1.Add(")");
                            }
                        }
                        else
                        {
                            //val is positive
                            //val does not start with "-"
                            al1.Add(al[i]);
                            al1.Add(G.Add0Ifmissing((String)value));
                        }
                        //i++;
                    }
                    else
                    {
                        //Word is not a variable
                        al1.Add(al[i]);
                        al1.Add(varName);
                    }
                    i = G.TspUtilitiesFindIndex(al, alType, i, +1);  //jumps forward to the new i
                }
                else
                {
                    //current pos is not a symbol, and/or next non-whitespace token is not a word
                    al1.Add(al[i]);
                }
            }

            using (FileStream fs = Program.WaitForFileStream(frmOutputFile, Program.GekkoFileReadOrWrite.Write))
                using (StreamWriter res = G.GekkoStreamWriter(fs))
                {
                    for (int i = 0; i < al1.Count; i++)
                    {
                        res.Write(al1[i]);
                    }
                    res.Flush();
                    res.Close();
                    G.Writeln("Inserted " + allCounter + " numbers, hereof " + (allCounter - constCounter) + " parameter values and " + constCounter + " constant values.");
                    G.Writeln("Output is in the file: output.frm.");
                    G.Writeln();
                }
        }