/**
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.product;
import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
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.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.google.common.collect.ImmutableSet;
import com.opengamma.strata.basics.ReferenceData;
import com.opengamma.strata.product.bond.BondFutureOptionSecurity;
import com.opengamma.strata.product.bond.FixedCouponBondSecurity;
import com.opengamma.strata.product.index.IborFutureSecurity;
/**
* A generic security, defined in terms of the value of each tick.
* <p>
* In most cases, applications will choose to represent information about securities
* using the relevant type, such as {@link FixedCouponBondSecurity},
* {@link BondFutureOptionSecurity} or {@link IborFutureSecurity}.
* Sometimes however, it can be useful to store minimal information about the security,
* expressing just the tick size and tick value.
*/
@BeanDefinition(builderScope = "private")
public final class GenericSecurity
implements Security, ImmutableBean, Serializable {
/**
* The standard security information.
* <p>
* This includes the security identifier.
*/
@PropertyDefinition(validate = "notNull", overrideGet = true)
private final SecurityInfo info;
//-------------------------------------------------------------------------
/**
* Obtains an instance from security information, tick size and tick value.
*
* @param securityInfo the security information
* @return the security
*/
public static GenericSecurity of(SecurityInfo securityInfo) {
return new GenericSecurity(securityInfo);
}
//-------------------------------------------------------------------------
@Override
public ImmutableSet<SecurityId> getUnderlyingIds() {
return ImmutableSet.of();
}
//-------------------------------------------------------------------------
@Override
public SecuritizedProduct createProduct(ReferenceData refData) {
throw new UnsupportedOperationException("Unable to create product, GenericSecurity does not have a product model");
}
@Override
public GenericSecurityTrade createTrade(TradeInfo info, double quantity, double tradePrice, ReferenceData refData) {
return new GenericSecurityTrade(info, this, quantity, tradePrice);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code GenericSecurity}.
* @return the meta-bean, not null
*/
public static GenericSecurity.Meta meta() {
return GenericSecurity.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(GenericSecurity.Meta.INSTANCE);
}
/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;
private GenericSecurity(
SecurityInfo info) {
JodaBeanUtils.notNull(info, "info");
this.info = info;
}
@Override
public GenericSecurity.Meta metaBean() {
return GenericSecurity.Meta.INSTANCE;
}
@Override
public <R> Property<R> property(String propertyName) {
return metaBean().<R>metaProperty(propertyName).createProperty(this);
}
@Override
public Set<String> propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the standard security information.
* <p>
* This includes the security identifier.
* @return the value of the property, not null
*/
@Override
public SecurityInfo getInfo() {
return info;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
GenericSecurity other = (GenericSecurity) obj;
return JodaBeanUtils.equal(info, other.info);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(info);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(64);
buf.append("GenericSecurity{");
buf.append("info").append('=').append(JodaBeanUtils.toString(info));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code GenericSecurity}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code info} property.
*/
private final MetaProperty<SecurityInfo> info = DirectMetaProperty.ofImmutable(
this, "info", GenericSecurity.class, SecurityInfo.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"info");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends GenericSecurity> builder() {
return new GenericSecurity.Builder();
}
@Override
public Class<? extends GenericSecurity> beanType() {
return GenericSecurity.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code info} property.
* @return the meta-property, not null
*/
public MetaProperty<SecurityInfo> info() {
return info;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3237038: // info
return ((GenericSecurity) bean).getInfo();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code GenericSecurity}.
*/
private static final class Builder extends DirectFieldsBeanBuilder<GenericSecurity> {
private SecurityInfo info;
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3237038: // info
return info;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 3237038: // info
this.info = (SecurityInfo) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder set(MetaProperty<?> property, Object value) {
super.set(property, value);
return this;
}
@Override
public Builder setString(String propertyName, String value) {
setString(meta().metaProperty(propertyName), value);
return this;
}
@Override
public Builder setString(MetaProperty<?> property, String value) {
super.setString(property, value);
return this;
}
@Override
public Builder setAll(Map<String, ? extends Object> propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public GenericSecurity build() {
return new GenericSecurity(
info);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(64);
buf.append("GenericSecurity.Builder{");
buf.append("info").append('=').append(JodaBeanUtils.toString(info));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}