/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.sesame.credit.config; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import org.joda.beans.Bean; 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.ImmutableMap; import com.opengamma.analytics.financial.credit.RestructuringClause; import com.opengamma.core.config.Config; import com.opengamma.util.money.Currency; /** * Defines which restructuring clause to use per currency. This is used to * drive which restructuring clause should be applied when pricing standard * CDS securities. */ @BeanDefinition @Config(description = "Restructuring settings", group = "Credit") public final class RestructuringSettings implements ImmutableBean { /** * Maps a currency to a restructuring clause. */ @PropertyDefinition private final Map<Currency, RestructuringClause> _restructuringMappings; //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code RestructuringSettings}. * @return the meta-bean, not null */ public static RestructuringSettings.Meta meta() { return RestructuringSettings.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(RestructuringSettings.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static RestructuringSettings.Builder builder() { return new RestructuringSettings.Builder(); } private RestructuringSettings( Map<Currency, RestructuringClause> restructuringMappings) { this._restructuringMappings = (restructuringMappings != null ? ImmutableMap.copyOf(restructuringMappings) : null); } @Override public RestructuringSettings.Meta metaBean() { return RestructuringSettings.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 maps a currency to a restructuring clause. * @return the value of the property */ public Map<Currency, RestructuringClause> getRestructuringMappings() { return _restructuringMappings; } //----------------------------------------------------------------------- /** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { RestructuringSettings other = (RestructuringSettings) obj; return JodaBeanUtils.equal(getRestructuringMappings(), other.getRestructuringMappings()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getRestructuringMappings()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("RestructuringSettings{"); buf.append("restructuringMappings").append('=').append(JodaBeanUtils.toString(getRestructuringMappings())); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code RestructuringSettings}. */ 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 restructuringMappings} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Map<Currency, RestructuringClause>> _restructuringMappings = DirectMetaProperty.ofImmutable( this, "restructuringMappings", RestructuringSettings.class, (Class) Map.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "restructuringMappings"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1080584734: // restructuringMappings return _restructuringMappings; } return super.metaPropertyGet(propertyName); } @Override public RestructuringSettings.Builder builder() { return new RestructuringSettings.Builder(); } @Override public Class<? extends RestructuringSettings> beanType() { return RestructuringSettings.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code restructuringMappings} property. * @return the meta-property, not null */ public MetaProperty<Map<Currency, RestructuringClause>> restructuringMappings() { return _restructuringMappings; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1080584734: // restructuringMappings return ((RestructuringSettings) bean).getRestructuringMappings(); } 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 RestructuringSettings}. */ public static final class Builder extends DirectFieldsBeanBuilder<RestructuringSettings> { private Map<Currency, RestructuringClause> _restructuringMappings; /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(RestructuringSettings beanToCopy) { this._restructuringMappings = (beanToCopy.getRestructuringMappings() != null ? new HashMap<Currency, RestructuringClause>(beanToCopy.getRestructuringMappings()) : null); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case -1080584734: // restructuringMappings return _restructuringMappings; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case -1080584734: // restructuringMappings this._restructuringMappings = (Map<Currency, RestructuringClause>) 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 RestructuringSettings build() { return new RestructuringSettings( _restructuringMappings); } //----------------------------------------------------------------------- /** * Sets the {@code restructuringMappings} property in the builder. * @param restructuringMappings the new value * @return this, for chaining, not null */ public Builder restructuringMappings(Map<Currency, RestructuringClause> restructuringMappings) { this._restructuringMappings = restructuringMappings; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("RestructuringSettings.Builder{"); buf.append("restructuringMappings").append('=').append(JodaBeanUtils.toString(_restructuringMappings)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }