예제 #1
0
 /* Boilerplate */
 public override bool Equals(Object other)
 {
     if (other == null)
     {
         return(false);
     }
     try {
         UnicodeMap that = (UnicodeMap)other;
         if (length != that.length)
         {
             return(false);
         }
         for (int i = 0; i < length - 1; ++i)
         {
             if (transitions[i] != that.transitions[i])
             {
                 return(false);
             }
             if (!AreEqual(values[i], that.values[i]))
             {
                 return(false);
             }
         }
         return(true);
     } catch (InvalidCastException e) {
         return(false);
     }
 }
예제 #2
0
 /// <summary>
 /// Add all the (main) values from a Unicode property
 /// </summary>
 ///
 /// <param name="prop">the property to add to the map</param>
 /// <returns>this (for chaining)</returns>
 public UnicodeMap PutAll(UnicodeMap prop)
 {
     // TODO optimize
     for (int i = 0; i <= 0x10FFFF; ++i)
     {
         _put(i, prop.GetValue(i));
     }
     return(this);
 }
예제 #3
0
        /// <summary>
        /// Standard clone. Warning, as with Collections, does not do deep clone.
        /// </summary>
        ///
        public Object CloneAsThawed()
        {
            UnicodeMap that = new UnicodeMap();

            that.length          = length;
            that.transitions     = (int[])transitions.Clone();
            that.values          = (Object[])values.Clone();
            that.availableValues = new HashedSet(availableValues);
            that.locked          = false;
            return(that);
        }
예제 #4
0
        static internal void GeneratePropertyAliases(bool showValues,
                                                     UnicodeProperty.Factory ups)
        {
            ComparatorInfo order  = System.Globalization.ComparatorInfo.GetInstance(System.Globalization.CultureInfo.CreateSpecificCulture("en"));
            SortedSet      props  = new SortedSet(order);
            SortedSet      values = new SortedSet(order);
            BagFormatter   bf     = new BagFormatter();

            ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(ups.GetAvailableNames(), props);
            for (int i = IBM.ICU.Charset.UnicodeProperty.BINARY; i < IBM.ICU.Charset.UnicodeProperty.LIMIT_TYPE; ++i)
            {
                System.Console.Out.WriteLine(IBM.ICU.Charset.UnicodeProperty.GetTypeName(i));
                IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(props.GetEnumerator());
                while (it.HasNext())
                {
                    String          propAlias = (String)it.Next();
                    UnicodeProperty up        = ups.GetProperty(propAlias);
                    int             type      = up.GetType();
                    if (type != i)
                    {
                        continue;
                    }
                    System.Console.Out.WriteLine();
                    System.Console.Out.WriteLine(propAlias + "\t"
                                                 + bf.Join(up.GetNameAliases()));
                    if (!showValues)
                    {
                        continue;
                    }
                    ILOG.J2CsMapping.Collections.Collections.Clear(values);
                    if (type == IBM.ICU.Charset.UnicodeProperty.NUMERIC ||
                        type == IBM.ICU.Charset.UnicodeProperty.EXTENDED_NUMERIC)
                    {
                        UnicodeMap um = new UnicodeMap();
                        um.PutAll(up);
                        System.Console.Out.WriteLine(um.ToString(new TestBagFormatter.NumberComparator()));
                        continue;
                    }
                    ILOG.J2CsMapping.Collections.Collections.Clear(values);
                    ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(up.GetAvailableValues(), values);
                    IIterator it2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(values.GetEnumerator());
                    while (it2.HasNext())
                    {
                        String valueAlias = (String)it2.Next();
                        System.Console.Out.WriteLine("\t"
                                                     + bf.Join(valueAlias + "\t"
                                                               + up.GetValueAliases(valueAlias)));
                    }
                }
            }
        }
예제 #5
0
 public UnicodeMap ComposeWith(UnicodeMap other, UnicodeMap.Composer composer)
 {
     for (int i = 0; i <= 0x10FFFF; ++i)
     {
         Object v1 = GetValue(i);
         Object v2 = other.GetValue(i);
         Object v3 = composer.Compose(i, v1, v2);
         if (v1 != v3 && (v1 == null || !v1.Equals(v3)))
         {
             Put(i, v3);
         }
     }
     return(this);
 }
예제 #6
0
            /*
             * @see com.ibm.icu.dev.test.TestBoilerplate#_createTestObject()
             */
            protected internal override bool _addTestObject(IList list)
            {
                if (list.Count > 30)
                {
                    return(false);
                }
                UnicodeMap result = new UnicodeMap();

                for (int i = 0; i < 50; ++i)
                {
                    int    start     = IBM.ICU.Charset.TestUtilities.random.Next(25);
                    String value_ren = IBM.ICU.Charset.TestUtilities.TEST_VALUES[IBM.ICU.Charset.TestUtilities.random.Next(TEST_VALUES.Length)];
                    result.Put(start, value_ren);
                }
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(list, result);
                return(true);
            }
예제 #7
0
        internal double _checkSetTime(int iterations, int type)
        {
            map1 = new UnicodeMap();
            map2 = new Hashtable();
            System.Console.Gc();
            double start = DateTime.Now.Millisecond;

            for (int j = 0; j < iterations; ++j)
            {
                for (int cp = 0; cp <= SET_LIMIT; ++cp)
                {
                    int enumValue = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(cp, propEnum);
                    if (enumValue <= 0)
                    {
                        continue;     // for smaller set
                    }
                    String value_ren = IBM.ICU.Lang.UCharacter.GetPropertyValueName(propEnum,
                                                                                    enumValue, IBM.ICU.Lang.UProperty.NameChoice.LONG);
                    switch (type)
                    {
                    case 0:
                        map1.Put(cp, value_ren);
                        break;

                    case 1:
                        ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(cp)), value_ren);
                        break;

                    case 3:
                        ILOG.J2CsMapping.Collections.Collections.Put(map3, ((int)(cp)), value_ren);
                        break;
                    }
                }
            }
            double end = DateTime.Now.Millisecond;

            return((end - start) / 1000 / iterations);
        }
예제 #8
0
        public void TestUnicodeMap()
        {
            random.SetSeed(12345);
            // do random change to both, then compare
            Logln("Comparing against HashMap");
            for (int counter = 0; counter < ITERATIONS; ++counter)
            {
                int    start     = random.Next(LIMIT);
                String value_ren = TEST_VALUES[random.Next(TEST_VALUES.Length)];
                String logline   = IBM.ICU.Impl.Utility.Hex(start) + "\t" + value_ren;
                if (SHOW_PROGRESS)
                {
                    Logln(counter + "\t" + logline);
                }
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(log, logline);
                if (DEBUG && counter == 144)
                {
                    System.Console.Out.WriteLine(" debug");
                }
                map1.Put(start, value_ren);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(start)), value_ren);
                Check(counter);
            }
            CheckNext(LIMIT);

            Logln("Setting General Category");
            map1 = new UnicodeMap();
            map2 = new SortedList();
            for (int cp = 0; cp <= SET_LIMIT; ++cp)
            {
                int enumValue = IBM.ICU.Lang.UCharacter.GetIntPropertyValue(cp, propEnum);
                // if (enumValue <= 0) continue; // for smaller set
                String value_0 = IBM.ICU.Lang.UCharacter.GetPropertyValueName(propEnum, enumValue,
                                                                              IBM.ICU.Lang.UProperty_Constants.NameChoice.LONG);
                map1.Put(cp, value_0);
                ILOG.J2CsMapping.Collections.Collections.Put(map2, ((int)(cp)), value_0);
            }
            CheckNext(Int32.MaxValue);

            Logln("Comparing General Category");
            Check(-1);
            Logln("Comparing Values");
            ILOG.J2CsMapping.Collections.ISet values1 = (ISet)map1.GetAvailableValues(new SortedSet());
            ILOG.J2CsMapping.Collections.ISet values2 = new SortedSet(map2.Values);
            if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, values1, values2))
            {
                throw new ArgumentException("Halting");
            }
            Logln("Comparing Sets");
            for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(values1.GetEnumerator()); it.HasNext();)
            {
                Object value_1 = it.Next();
                Logln((value_1 == null) ? "null" : value_1.ToString());
                UnicodeSet set1 = map1.GetSet(value_1);
                UnicodeSet set2 = IBM.ICU.Charset.TestBoilerplate.GetSet(map2, value_1);
                if (!IBM.ICU.Charset.TestBoilerplate.VerifySetsIdentical(this, set1, set2))
                {
                    throw new ArgumentException("Halting");
                }
            }

            Logln("Getting Scripts");
            UnicodeMap scripts = IBM.ICU.Charset.ICUPropertyFactory.Make().GetProperty("script")
                                 .GetUnicodeMap_internal();

            UnicodeMap.Composer composer = new TestUtilities.Anonymous_C1();

            Logln("Trying Compose");
            UnicodeMap composed = ((UnicodeMap)scripts.CloneAsThawed())
                                  .ComposeWith(map1, composer);
            Object last = "";

            for (int i = 0; i < 0x10FFFF; ++i)
            {
                Object comp = composed.GetValue(i);
                Object gc   = map1.GetValue(i);
                Object sc   = scripts.GetValue(i);
                if (!comp.Equals(composer.Compose(i, gc, sc)))
                {
                    Errln("Failed compose at: " + i);
                }
                if (!last.Equals(comp))
                {
                    Logln(IBM.ICU.Impl.Utility.Hex(i) + "\t" + comp);
                    last = comp;
                }
            }

            // check boilerplate
            IList argList = new ArrayList();

            ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "TestMain");
            if (paras.nothrow)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-nothrow");
            }
            if (paras.verbose)
            {
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(argList, "-verbose");
            }
            String[] args = new String[argList.Count];
            ILOG.J2CsMapping.Collections.Collections.ToArray(argList, args);
            new TestUtilities.UnicodeMapBoilerplate().Run(args);
            // TODO: the following is not being reached
            new TestUtilities.UnicodeSetBoilerplate().Run(args);
        }
예제 #9
0
 public UnicodeMap.MapIterator  Reset(UnicodeMap newMap)
 {
     this.map = newMap;
     return(Reset());
 }
예제 #10
0
 public MapIterator(UnicodeMap map_0)
 {
     Reset(map_0);
 }