static internal void TestLocales() { CultureInfo[] locales = System.Globalization.ComparatorInfo.GetAvailableLocales(); ILOG.J2CsMapping.Collections.ISet s = new SortedSet(System.Globalization.ComparatorInfo.GetInstance()); for (int i = 0; i < locales.Length; ++i) { String lang = locales[i].TwoLetterISOLanguageName; String dlang = locales[i].GetDisplayLanguage(); String country = ILOG.J2CsMapping.Util.Culture.CultureInfoHelper.GetCountry(locales[i]); String dcountry = locales[i].GetDisplayCountry(); if (country.Equals("")) { continue; } ILOG.J2CsMapping.Collections.Generics.Collections.Add(s, "" + "\t" + dcountry + "\t" + country + "\t" + dlang + "\t" + lang); } // CollectionFormatter cf = new CollectionFormatter(); StreamWriter pw = IBM.ICU.Charset.BagFormatter.OpenUTF8Writer("", "countries.txt"); IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(s.GetEnumerator()); while (it.HasNext()) { pw.WriteLine(it.Next()); } pw.Close(); }
// for subclassing protected internal void DoAt(ICollection c) { if (c.Count == 0) { DoBefore(c, null); } IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); bool first = true; Object last = null; while (it.HasNext()) { Object item = it.Next(); if (first) { DoBefore(c, item); first = false; } else { DoBetween(c, last, item); } DoAt(last = item); } DoAfter(c, last); }
/// <summary> /// Stop notifying this listener. The listener must not be null. Attemps to /// remove a listener that is not registered will be silently ignored. /// </summary> /// public void RemoveListener(IEventListener l) { if (l == null) { throw new NullReferenceException(); } lock (notifyLock) { if (listeners != null) { // identity equality check IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(listeners.GetEnumerator()); while (iter.HasNext()) { if (iter.Next() == (Object)l) { iter.Remove(); if (listeners.Count == 0) { listeners = null; } return; } } } } }
/// <summary> /// Return a snapshot of the mapping from display names to visible IDs for /// this service. This set will not change as factories are added or removed, /// but the supported ids will, so there is no guarantee that all and only /// the ids in the returned map will be visible and supported by the service /// in subsequent calls, nor is there any guarantee that the current display /// names match those in the set. The display names are sorted based on the /// comparator provided. /// </summary> /// public SortedList GetDisplayNames(ULocale locale, IComparer com, String matchID) { SortedList dncache = null; ICUService.LocaleRef xref = dnref; if (xref != null) { dncache = xref.Get(locale, com); } while (dncache == null) { lock (this) { if (xref == dnref || dnref == null) { dncache = new SortedList(com); // sorted IDictionary m = GetVisibleIDMap(); IIterator ei = new ILOG.J2CsMapping.Collections.IteratorAdapter(m.GetEnumerator()); while (ei.HasNext()) { DictionaryEntry e = (DictionaryEntry)ei.Next(); String id_0 = (String)((DictionaryEntry)e).Key; ICUService.Factory f = (ICUService.Factory)((DictionaryEntry)e).Value; ILOG.J2CsMapping.Collections.Collections.Put(dncache, f.GetDisplayName(id_0, locale), id_0); } dncache = /*ILOG.J2CsMapping.Collections.Generics.Collections.UnmodifiableSortedMap(*/ dncache /*)*/; dnref = new ICUService.LocaleRef(dncache, locale, com); } else { xref = dnref; dncache = xref.Get(locale, com); } } } ICUService.Key matchKey = CreateKey(matchID); if (matchKey == null) { return(dncache); } SortedList result = new SortedList(dncache); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(result.GetEnumerator()); while (iter.HasNext()) { DictionaryEntry e_1 = (DictionaryEntry)iter.Next(); if (!matchKey.IsFallbackOf((String)((DictionaryEntry)e_1).Value)) { iter.Remove(); } } return(result); }
private ICUPropertyFactory() { ICollection c = GetInternalAvailablePropertyAliases(new ArrayList()); IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); while (it.HasNext()) { Add(GetInternalProperty((String)it.Next())); } }
public Object GetFirst(ICollection c) { IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); if (!it.HasNext()) { return(null); } return(it.Next()); }
// ----------------------------------------------------------------------------- // // printSet Debug function. Print the contents of a set of Nodes // // ----------------------------------------------------------------------------- internal void PrintSet(ICollection s) { IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(s.GetEnumerator()); while (it.HasNext()) { RBBINode n = (RBBINode)it.Next(); IBM.ICU.Text.RBBINode.PrintInt(n.fSerialNum, 8); } System.Console.Out.WriteLine(); }
/// <summary> /// Override of superclass method. /// </summary> /// public override void UpdateVisibleIDs(IDictionary result) { ILOG.J2CsMapping.Collections.ISet visibleIDs = IBM.ICU.Impl.ICUResourceBundle .GetAvailableLocaleNameSet(bundleName); // only visible ids IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(visibleIDs.GetEnumerator()); while (iter.HasNext()) { String id_0 = (String)iter.Next(); ILOG.J2CsMapping.Collections.Collections.Put(result, id_0, this); } }
/// <exclude/> /// <summary> /// Simple implementation of permutation. <br> /// <b>Warning: The strings are not guaranteed to be in any particular /// order.</b> /// </summary> /// /// <param name="source">the string to find permutations for</param> /// <param name="skipZeros">set to true to skip characters with canonical combining classzero</param> /// <param name="output">the set to add the results to</param> public static void Permute(String source, bool skipZeros, ILOG.J2CsMapping.Collections.ISet output) { // TODO: optimize // if (PROGRESS) System.out.println("Permute: " + source); // optimization: // if zero or one character, just return a set with it // we check for length < 2 to keep from counting code points all the // time if (source.Length <= 2 && IBM.ICU.Text.UTF16.CountCodePoint(source) <= 1) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(output, source); return; } // otherwise iterate through the string, and recursively permute all the // other characters ILOG.J2CsMapping.Collections.ISet subpermute = new HashedSet(); int cp; for (int i = 0; i < source.Length; i += IBM.ICU.Text.UTF16.GetCharCount(cp)) { cp = IBM.ICU.Text.UTF16.CharAt(source, i); // optimization: // if the character is canonical combining class zero, // don't permute it if (skipZeros && i != 0 && IBM.ICU.Lang.UCharacter.GetCombiningClass(cp) == 0) { // System.out.println("Skipping " + // Utility.hex(UTF16.valueOf(source, i))); continue; } // see what the permutations of the characters before and after this // one are ILOG.J2CsMapping.Collections.Collections.Clear(subpermute); Permute(source.Substring(0, (i) - (0)) + source.Substring(i + IBM.ICU.Text.UTF16.GetCharCount(cp)), skipZeros, subpermute); // prefix this character to all of them String chStr = IBM.ICU.Text.UTF16.ValueOf(source, i); IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(subpermute.GetEnumerator()); while (it.HasNext()) { String piece = chStr + (String)it.Next(); // if (PROGRESS) System.out.println(" Piece: " + piece); ILOG.J2CsMapping.Collections.Generics.Collections.Add(output, piece); } } }
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))); } } } }
// we have a segment, in NFD. Find all the strings that are canonically // equivalent to it. private String[] GetEquivalents(String segment) { ILOG.J2CsMapping.Collections.ISet result = new HashedSet(); ILOG.J2CsMapping.Collections.ISet basic = GetEquivalents2(segment); ILOG.J2CsMapping.Collections.ISet permutations = new HashedSet(); // now get all the permutations // add only the ones that are canonically equivalent // TODO: optimize by not permuting any class zero. IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(basic.GetEnumerator()); while (it.HasNext()) { String item = (String)it.Next(); ILOG.J2CsMapping.Collections.Collections.Clear(permutations); Permute(item, SKIP_ZEROS, permutations); IIterator it2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(permutations.GetEnumerator()); while (it2.HasNext()) { String possible = (String)it2.Next(); /* * String attempt = Normalizer.normalize(possible, * Normalizer.DECOMP, 0); if (attempt.equals(segment)) { */ if (IBM.ICU.Text.Normalizer.Compare(possible, segment, 0) == 0) { if (PROGRESS) { System.Console.Out.WriteLine("Adding Permutation: " + IBM.ICU.Impl.Utility.Hex(possible)); } ILOG.J2CsMapping.Collections.Generics.Collections.Add(result, possible); } else { if (PROGRESS) { System.Console.Out.WriteLine("-Skipping Permutation: " + IBM.ICU.Impl.Utility.Hex(possible)); } } } } // convert into a String[] to clean up storage String[] finalResult = new String[result.Count]; ILOG.J2CsMapping.Collections.Generics.Collections.ToArray(result, finalResult); return(finalResult); }
/// <summary> /// Convenience method for callers using locales. This returns the standard /// ULocale list, built from the Set of visible ids. /// </summary> /// public ULocale[] GetAvailableULocales() { ILOG.J2CsMapping.Collections.ISet visIDs = GetVisibleIDs(); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(visIDs.GetEnumerator()); ULocale[] locales = new ULocale[visIDs.Count]; int n = 0; while (iter.HasNext()) { locales[n++] = new ULocale((String)iter.Next()); } return(locales); }
public static Object GetBest(ICollection c, IComparer comp, int direction) { IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); if (!it.HasNext()) { return(null); } Object bestSoFar = it.Next(); if (direction < 0) { while (it.HasNext()) { Object item = it.Next(); int compValue = comp.Compare(item, bestSoFar); if (compValue < 0) { bestSoFar = item; } } } else { while (it.HasNext()) { Object item_0 = it.Next(); int compValue_1 = comp.Compare(item_0, bestSoFar); if (compValue_1 > 0) { bestSoFar = item_0; } } } return(bestSoFar); }
/// <summary> /// Convenience method for callers using locales. This returns the standard /// Locale list, built from the Set of visible ids. /// </summary> /// public ILOG.J2CsMapping.Util.Locale[] GetAvailableLocales() { // TODO make this wrap getAvailableULocales later ILOG.J2CsMapping.Collections.ISet visIDs = GetVisibleIDs(); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(visIDs.GetEnumerator()); ILOG.J2CsMapping.Util.Locale[] locales = new ILOG.J2CsMapping.Util.Locale[visIDs.Count]; int n = 0; while (iter.HasNext()) { ILOG.J2CsMapping.Util.Locale loc = IBM.ICU.Impl.LocaleUtility.GetLocaleFromName((String)iter.Next()); locales[n++] = loc; } return(locales); }
static internal void TestIsRTL() { CultureInfo[] locales = System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures); ILOG.J2CsMapping.Collections.ISet s = new SortedSet(); for (int i = 0; i < locales.Length; ++i) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(s, ((IsRTL(locales[i])) ? "R " : "L ") + locales[i].DisplayName); } IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(s.GetEnumerator()); while (it.HasNext()) { System.Console.Out.WriteLine(it.Next()); } }
// ----------------------------------------------------------------------------- // // bofFixup. Fixup for state tables that include {bof} beginning of input // testing. // Do an swizzle similar to chaining, modifying the followPos set of // the bofNode to include the followPos nodes from other {bot} nodes // scattered through the tree. // // This function has much in common with calcChainedFollowPos(). // // ----------------------------------------------------------------------------- internal void BofFixup() { // // The parse tree looks like this ... // fTree root --. <cat> // / \ // <cat> <#end node> // / \ // <bofNode> rest // of tree // // We will be adding things to the followPos set of the <bofNode> // RBBINode bofNode = fRB.fTreeRoots[fRootIx].fLeftChild.fLeftChild; IBM.ICU.Impl.Assert.Assrt(bofNode.fType == IBM.ICU.Text.RBBINode.leafChar); IBM.ICU.Impl.Assert.Assrt(bofNode.fVal == 2); // Get all nodes that can be the start a match of the user-written rules // (excluding the fake bofNode) // We want the nodes that can start a match in the // part labeled "rest of tree" // ILOG.J2CsMapping.Collections.ISet matchStartNodes = fRB.fTreeRoots[fRootIx].fLeftChild.fRightChild.fFirstPosSet; IIterator startNodeIt = new ILOG.J2CsMapping.Collections.IteratorAdapter(matchStartNodes.GetEnumerator()); while (startNodeIt.HasNext()) { RBBINode startNode = (RBBINode)startNodeIt.Next(); if (startNode.fType != IBM.ICU.Text.RBBINode.leafChar) { continue; } if (startNode.fVal == bofNode.fVal) { // We found a leaf node corresponding to a {bof} that was // explicitly written into a rule. // Add everything from the followPos set of this node to the // followPos set of the fake bofNode at the start of the tree. // ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(startNode.fFollowPos, bofNode.fFollowPos); } } }
/// <summary> /// Override of superclass method. /// </summary> /// public virtual void UpdateVisibleIDs(IDictionary result) { ILOG.J2CsMapping.Collections.ISet cache = GetSupportedIDs(); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(cache.GetEnumerator()); while (iter.HasNext()) { String id = (String)iter.Next(); if (visible) { ILOG.J2CsMapping.Collections.Collections.Put(result, id, this); } else { ILOG.J2CsMapping.Collections.Collections.Remove(result, id); } } }
/// <summary> /// Resets this iterator to the start of the set. /// </summary> /// /// @stable ICU 2.0 public void Reset() { endRange = set.GetRangeCount() - 1; range = 0; endElement = -1; nextElement = 0; if (endRange >= 0) { LoadRange(range); } stringIterator = null; if (set.strings != null) { stringIterator = new ILOG.J2CsMapping.Collections.IteratorAdapter(set.strings.GetEnumerator()); if (!stringIterator.HasNext()) { stringIterator = null; } } }
public void Display() { IDictionary names = IBM.ICU.Charset.ICUServiceTestSample.HelloService.GetDisplayNames(IBM.ICU.Util.ULocale.US); System.Console.Out.WriteLine("displaying " + names.Count + " names."); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(names.GetEnumerator()); while (iter.HasNext()) { DictionaryEntry entry = (DictionaryEntry)iter.Next(); String displayName = (String)((DictionaryEntry)entry).Key; ICUServiceTestSample.HelloService service = IBM.ICU.Charset.ICUServiceTestSample.HelloService.Get((String)((DictionaryEntry)entry).Value); System.Console.Out.WriteLine(displayName + " says " + service.Hello()); try { ILOG.J2CsMapping.Threading.ThreadWrapper.Sleep(50); } catch (ThreadInterruptedException e) { } } System.Console.Out.WriteLine("----"); }
/// <summary> /// <p> /// Return a snapshot of the visible IDs for this service. This set will not /// change as Factories are added or removed, but the supported ids will, so /// there is no guarantee that all and only the ids in the returned set are /// visible and supported by the service in subsequent calls. /// </p> /// <p> /// matchID is passed to createKey to create a key. If the key is not null, /// it is used to filter out ids that don't have the key as a fallback. /// </summary> /// public ILOG.J2CsMapping.Collections.ISet GetVisibleIDs(String matchID) { ILOG.J2CsMapping.Collections.ISet result = new ILOG.J2CsMapping.Collections.ListSet(GetVisibleIDMap().Keys); ICUService.Key fallbackKey = CreateKey(matchID); if (fallbackKey != null) { ILOG.J2CsMapping.Collections.ISet temp = new HashedSet(result.Count); IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(result.GetEnumerator()); while (iter.HasNext()) { String id_0 = (String)iter.Next(); if (fallbackKey.IsFallbackOf(id_0)) { ILOG.J2CsMapping.Collections.Generics.Collections.Add(temp, id_0); } } result = temp; } return(result); }
internal String ShowDiff(ILOG.J2CsMapping.Collections.ISet a, ILOG.J2CsMapping.Collections.ISet b) { ILOG.J2CsMapping.Collections.ISet temp = new HashedSet(); ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(a, temp); temp.RemoveAll(b); if (temp.Count == 0) { return(""); } StringBuilder buffer = new StringBuilder(); IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(temp.GetEnumerator()); while (it.HasNext()) { if (buffer.Length != 0) { buffer.Append(", "); } buffer.Append(it.Next().ToString()); } return(buffer.ToString()); }
// ----------------------------------------------------------------------------- // // calcFollowPos. Impossible to explain succinctly. See Aho, section 3.9 // // ----------------------------------------------------------------------------- internal void CalcFollowPos(RBBINode n) { if (n == null || n.fType == IBM.ICU.Text.RBBINode.leafChar || n.fType == IBM.ICU.Text.RBBINode.endMark) { return; } CalcFollowPos(n.fLeftChild); CalcFollowPos(n.fRightChild); // Aho rule #1 if (n.fType == IBM.ICU.Text.RBBINode.opCat) { RBBINode i; // is 'i' in Aho's description ILOG.J2CsMapping.Collections.ISet LastPosOfLeftChild = n.fLeftChild.fLastPosSet; IIterator ix = new ILOG.J2CsMapping.Collections.IteratorAdapter(LastPosOfLeftChild.GetEnumerator()); while (ix.HasNext()) { i = (RBBINode)ix.Next(); ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(n.fRightChild.fFirstPosSet, i.fFollowPos); } } // Aho rule #2 if (n.fType == IBM.ICU.Text.RBBINode.opStar || n.fType == IBM.ICU.Text.RBBINode.opPlus) { RBBINode i_0; // again, n and i are the names from Aho's description. IIterator ix_1 = new ILOG.J2CsMapping.Collections.IteratorAdapter(n.fLastPosSet.GetEnumerator()); while (ix_1.HasNext()) { i_0 = (RBBINode)ix_1.Next(); ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(n.fFirstPosSet, i_0.fFollowPos); } } }
/// <summary> /// Add a listener to be notified when notifyChanged is called. The listener /// must not be null. AcceptsListener must return true for the listener. /// Attempts to concurrently register the identical listener more than once /// will be silently ignored. /// </summary> /// public void AddListener(IEventListener l) { if (l == null) { throw new NullReferenceException(); } if (AcceptsListener(l)) { lock (notifyLock) { if (listeners == null) { listeners = new ArrayList(5); } else { // identity equality check IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(listeners.GetEnumerator()); while (iter.HasNext()) { if (iter.Next() == (Object)l) { return; } } } ILOG.J2CsMapping.Collections.Generics.Collections.Add(listeners, l); } } else { throw new InvalidOperationException( "Listener invalid for this notifier."); } }
public static String Show(IDictionary m) { StringBuilder buffer = new StringBuilder(); for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(m.Keys).GetEnumerator()); it.HasNext();) { Object key = it.Next(); buffer.Append(key + "=>" + ILOG.J2CsMapping.Collections.Collections.Get(m, key) + "\r\n"); } return(buffer.ToString()); }
/// <summary> /// Create the content key corresponding to the timeSlot. This first checks if /// the content key exists. For an existing content key, this returns the /// content key name directly. If the key does not exist, this creates one and /// encrypts it using the corresponding E-KEYs. The encrypted content keys are /// passed to the onEncryptedKeys callback. /// </summary> /// /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param> /// <param name="onEncryptedKeys_1">content key Data packets. If onEncryptedKeys is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param> /// <param name="onError_2">better error handling the callback should catch and properly handle any exceptions.</param> /// <returns>The content key name.</returns> public Name createContentKey(double timeSlot_0, Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2) { double hourSlot = getRoundedTimeSlot(timeSlot_0); // Create the content key name. Name contentKeyName = new Name(namespace_); contentKeyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY); contentKeyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(hourSlot)); Blob contentKeyBits; // Check if we have created the content key before. if (database_.hasContentKey(timeSlot_0)) // We have created the content key. Return its name directly. return contentKeyName; // We haven't created the content key. Create one and add it into the database. AesKeyParams aesParams = new AesKeyParams(128); contentKeyBits = net.named_data.jndn.encrypt.algo.AesAlgorithm.generateKey(aesParams).getKeyBits(); database_.addContentKey(timeSlot_0, contentKeyBits); // Now we need to retrieve the E-KEYs for content key encryption. double timeCount = Math.Round(timeSlot_0,MidpointRounding.AwayFromZero); ILOG.J2CsMapping.Collections.Collections.Put(keyRequests_,timeCount,new Producer.KeyRequest (eKeyInfo_.Count)); Producer.KeyRequest keyRequest = (Producer.KeyRequest ) ILOG.J2CsMapping.Collections.Collections.Get(keyRequests_,timeCount); // Check if the current E-KEYs can cover the content key. Exclude timeRange = new Exclude(); excludeAfter(timeRange, new Name.Component(net.named_data.jndn.encrypt.Schedule.toIsoString(timeSlot_0))); new ILOG.J2CsMapping.Collections.IteratorAdapter(eKeyInfo_.GetEnumerator()); for (IIterator i = new ILOG.J2CsMapping.Collections.IteratorAdapter(eKeyInfo_.GetEnumerator()); i.HasNext();) { // For each current E-KEY. DictionaryEntry entry = (DictionaryEntry) i.Next(); Producer.KeyInfo keyInfo = (Producer.KeyInfo ) ((DictionaryEntry) entry).Value; if (timeSlot_0 < keyInfo.beginTimeSlot || timeSlot_0 >= keyInfo.endTimeSlot) { // The current E-KEY cannot cover the content key, so retrieve one. ILOG.J2CsMapping.Collections.Collections.Put(keyRequest.repeatAttempts,((DictionaryEntry) entry).Key,0); sendKeyInterest( new Interest((Name) ((DictionaryEntry) entry).Key).setExclude( timeRange).setChildSelector(1), timeSlot_0, onEncryptedKeys_1, onError_2); } else { // The current E-KEY can cover the content key. // Encrypt the content key directly. Name eKeyName = new Name((Name) ((DictionaryEntry) entry).Key); eKeyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(keyInfo.beginTimeSlot)); eKeyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(keyInfo.endTimeSlot)); encryptContentKey(keyInfo.keyBits, eKeyName, timeSlot_0, onEncryptedKeys_1, onError_2); } } return contentKeyName; }
public String Replace(String source) { String oldSource; do { oldSource = source; for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(m.Keys).GetEnumerator()); it.HasNext();) { String variable = (String)it.Next(); String value_ren = (String)ILOG.J2CsMapping.Collections.Collections.Get(m, variable); source = ReplaceAll(source, variable, value_ren); } } while (!source.Equals(oldSource)); return(source); }
private ILOG.J2CsMapping.Collections.ISet GetEquivalents2(String segment) { ILOG.J2CsMapping.Collections.ISet result = new HashedSet(); if (PROGRESS) { System.Console.Out.WriteLine("Adding: " + IBM.ICU.Impl.Utility.Hex(segment)); } ILOG.J2CsMapping.Collections.Generics.Collections.Add(result, segment); StringBuilder workingBuffer = new StringBuilder(); // cycle through all the characters int cp = 0; int[] range = new int[2]; for (int i = 0; i < segment.Length; i += IBM.ICU.Text.UTF16.GetCharCount(cp)) { // see if any character is at the start of some decomposition cp = IBM.ICU.Text.UTF16.CharAt(segment, i); USerializedSet starts = new USerializedSet(); if (!IBM.ICU.Impl.NormalizerImpl.GetCanonStartSet(cp, starts)) { continue; } int j = 0; // if so, see which decompositions match int rangeCount = starts.CountRanges(); for (j = 0; j < rangeCount; ++j) { starts.GetRange(j, range); int end = range[1]; for (int cp2 = range[0]; cp2 <= end; ++cp2) { ILOG.J2CsMapping.Collections.ISet remainder = Extract(cp2, segment, i, workingBuffer); if (remainder == null) { continue; } // there were some matches, so add all the possibilities to // the set. String prefix = segment.Substring(0, (i) - (0)); prefix += IBM.ICU.Text.UTF16.ValueOf(cp2); // int el = -1; IIterator iter = new ILOG.J2CsMapping.Collections.IteratorAdapter(remainder.GetEnumerator()); while (iter.HasNext()) { String item = (String)iter.Next(); String toAdd = prefix; toAdd += item; ILOG.J2CsMapping.Collections.Generics.Collections.Add(result, toAdd); // if (PROGRESS) printf("Adding: %s\n", // UToS(Tr(*toAdd))); } } } } return(result); /* * Set result = new HashSet(); if (PROGRESS) * System.out.println("Adding: " + NAME.transliterate(segment)); * result.add(segment); StringBuffer workingBuffer = new StringBuffer(); * * // cycle through all the characters int cp; * * for (int i = 0; i < segment.length(); i += UTF16.getCharCount(cp)) { * // see if any character is at the start of some decomposition cp = * UTF16.charAt(segment, i); NormalizerImpl.getCanonStartSet(c,fillSet) * UnicodeSet starts = AT_START.get(cp); if (starts == null) continue; * UnicodeSetIterator usi = new UnicodeSetIterator(starts); // if so, * see which decompositions match while (usi.next()) { int cp2 = * usi.codepoint; // we know that there are no strings in it // so we * don't have to check CharacterIterator.IS_STRING Set remainder = * extract(cp2, segment, i, workingBuffer); if (remainder == null) * continue; * * // there were some matches, so add all the possibilities to the set. * String prefix = segment.substring(0, i) + UTF16.valueOf(cp2); * Iterator it = remainder.iterator(); while (it.hasNext()) { String * item = (String) it.next(); if (PROGRESS) * System.out.println("Adding: " + NAME.transliterate(prefix + item)); * result.add(prefix + item); } } } return result; */ }
public static UnicodeSet GetSet(IDictionary m, Object value_ren) { UnicodeSet result = new UnicodeSet(); for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(new ILOG.J2CsMapping.Collections.ListSet(m.Keys).GetEnumerator()); it.HasNext();) { Object key = it.Next(); Object val = ILOG.J2CsMapping.Collections.Collections.Get(m, key); if (!val.Equals(value_ren)) { continue; } result.Add(((Int32)key)); } return(result); }
public BNF Complete() { // check that the rules match the variables, except for $root in rules ILOG.J2CsMapping.Collections.ISet ruleSet = new ILOG.J2CsMapping.Collections.ListSet(map.Keys); // add also ILOG.J2CsMapping.Collections.Generics.Collections.Add(variables, "$root"); ILOG.J2CsMapping.Collections.Generics.Collections.AddAll(t.GetLookedUpItems(), variables); if (!ruleSet.Equals(variables)) { String msg = ShowDiff(variables, ruleSet); if (msg.Length != 0) { msg = "Error: Missing definitions for: " + msg; } String temp = ShowDiff(ruleSet, variables); if (temp.Length != 0) { temp = "Warning: Defined but not used: " + temp; } if (msg.Length == 0) { msg = temp; } else if (temp.Length != 0) { msg = msg + "; " + temp; } Error(msg); } if (!ruleSet.Equals(variables)) { String msg_0 = ShowDiff(variables, ruleSet); if (msg_0.Length != 0) { msg_0 = "Missing definitions for: " + msg_0; } String temp_1 = ShowDiff(ruleSet, variables); if (temp_1.Length != 0) { temp_1 = "Defined but not used: " + temp_1; } if (msg_0.Length == 0) { msg_0 = temp_1; } else if (temp_1.Length != 0) { msg_0 = msg_0 + "; " + temp_1; } Error(msg_0); } // replace variables by definitions IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(ruleSet.GetEnumerator()); while (it.HasNext()) { String key = (String)it.Next(); Pick expression = (Pick)ILOG.J2CsMapping.Collections.Collections.Get(map, key); IIterator it2 = new ILOG.J2CsMapping.Collections.IteratorAdapter(ruleSet.GetEnumerator()); if (false && key.Equals("$crlf")) { System.Console.Out.WriteLine("debug"); } while (it2.HasNext()) { Object key2 = it2.Next(); if (key.Equals(key2)) { continue; } Pick expression2 = (Pick)ILOG.J2CsMapping.Collections.Collections.Get(map, key2); expression2.Replace(key, expression); } } pick = (Pick)ILOG.J2CsMapping.Collections.Collections.Get(map, "$root"); target = IBM.ICU.Charset.Pick.Target.Make(pick, random, quoter); // TODO remove temp collections return(this); }
/// <exception cref="IOException"></exception> public void WriteCollection(ICollection c, IDictionary object_index) { WriteUInt(c.Count); int i = 0; ILOG.J2CsMapping.Collections.Collections.Put(object_index, null, ((int)(i++))); for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); it.HasNext();) { Object s = it.Next(); dataOutput.WriteObject(s); if (object_index != null) { ILOG.J2CsMapping.Collections.Collections.Put(object_index, s, ((int)(i++))); } } }
public static String Show(ICollection c) { StringBuilder buffer = new StringBuilder(); for (IIterator it = new ILOG.J2CsMapping.Collections.IteratorAdapter(c.GetEnumerator()); it.HasNext();) { buffer.Append(it.Next() + "\r\n"); } return(buffer.ToString()); }
/// <summary> /// Create a group key for the interval into which timeSlot falls. This creates /// a group key if it doesn't exist, and encrypts the key using the public key /// of each eligible member. /// </summary> /// /// <param name="timeSlot">The time slot to cover as milliseconds since Jan 1, 1970 UTC.</param> /// <returns>A List of Data packets where the first is the E-KEY data packet /// with the group's public key and the rest are the D-KEY data packets with /// the group's private key encrypted with the public key of each eligible /// member. (Use List without generics so it works with older Java compilers.)</returns> /// <exception cref="GroupManagerDb.Error">for a database error.</exception> /// <exception cref="System.Security.SecurityException">for an error using the security KeyChain.</exception> public IList getGroupKey(double timeSlot) { IDictionary memberKeys = new SortedList(); IList result = new ArrayList(); // Get the time interval. Interval finalInterval = calculateInterval(timeSlot, memberKeys); if (finalInterval.isValid() == false) return result; String startTimeStamp = net.named_data.jndn.encrypt.Schedule.toIsoString(finalInterval .getStartTime()); String endTimeStamp = net.named_data.jndn.encrypt.Schedule.toIsoString(finalInterval.getEndTime()); // Generate the private and public keys. Blob[] privateKeyBlob = { null }; Blob[] publicKeyBlob = { null }; generateKeyPair(privateKeyBlob, publicKeyBlob); // Add the first element to the result. // The E-KEY (public key) data packet name convention is: // /<data_type>/E-KEY/[start-ts]/[end-ts] Data data = createEKeyData(startTimeStamp, endTimeStamp, publicKeyBlob[0]); ILOG.J2CsMapping.Collections.Collections.Add(result,data); // Encrypt the private key with the public key from each member's certificate. for (IIterator i = new ILOG.J2CsMapping.Collections.IteratorAdapter(memberKeys.GetEnumerator()); i.HasNext();) { DictionaryEntry entry = (DictionaryEntry) i.Next(); Name keyName = (Name) ((DictionaryEntry) entry).Key; Blob certificateKey = (Blob) ((DictionaryEntry) entry).Value; // Generate the name of the packet. // The D-KEY (private key) data packet name convention is: // /<data_type>/D-KEY/[start-ts]/[end-ts]/[member-name] data = createDKeyData(startTimeStamp, endTimeStamp, keyName, privateKeyBlob[0], certificateKey); ILOG.J2CsMapping.Collections.Collections.Add(result,data); } return result; }