/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.sesame.engine; import java.util.ArrayList; import java.util.Arrays; import java.util.List; 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.ImmutableConstructor; 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.ImmutableList; import com.opengamma.sesame.config.ViewConfig; import com.opengamma.sesame.marketdata.MarketDataEnvironment; import com.opengamma.util.ArgumentChecker; /** * Encapsulates the arguments to * {@link ViewRunner#runView(ViewConfig, CalculationArguments, MarketDataEnvironment, List)} * so it can be invoked via REST. */ @BeanDefinition public final class RunViewArguments implements ImmutableBean { /** Configuration of the view defining the calculations. */ @PropertyDefinition(validate = "notNull") private final ViewConfig _viewConfig; /** Arguments specifying how the calculations should be run. */ @PropertyDefinition(validate = "notNull") private final CalculationArguments _calculationArguments; /** * Market data for running the calculations. The engine will try to provide any data required by the calculations * but not included in the environment. */ @PropertyDefinition(validate = "notNull") private final MarketDataEnvironment _suppliedData; /** Items in the portfolio (normally trades) which are the inputs to the calculations. */ @PropertyDefinition(validate = "notNull") private final List<Object> _portfolio; /** * @param viewConfig configuration of the view defining the calculations * @param calculationArguments arguments specifying how the calculations should be run * @param suppliedData market data for running the calculations. The engine will try to provide any data * required by the calculations but not included in the environment. * @param portfolio items in the portfolio (normally trades) which are the inputs to the calculations */ @ImmutableConstructor public RunViewArguments( ViewConfig viewConfig, CalculationArguments calculationArguments, MarketDataEnvironment suppliedData, List<?> portfolio) { ArgumentChecker.notNull(viewConfig, "viewConfig"); ArgumentChecker.notNull(calculationArguments, "calculationArguments"); ArgumentChecker.notNull(suppliedData, "suppliedData"); ArgumentChecker.notNull(portfolio, "portfolio"); _viewConfig = viewConfig; _calculationArguments = calculationArguments; _suppliedData = suppliedData; _portfolio = ImmutableList.copyOf(portfolio); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code RunViewArguments}. * @return the meta-bean, not null */ public static RunViewArguments.Meta meta() { return RunViewArguments.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(RunViewArguments.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static RunViewArguments.Builder builder() { return new RunViewArguments.Builder(); } @Override public RunViewArguments.Meta metaBean() { return RunViewArguments.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 configuration of the view defining the calculations. * @return the value of the property, not null */ public ViewConfig getViewConfig() { return _viewConfig; } //----------------------------------------------------------------------- /** * Gets arguments specifying how the calculations should be run. * @return the value of the property, not null */ public CalculationArguments getCalculationArguments() { return _calculationArguments; } //----------------------------------------------------------------------- /** * Gets market data for running the calculations. The engine will try to provide any data required by the calculations * but not included in the environment. * @return the value of the property, not null */ public MarketDataEnvironment getSuppliedData() { return _suppliedData; } //----------------------------------------------------------------------- /** * Gets items in the portfolio (normally trades) which are the inputs to the calculations. * @return the value of the property, not null */ public List<Object> getPortfolio() { return _portfolio; } //----------------------------------------------------------------------- /** * 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()) { RunViewArguments other = (RunViewArguments) obj; return JodaBeanUtils.equal(getViewConfig(), other.getViewConfig()) && JodaBeanUtils.equal(getCalculationArguments(), other.getCalculationArguments()) && JodaBeanUtils.equal(getSuppliedData(), other.getSuppliedData()) && JodaBeanUtils.equal(getPortfolio(), other.getPortfolio()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getViewConfig()); hash = hash * 31 + JodaBeanUtils.hashCode(getCalculationArguments()); hash = hash * 31 + JodaBeanUtils.hashCode(getSuppliedData()); hash = hash * 31 + JodaBeanUtils.hashCode(getPortfolio()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(160); buf.append("RunViewArguments{"); buf.append("viewConfig").append('=').append(getViewConfig()).append(',').append(' '); buf.append("calculationArguments").append('=').append(getCalculationArguments()).append(',').append(' '); buf.append("suppliedData").append('=').append(getSuppliedData()).append(',').append(' '); buf.append("portfolio").append('=').append(JodaBeanUtils.toString(getPortfolio())); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code RunViewArguments}. */ 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 viewConfig} property. */ private final MetaProperty<ViewConfig> _viewConfig = DirectMetaProperty.ofImmutable( this, "viewConfig", RunViewArguments.class, ViewConfig.class); /** * The meta-property for the {@code calculationArguments} property. */ private final MetaProperty<CalculationArguments> _calculationArguments = DirectMetaProperty.ofImmutable( this, "calculationArguments", RunViewArguments.class, CalculationArguments.class); /** * The meta-property for the {@code suppliedData} property. */ private final MetaProperty<MarketDataEnvironment> _suppliedData = DirectMetaProperty.ofImmutable( this, "suppliedData", RunViewArguments.class, MarketDataEnvironment.class); /** * The meta-property for the {@code portfolio} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<List<Object>> _portfolio = DirectMetaProperty.ofImmutable( this, "portfolio", RunViewArguments.class, (Class) List.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "viewConfig", "calculationArguments", "suppliedData", "portfolio"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 1970035271: // viewConfig return _viewConfig; case -172471155: // calculationArguments return _calculationArguments; case 1993166472: // suppliedData return _suppliedData; case 1121781064: // portfolio return _portfolio; } return super.metaPropertyGet(propertyName); } @Override public RunViewArguments.Builder builder() { return new RunViewArguments.Builder(); } @Override public Class<? extends RunViewArguments> beanType() { return RunViewArguments.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code viewConfig} property. * @return the meta-property, not null */ public MetaProperty<ViewConfig> viewConfig() { return _viewConfig; } /** * The meta-property for the {@code calculationArguments} property. * @return the meta-property, not null */ public MetaProperty<CalculationArguments> calculationArguments() { return _calculationArguments; } /** * The meta-property for the {@code suppliedData} property. * @return the meta-property, not null */ public MetaProperty<MarketDataEnvironment> suppliedData() { return _suppliedData; } /** * The meta-property for the {@code portfolio} property. * @return the meta-property, not null */ public MetaProperty<List<Object>> portfolio() { return _portfolio; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1970035271: // viewConfig return ((RunViewArguments) bean).getViewConfig(); case -172471155: // calculationArguments return ((RunViewArguments) bean).getCalculationArguments(); case 1993166472: // suppliedData return ((RunViewArguments) bean).getSuppliedData(); case 1121781064: // portfolio return ((RunViewArguments) bean).getPortfolio(); } 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 RunViewArguments}. */ public static final class Builder extends DirectFieldsBeanBuilder<RunViewArguments> { private ViewConfig _viewConfig; private CalculationArguments _calculationArguments; private MarketDataEnvironment _suppliedData; private List<Object> _portfolio = new ArrayList<Object>(); /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(RunViewArguments beanToCopy) { this._viewConfig = beanToCopy.getViewConfig(); this._calculationArguments = beanToCopy.getCalculationArguments(); this._suppliedData = beanToCopy.getSuppliedData(); this._portfolio = new ArrayList<Object>(beanToCopy.getPortfolio()); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 1970035271: // viewConfig return _viewConfig; case -172471155: // calculationArguments return _calculationArguments; case 1993166472: // suppliedData return _suppliedData; case 1121781064: // portfolio return _portfolio; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case 1970035271: // viewConfig this._viewConfig = (ViewConfig) newValue; break; case -172471155: // calculationArguments this._calculationArguments = (CalculationArguments) newValue; break; case 1993166472: // suppliedData this._suppliedData = (MarketDataEnvironment) newValue; break; case 1121781064: // portfolio this._portfolio = (List<Object>) 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 RunViewArguments build() { return new RunViewArguments( _viewConfig, _calculationArguments, _suppliedData, _portfolio); } //----------------------------------------------------------------------- /** * Sets the {@code viewConfig} property in the builder. * @param viewConfig the new value, not null * @return this, for chaining, not null */ public Builder viewConfig(ViewConfig viewConfig) { JodaBeanUtils.notNull(viewConfig, "viewConfig"); this._viewConfig = viewConfig; return this; } /** * Sets the {@code calculationArguments} property in the builder. * @param calculationArguments the new value, not null * @return this, for chaining, not null */ public Builder calculationArguments(CalculationArguments calculationArguments) { JodaBeanUtils.notNull(calculationArguments, "calculationArguments"); this._calculationArguments = calculationArguments; return this; } /** * Sets the {@code suppliedData} property in the builder. * @param suppliedData the new value, not null * @return this, for chaining, not null */ public Builder suppliedData(MarketDataEnvironment suppliedData) { JodaBeanUtils.notNull(suppliedData, "suppliedData"); this._suppliedData = suppliedData; return this; } /** * Sets the {@code portfolio} property in the builder. * @param portfolio the new value, not null * @return this, for chaining, not null */ public Builder portfolio(List<Object> portfolio) { JodaBeanUtils.notNull(portfolio, "portfolio"); this._portfolio = portfolio; return this; } /** * Sets the {@code portfolio} property in the builder * from an array of objects. * @param portfolio the new value, not null * @return this, for chaining, not null */ public Builder portfolio(Object... portfolio) { return portfolio(Arrays.asList(portfolio)); } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(160); buf.append("RunViewArguments.Builder{"); buf.append("viewConfig").append('=').append(JodaBeanUtils.toString(_viewConfig)).append(',').append(' '); buf.append("calculationArguments").append('=').append(JodaBeanUtils.toString(_calculationArguments)).append(',').append(' '); buf.append("suppliedData").append('=').append(JodaBeanUtils.toString(_suppliedData)).append(',').append(' '); buf.append("portfolio").append('=').append(JodaBeanUtils.toString(_portfolio)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }