<commit_before>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.livedata;

import java.io.Serializable;

import org.fudgemsg.FudgeFieldContainer;


/**
 * A simple JavaBean-based implementation of {@link LiveDataValueUpdate}.
 *
 * @author kirk
 */
public class LiveDataValueUpdateBean implements LiveDataValueUpdate,
    Serializable {
  private final long _relevantTimestamp;
  private final LiveDataSpecification _specification;
  private final FudgeFieldContainer _fieldContainer;
  
  public LiveDataValueUpdateBean(long relevantTimestamp, LiveDataSpecification specification, FudgeFieldContainer fieldContainer) {
    // TODO kirk 2009-09-29 -- Check Inputs.
    _relevantTimestamp = relevantTimestamp;
    _specification = specification;
    _fieldContainer = fieldContainer;
  }

  @Override
  public FudgeFieldContainer getFields() {
    return _fieldContainer;
  }

  @Override
  public long getRelevantTimestamp() {
    return _relevantTimestamp;
  }

  @Override
  public LiveDataSpecification getSpecification() {
    return _specification;
  }

}<commit_msg>Added Fudge serialization methods.<commit_after>/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.livedata;

import java.io.Serializable;

import org.fudgemsg.FudgeContext;
import org.fudgemsg.FudgeFieldContainer;
import org.fudgemsg.FudgeMsg;


/**
 * A simple JavaBean-based implementation of {@link LiveDataValueUpdate}.
 *
 * @author kirk
 */
public class LiveDataValueUpdateBean implements LiveDataValueUpdate,
    Serializable {
  private static final String RELEVANT_TIMESTAMP_FIELD_NAME = "relevantTimestamp";
  private static final String SPECIFICATION_FIELD_NAME = "specification";
  private static final String FIELDS_FIELD_NAME = "fields";
  private final long _relevantTimestamp;
  private final LiveDataSpecification _specification;
  private final FudgeFieldContainer _fieldContainer;
  
  public LiveDataValueUpdateBean(long relevantTimestamp, LiveDataSpecification specification, FudgeFieldContainer fieldContainer) {
    // TODO kirk 2009-09-29 -- Check Inputs.
    _relevantTimestamp = relevantTimestamp;
    _specification = specification;
    _fieldContainer = fieldContainer;
  }

  @Override
  public FudgeFieldContainer getFields() {
    return _fieldContainer;
  }

  @Override
  public long getRelevantTimestamp() {
    return _relevantTimestamp;
  }

  @Override
  public LiveDataSpecification getSpecification() {
    return _specification;
  }
  
  public FudgeMsg toFudgeMsg(FudgeContext fudgeContext) {
    FudgeMsg msg = fudgeContext.newMessage();
    msg.add(RELEVANT_TIMESTAMP_FIELD_NAME, getRelevantTimestamp());
    if(getSpecification() != null) {
      msg.add(SPECIFICATION_FIELD_NAME, getSpecification().toFudgeMsg(fudgeContext));
    }
    if(getFields() != null) {
      msg.add(FIELDS_FIELD_NAME, getFields());
    }
    return msg;
  }
  
  public static LiveDataValueUpdateBean fromFudgeMsg(FudgeMsg msg) {
    Long relevantTimestamp = msg.getLong(RELEVANT_TIMESTAMP_FIELD_NAME);
    FudgeFieldContainer specificationFields = msg.getMessage(SPECIFICATION_FIELD_NAME);
    FudgeFieldContainer fields = msg.getMessage(FIELDS_FIELD_NAME);
    // REVIEW kirk 2009-10-28 -- Right thing to do here?
    if(relevantTimestamp == null) {
      return null;
    }
    if(specificationFields == null) {
      return null;
    }
    if(fields == null) {
      return null;
    }
    LiveDataSpecification spec = new LiveDataSpecificationImpl(specificationFields);
    return new LiveDataValueUpdateBean(relevantTimestamp, spec, fields);
  }

}
{'fraction_non_alphanumeric': 0.07834101382488479, 'fraction_numerical': 0.010843046896177827, 'mean_word_length': 4.458579881656805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '369711', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1037, 'n_words': 251}