Example #1
0
        /// <summary>
        /// Reverses the specified OrderedMap, if <code>preserveKeys</code> is true, the original keys will be used.
        /// </summary>
        /// <param name="input">The OrderedMap that will be reversed.</param>
        /// <param name="preserveKeys">The boolean value that indicates whether to preserve the original keys or auto-generate new keys.</param>
        /// <returns>Returns a new reversed OrderedMap.</returns>
        public static OrderedMap Reverse(OrderedMap input, bool preserveKeys)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();
                for (int index = input.Count - 1; index >= 0; index--)
                {
                    System.Collections.DictionaryEntry entry = input.GetEntryAt(index);
                    if (preserveKeys)
                        newOrderedMap[entry.Key] = entry.Value;
                    else
                    {
                        if (IsKeyInteger(entry.Key.ToString()))
                            newOrderedMap[null] = entry.Value;
                        else
                            newOrderedMap[entry.Key] = entry.Value;
                    }
                }
            }
            return newOrderedMap;
        }
Example #2
0
        /// <summary>
        /// Returns a new OrderedMap that represents a slice of the specified OrderedMap.
        /// </summary>
        /// <param name="input">The OrderedMap to extract the slice from.</param>
        /// <param name="offset">The starting position of the slice.</param>
        /// <param name="length">The length of the slice.</param>
        /// <returns>Returns a new OrderedMap that represents a slice of the specified OrderedMap.</returns>
        public static OrderedMap Slice(OrderedMap input, int offset, int length)
        {
            OrderedMap newOrderedMap = null;

            if (input != null && input.Count > 0)
            {
                newOrderedMap = new OrderedMap();

                int theOffset = offset, theLength = length;
                _GetAbsPositions(ref theOffset, ref theLength, input.Count);
                for (int index = theOffset; index < theOffset + theLength; index++)
                {
                    System.Collections.DictionaryEntry entry = input.GetEntryAt(index);

                    if (OrderedMap.IsKeyInteger((string) entry.Key))
                        newOrderedMap[null] = entry.Value;
                    else
                        newOrderedMap[entry.Key] = entry.Value;
                }
            }
            return newOrderedMap;
        }
Example #3
0
 /// <summary>
 /// Computes the intersection of two OrderedMaps with extra key checking.
 /// That is, elements and keys of the first OrderedMap present in the second OrderedMap.
 /// </summary>
 /// <param name="input1">The OrderedMap that contains the entries to be searched.</param>
 /// <param name="input2">The OrderedMap where the entries of the first element will be searched.</param>
 /// <returns>Returns a new OrderedMap that contains the entries of the first OrderedMap present in the second OrderedMap.</returns>
 public static OrderedMap IntersectionWithKey(OrderedMap input1, OrderedMap input2)
 {
     OrderedMap newOrderedMap = null;
     for (int index = 0; index < input1.Count; index++)
     {
         System.Collections.DictionaryEntry entry = input1.GetEntryAt(index);
         if (input2.SearchStringRepresentation(entry) != -1)
         {
             if (newOrderedMap == null) newOrderedMap = new OrderedMap();
             newOrderedMap[entry.Key] = entry.Value;
         }
     }
     return newOrderedMap;
 }