public int Compare(string o1, string o2) { int cp1 = UnicodeSet.GetSingleCodePoint(o1); int cp2 = UnicodeSet.GetSingleCodePoint(o2); int result = cp1 - cp2; if (result != 0) { return(result); } if (cp1 == int.MaxValue) { return(o1.CompareToOrdinal(o2)); } return(0); }
/** * @param me * @param stayWithMe */ private void checkEquals(UnicodeMap <Integer> me, JCG.SortedDictionary <String, Integer> stayWithMe) { temp.Clear(); foreach (var e in me.EntrySet()) { temp.Add(e); } ISet <KeyValuePair <String, Integer> > entrySet = new JCG.HashSet <KeyValuePair <string, Integer> >(stayWithMe); if (!entrySet.SetEquals(temp)) { Logln(me.EntrySet().ToString()); Logln(me.ToString()); assertEquals("are in parallel", entrySet, temp); // we failed. Reset and start again entrySet.Clear(); temp.Clear(); return; } // ICU4N: looping through pairs instead of doing explicity table lookups is much faster foreach (var pair in stayWithMe) { assertEquals("containsKey", stayWithMe.ContainsKey(pair.Key), me.ContainsKey(pair.Key)); Integer value = pair.Value; assertEquals("get", value, me.Get(pair.Key)); assertEquals("containsValue", stayWithMe.ContainsValue(value), me.ContainsValue(value)); int cp = UnicodeSet.GetSingleCodePoint(pair.Key); if (cp != int.MaxValue) { assertEquals("get", value, me.Get(cp)); } } // ICU4N TODO: complete implementation //ISet<String> nonCodePointStrings = stayWithMe.tailMap("").keySet(); //if (nonCodePointStrings.Count == 0) nonCodePointStrings = null; // for parallel api //assertEquals("getNonRangeStrings", nonCodePointStrings, me.GetNonRangeStrings()); ISet <Integer> values = new JCG.SortedSet <Integer>(stayWithMe.Values); ISet <Integer> myValues = new JCG.SortedSet <Integer>(me.Values()); assertEquals("values", myValues, values); foreach (String key in stayWithMe.Keys) { assertEquals("containsKey", stayWithMe.ContainsKey(key), me.ContainsKey(key)); } }