/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.util.fudgemsg;

import java.util.Map;

import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectBean;
import org.joda.beans.impl.direct.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;

/**
 * A wrapper for a boolean that ensures transfer by Fudge.
 * <p>
 * This allows a boolean to be easily sent in a full Fudge wrapper.
 */
@BeanDefinition
public class FudgeBooleanWrapper extends DirectBean {

  /**
   * The boolean value.
   */
  @PropertyDefinition
  private boolean _value;

  /**
   * Creates an instance.
   * 
   * @param value  the value, not null
   * @return the list, not null
   */
  public static FudgeBooleanWrapper of(boolean value) {
    return new FudgeBooleanWrapper(value);
  }

  //-------------------------------------------------------------------------
  /**
   * Creates an instance.
   */
  private FudgeBooleanWrapper() {
  }

  /**
   * Creates an instance.
   * 
   * @param value  the value, not null
   */
  public FudgeBooleanWrapper(boolean value) {
    setValue(value);
  }

  //------------------------- AUTOGENERATED START -------------------------
  ///CLOVER:OFF
  /**
   * The meta-bean for {@code FudgeBooleanWrapper}.
   * @return the meta-bean, not null
   */
  public static FudgeBooleanWrapper.Meta meta() {
    return FudgeBooleanWrapper.Meta.INSTANCE;
  }
  static {
    JodaBeanUtils.registerMetaBean(FudgeBooleanWrapper.Meta.INSTANCE);
  }

  @Override
  public FudgeBooleanWrapper.Meta metaBean() {
    return FudgeBooleanWrapper.Meta.INSTANCE;
  }

  @Override
  protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
      case 111972721:  // value
        return isValue();
    }
    return super.propertyGet(propertyName, quiet);
  }

  @Override
  protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
      case 111972721:  // value
        setValue((Boolean) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      FudgeBooleanWrapper other = (FudgeBooleanWrapper) obj;
      return JodaBeanUtils.equal(isValue(), other.isValue());
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash += hash * 31 + JodaBeanUtils.hashCode(isValue());
    return hash;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the boolean value.
   * @return the value of the property
   */
  public boolean isValue() {
    return _value;
  }

  /**
   * Sets the boolean value.
   * @param value  the new value of the property
   */
  public void setValue(boolean value) {
    this._value = value;
  }

  /**
   * Gets the the {@code value} property.
   * @return the property, not null
   */
  public final Property<Boolean> value() {
    return metaBean().value().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code FudgeBooleanWrapper}.
   */
  public static class Meta extends DirectMetaBean {
    /**
     * The singleton instance of the meta-bean.
     */
    static final Meta INSTANCE = new Meta();

    /**
     * The meta-property for the {@code value} property.
     */
    private final MetaProperty<Boolean> _value = DirectMetaProperty.ofReadWrite(
        this, "value", FudgeBooleanWrapper.class, Boolean.TYPE);
    /**
     * The meta-properties.
     */
    private final Map<String, MetaProperty<Object>> _map = new DirectMetaPropertyMap(
        this, null,
        "value");

    /**
     * Restricted constructor.
     */
    protected Meta() {
    }

    @Override
    protected MetaProperty<?> metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case 111972721:  // value
          return _value;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder<? extends FudgeBooleanWrapper> builder() {
      return new DirectBeanBuilder<FudgeBooleanWrapper>(new FudgeBooleanWrapper());
    }

    @Override
    public Class<? extends FudgeBooleanWrapper> beanType() {
      return FudgeBooleanWrapper.class;
    }

    @Override
    public Map<String, MetaProperty<Object>> metaPropertyMap() {
      return _map;
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-property for the {@code value} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<Boolean> value() {
      return _value;
    }

  }

  ///CLOVER:ON
  //-------------------------- AUTOGENERATED END --------------------------
}

Add simple boolean wrapper to aid with Fudge