public static void fromFudgeMsg(
     FudgeDeserializer deserializer, FudgeMsg msg, FXOptionSecurity object) {
   FinancialSecurityFudgeBuilder.fromFudgeMsg(deserializer, msg, object);
   object.setPutCurrency(msg.getValue(Currency.class, PUT_CURRENCY_FIELD_NAME));
   object.setCallCurrency(msg.getValue(Currency.class, CALL_CURRENCY_FIELD_NAME));
   object.setPutAmount(msg.getDouble(PUT_AMOUNT_FIELD_NAME));
   object.setCallAmount(msg.getDouble(CALL_AMOUNT_FIELD_NAME));
   object.setExpiry(
       ExpiryFudgeBuilder.fromFudgeMsg(deserializer, msg.getMessage(EXPIRY_FIELD_NAME)));
   object.setSettlementDate(
       ZonedDateTimeFudgeBuilder.fromFudgeMsg(
           deserializer, msg.getMessage(SETTLEMENT_DATE_FIELD_NAME)));
   object.setLongShort(LongShort.ofLong(msg.getBoolean(IS_LONG_FIELD_NAME)));
 }
 public static void fromFudgeMsg(
     FudgeDeserializer deserializer, FudgeMsg msg, EnergyFutureSecurity object) {
   CommodityFutureSecurityFudgeBuilder.fromFudgeMsg(deserializer, msg, object);
   object.setUnderlyingId(
       ExternalIdFudgeBuilder.fromFudgeMsg(
           deserializer, msg.getMessage(UNDERLYING_IDENTIFIER_FIELD_NAME)));
 }
 protected Map<ValueSpecification, Collection<ValueSpecification>> decodeMarketDataAliases(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg msgRequirements = msg.getMessage(MARKET_DATA_REQUIREMENTS_FIELD);
   final FudgeMsg msgAliases = msg.getMessage(MARKET_DATA_ALIASES_FIELD);
   if ((msgRequirements == null) || (msgAliases == null) || msgRequirements.isEmpty()) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Collection<ValueSpecification>> result =
       Maps.newHashMapWithExpectedSize(msgRequirements.getNumFields());
   final Iterator<FudgeField> itrRequirements = msgRequirements.iterator();
   final Iterator<FudgeField> itrAliases = msgAliases.iterator();
   while (itrRequirements.hasNext() && itrAliases.hasNext()) {
     final FudgeField requirement = itrRequirements.next();
     final FudgeField alias = itrAliases.next();
     final ValueSpecification spec =
         deserializer.fieldValueToObject(ValueSpecification.class, requirement);
     if (alias.getValue() == IndicatorType.INSTANCE) {
       result.put(spec, Collections.singleton(spec));
     } else {
       final FudgeMsg msgAlias = (FudgeMsg) alias.getValue();
       final String clazz = msgAlias.getString(0);
       if ("list".equals(clazz)) {
         final Collection<ValueSpecification> aliases =
             new ArrayList<ValueSpecification>(msgAlias.getNumFields() - 1);
         for (FudgeField aliasField : msgAlias) {
           if (aliasField.getValue() == IndicatorType.INSTANCE) {
             aliases.add(spec);
           } else if (aliasField.getValue() instanceof FudgeMsg) {
             aliases.add(deserializer.fieldValueToObject(ValueSpecification.class, aliasField));
           }
         }
         result.put(spec, aliases);
       } else {
         result.put(
             spec,
             Collections.singleton(
                 deserializer.fieldValueToObject(ValueSpecification.class, alias)));
       }
     }
   }
   return result;
 }
    @SuppressWarnings("synthetic-access")
    @Override
    public CurrencyLabelledMatrix1D buildObject(
        final FudgeDeserializer deserializer, final FudgeMsg message) {
      final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);

      final Queue<String> labelTypes = new LinkedList<String>();
      final Queue<FudgeField> labelValues = new LinkedList<FudgeField>();

      final List<Currency> keys = new LinkedList<Currency>();
      final List<Object> labels = new LinkedList<Object>();
      final List<Double> values = new LinkedList<Double>();

      for (final FudgeField field : msg) {
        switch (field.getOrdinal()) {
          case LABEL_TYPE_ORDINAL:
            labelTypes.add((String) field.getValue());
            break;
          case KEY_ORDINAL:
            keys.add(Currency.of((String) field.getValue()));
            break;
          case LABEL_ORDINAL:
            labelValues.add(field);
            break;
          case VALUE_ORDINAL:
            values.add((Double) field.getValue());
            break;
        }

        if (!labelTypes.isEmpty() && !labelValues.isEmpty()) {
          // Have a type and a value, which can be consumed
          final String labelType = labelTypes.remove();
          Class<?> labelClass;
          try {
            labelClass = LabelledMatrix1DBuilder.getLabelClass(labelType, _loadedClasses);
          } catch (final ClassNotFoundException ex) {
            throw new OpenGammaRuntimeException(
                "Could not deserialize label of type " + labelType, ex);
          }
          final FudgeField labelValue = labelValues.remove();
          final Object label = deserializer.fieldValueToObject(labelClass, labelValue);
          //          labels.add(Currency.of((String) label));
          labels.add(label);
        }
      }

      final int matrixSize = keys.size();
      final Currency[] keysArray = new Currency[matrixSize];
      keys.toArray(keysArray);
      final Object[] labelsArray = new Object[matrixSize];
      labels.toArray(labelsArray);
      final double[] valuesArray = Doubles.toArray(values);
      return new CurrencyLabelledMatrix1D(keysArray, labelsArray, valuesArray);
    }
 protected Set<ComputationTargetSpecification> decodeComputationTargets(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg submsg = msg.getMessage(COMPUTATION_TARGETS_FIELD);
   if (submsg == null) {
     return Collections.emptySet();
   }
   final Set<ComputationTargetSpecification> result =
       Sets.newHashSetWithExpectedSize(submsg.getNumFields());
   for (final FudgeField field : submsg) {
     result.add(
         deserializer
             .fieldValueToObject(ComputationTargetReference.class, field)
             .getSpecification());
   }
   return result;
 }
    @Override
    public LocalDateLabelledMatrix1D buildObject(
        final FudgeDeserializer deserializer, final FudgeMsg message) {
      final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);

      final Queue<String> labelTypes = new LinkedList<String>();
      final Queue<FudgeField> labelValues = new LinkedList<FudgeField>();

      final List<LocalDate> keys = new LinkedList<LocalDate>();
      final List<Object> labels = new LinkedList<Object>();
      final List<Double> values = new LinkedList<Double>();

      for (final FudgeField field : msg) {
        switch (field.getOrdinal()) {
          case LABEL_TYPE_ORDINAL:
            labelTypes.add((String) field.getValue());
            break;
          case KEY_ORDINAL:
            keys.add(((FudgeDate) field.getValue()).toLocalDate());
            break;
          case LABEL_ORDINAL:
            labelValues.add(field);
            break;
          case VALUE_ORDINAL:
            values.add((Double) field.getValue());
            break;
        }

        if (!labelTypes.isEmpty() && !labelValues.isEmpty()) {
          // Have a type and a value, which can be consumed
          final String labelType = labelTypes.remove();
          Class<?> labelClass = getClass(labelType);
          final FudgeField labelValue = labelValues.remove();
          final Object label = deserializer.fieldValueToObject(labelClass, labelValue);
          labels.add(label);
        }
      }

      final int matrixSize = keys.size();
      final LocalDate[] keysArray = new LocalDate[matrixSize];
      keys.toArray(keysArray);
      final Object[] labelsArray = new Object[matrixSize];
      labels.toArray(labelsArray);
      final double[] valuesArray = Doubles.toArray(values);
      return new LocalDateLabelledMatrix1D(keysArray, labelsArray, valuesArray);
    }
 @Override
 public StringLabelledMatrix1D buildObject(
     final FudgeDeserializer deserializer, final FudgeMsg message) {
   final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);
   final List<String> keys = new LinkedList<String>();
   final List<Double> values = new LinkedList<Double>();
   for (final FudgeField field : msg) {
     switch (field.getOrdinal()) {
       case KEY_ORDINAL:
         keys.add((String) field.getValue());
         break;
       case VALUE_ORDINAL:
         values.add((Double) field.getValue());
         break;
     }
   }
   String[] keysArray = keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
   final double[] valuesArray = Doubles.toArray(values);
   return new StringLabelledMatrix1D(keysArray, valuesArray);
 }
 @Override
 public FixedIncomeStripWithSecurity buildObject(
     FudgeDeserializationContext context, FudgeMsg message) {
   StripInstrumentType type =
       context.fieldValueToObject(StripInstrumentType.class, message.getByName("type"));
   Tenor tenor = context.fieldValueToObject(Tenor.class, message.getByName("tenor"));
   Tenor resolvedTenor =
       context.fieldValueToObject(Tenor.class, message.getByName("resolvedTenor"));
   ZonedDateTimeBuilder zonedDateTimeBuilder = new ZonedDateTimeBuilder();
   ZonedDateTime maturity =
       zonedDateTimeBuilder.buildObject(context, message.getMessage("maturity"));
   Identifier identifier =
       context.fieldValueToObject(Identifier.class, message.getByName("identifier"));
   Security security = (Security) context.fieldValueToObject(message.getByName("security"));
   if (type == StripInstrumentType.FUTURE) {
     int numFutures = message.getInt("numFutures");
     return new FixedIncomeStripWithSecurity(
         type, tenor, resolvedTenor, numFutures, maturity, identifier, security);
   } else {
     return new FixedIncomeStripWithSecurity(
         type, tenor, resolvedTenor, maturity, identifier, security);
   }
 }
 @SuppressWarnings("unchecked")
 protected Map<ValueSpecification, Set<ValueRequirement>> decodeTerminalOutputSpecifications(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg submsg = msg.getMessage(TERMINAL_OUTPUT_SPECIFICATIONS_FIELD);
   if (submsg == null) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Set<ValueRequirement>> result =
       Maps.newHashMapWithExpectedSize(submsg.getNumFields() / 2);
   LinkedList<Object> overflow = null;
   ValueSpecification key = null;
   Set<ValueRequirement> value = null;
   for (final FudgeField field : submsg) {
     if (MAP_KEY.equals(field.getOrdinal())) {
       final ValueSpecification fieldValue =
           deserializer.fieldValueToObject(ValueSpecification.class, field);
       if (key == null) {
         if (value == null) {
           key = fieldValue;
         } else {
           result.put(fieldValue, value);
           if (overflow != null) {
             value = overflow.isEmpty() ? null : (Set<ValueRequirement>) overflow.removeFirst();
           } else {
             value = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     } else if (MAP_VALUE.equals(field.getOrdinal())) {
       final FudgeMsg submsg2 = (FudgeMsg) field.getValue();
       final Set<ValueRequirement> fieldValue =
           Sets.newHashSetWithExpectedSize(submsg2.getNumFields());
       for (final FudgeField field2 : submsg2) {
         fieldValue.add(deserializer.fieldValueToObject(ValueRequirement.class, field2));
       }
       if (value == null) {
         if (key == null) {
           value = fieldValue;
         } else {
           result.put(key, fieldValue);
           if (overflow != null) {
             key = overflow.isEmpty() ? null : (ValueSpecification) overflow.removeFirst();
           } else {
             key = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     }
   }
   return result;
 }