public override void ProcessList(IOrderedCompositeSpec spec, JArray inputList, WalkedPath walkedPath, JObject output, JObject context)
        {
            int?originalSize = walkedPath.LastElement().OrigSize;

            foreach (var kv in spec.GetLiteralChildren())
            {
                JToken subInputOptional = null;
                // If the data is an Array, but the spec keys are Non-Integer Strings,
                //  we are annoyed, but we don't stop the whole transform.
                // Just this part of the Transform won't work.
                if (Int32.TryParse(kv.Key, out int keyInt) &&
                    keyInt >= 0 && keyInt < inputList.Count)
                {
                    // if the input in not available in the list use null or else get value,
                    // then lookup and place a default value as defined in spec there
                    JToken subInput = inputList[keyInt];
                    if ((subInput != null && subInput.Type != JTokenType.Null) |
                        !originalSize.HasValue || keyInt < originalSize.Value)
                    {
                        subInputOptional = subInput;
                    }
                }
                kv.Value.Apply(kv.Key, subInputOptional, walkedPath, output, context);
            }
        }
 public override void ProcessScalar(IOrderedCompositeSpec spec, string scalarInput, WalkedPath walkedPath, JObject output, JObject context)
 {
     if (spec.GetLiteralChildren().TryGetValue(scalarInput, out var literalChild))
     {
         literalChild.Apply(scalarInput, null, walkedPath, output, context);
     }
 }
        public override void ProcessList(IOrderedCompositeSpec spec, JArray inputList, WalkedPath walkedPath, JObject output, JObject context)
        {
            int?originalSize = walkedPath.LastElement().OrigSize;

            foreach (var kv in spec.GetLiteralChildren())
            {
                // If the data is an Array, but the spec keys are Non-Integer Strings,
                //  we are annoyed, but we don't stop the whole transform.
                // Just this part of the Transform won't work.
                if (Int32.TryParse(kv.Key, out int keyInt) &&
                    // Do not work if the index is outside of the input list
                    keyInt < inputList.Count)
                {
                    // XXX: does this make sense? can you have a literal null in JArray?
                    JToken subInput = inputList[keyInt];
                    JToken subInputOptional;
                    if (subInput == null && originalSize.HasValue && keyInt >= originalSize.Value)
                    {
                        subInputOptional = null;
                    }
                    else
                    {
                        subInputOptional = subInput;
                    }

                    kv.Value.Apply(kv.Key, subInputOptional, walkedPath, output, context);
                }
            }
        }
 public override void ProcessMap(IOrderedCompositeSpec spec, JObject inputMap, WalkedPath walkedPath, JObject output, JObject context)
 {
     // Iterate over the whole entrySet rather than the keyset with follow on gets of the values
     foreach (var inputEntry in inputMap)
     {
         ApplyKeyToLiteralAndComputed(spec, inputEntry.Key, inputEntry.Value, walkedPath, output, context);
     }
 }
 public override void ProcessMap(IOrderedCompositeSpec spec, JObject inputMap, WalkedPath walkedPath, JObject output, JObject context)
 {
     foreach (var kv in spec.GetLiteralChildren())
     {
         // if the input in not available in the map us null or else get value,
         // then lookup and place a defined value from spec there
         inputMap.TryGetValue(kv.Key, out var input);
         kv.Value.Apply(kv.Key, input, walkedPath, output, context);
     }
 }
 /**
  * The performance assumption built into this code is that the literal values in the spec, are generally smaller
  *  than the number of potential keys to check in the input.
  *
  *  More specifically, the assumption here is that the set of literalChildren is smaller than the input "keyset".
  */
 public override void ProcessMap(IOrderedCompositeSpec spec, JObject inputMap, WalkedPath walkedPath, JObject output, JObject context)
 {
     foreach (var kv in spec.GetLiteralChildren())
     {
         // Do not work if the value is missing in the input map
         if (inputMap.TryGetValue(kv.Key, out var inputValue))
         {
             kv.Value.Apply(kv.Key, inputValue, walkedPath, output, context);
         }
     }
 }
 public void Process(IOrderedCompositeSpec spec, JToken input, WalkedPath walkedPath, JObject output, JObject context)
 {
     if (input is JObject map)
     {
         ProcessMap(spec, map, walkedPath, output, context);
     }
     else if (input is JArray list)
     {
         ProcessList(spec, list, walkedPath, output, context);
     }
     else if (input != null && input.Type != JTokenType.Null)
     {
         // if not a map or list, must be a scalar
         ProcessScalar(spec, ToString(input), walkedPath, output, context);
     }
 }
        public override void ProcessList(IOrderedCompositeSpec spec, JArray inputList, WalkedPath walkedPath, JObject output, JObject context)
        {
            int?originalSize = walkedPath.LastElement().OrigSize;

            for (int index = 0; index < inputList.Count; index++)
            {
                JToken subInput  = inputList[index];
                string subKeyStr = index.ToString();
                JToken subInputOptional;
                if (subInput == null && originalSize.HasValue && index >= originalSize.Value)
                {
                    subInputOptional = null;
                }
                else
                {
                    subInputOptional = subInput;
                }

                ApplyKeyToComputed(spec.GetComputedChildren(), walkedPath, output, subKeyStr, subInputOptional, context);
            }
        }
 public abstract void ProcessScalar(IOrderedCompositeSpec spec, string scalarInput, WalkedPath walkedPath, JObject output, JObject context);
 public abstract void ProcessList(IOrderedCompositeSpec spec, JArray inputList, WalkedPath walkedPath, JObject output, JObject context);
 public abstract void ProcessMap(IOrderedCompositeSpec spec, JObject inputMap, WalkedPath walkedPath, JObject output, JObject context);
 public override void ProcessScalar(IOrderedCompositeSpec spec, string scalarInput, WalkedPath walkedPath, JObject output, JObject context)
 {
     ExecutionStrategy.AllLiterals.ProcessScalar(spec, scalarInput, walkedPath, output, context);
     ExecutionStrategy.Computed.ProcessScalar(spec, scalarInput, walkedPath, output, context);
 }
 public override void ProcessList(IOrderedCompositeSpec spec, JArray inputList, WalkedPath walkedPath, JObject output, JObject context)
 {
     ExecutionStrategy.AllLiterals.ProcessList(spec, inputList, walkedPath, output, context);
     ExecutionStrategy.Computed.ProcessList(spec, inputList, walkedPath, output, context);
 }
 public override void ProcessMap(IOrderedCompositeSpec spec, JObject inputMap, WalkedPath walkedPath, JObject output, JObject context)
 {
     ExecutionStrategy.AvailableLiterals.ProcessMap(spec, inputMap, walkedPath, output, context);
     ExecutionStrategy.Computed.ProcessMap(spec, inputMap, walkedPath, output, context);
 }
 public override void ProcessScalar(IOrderedCompositeSpec spec, string scalarInput, WalkedPath walkedPath, JObject output, JObject context)
 {
     ApplyKeyToLiteralAndComputed(spec, scalarInput, null, walkedPath, output, context);
 }