コード例 #1
0
    @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);
    }
コード例 #2
0
    @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);
    }
コード例 #3
0
 @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);
 }
 @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;
 }