/**
* 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.HashMap;
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.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.google.common.collect.ImmutableMap;
/**
* Immutable bean that holds the outputs produced by a view.
* This is just a holder so that the outputs of a view can
* easily be serialized separately from the view's inputs.
*/
@BeanDefinition
public class ViewOutputs implements ImmutableBean {
/**
* The column names of the outputs.
*/
@PropertyDefinition(validate = "notNull")
private final List<String> _columnNames;
/**
* The rows containing the outputs.
*/
@PropertyDefinition(validate = "notNull")
private final List<ResultRow> _rows;
/**
* Arbitrary outputs that aren't calculated for a particular
* position or trade, e.g. a curve or surface.
*/
@PropertyDefinition(validate = "notNull")
private final Map<String, ResultItem> _nonPortfolioResults;
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code ViewOutputs}.
* @return the meta-bean, not null
*/
public static ViewOutputs.Meta meta() {
return ViewOutputs.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(ViewOutputs.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static ViewOutputs.Builder builder() {
return new ViewOutputs.Builder();
}
/**
* Restricted constructor.
* @param builder the builder to copy from, not null
*/
protected ViewOutputs(ViewOutputs.Builder builder) {
JodaBeanUtils.notNull(builder._columnNames, "columnNames");
JodaBeanUtils.notNull(builder._rows, "rows");
JodaBeanUtils.notNull(builder._nonPortfolioResults, "nonPortfolioResults");
this._columnNames = ImmutableList.copyOf(builder._columnNames);
this._rows = ImmutableList.copyOf(builder._rows);
this._nonPortfolioResults = ImmutableMap.copyOf(builder._nonPortfolioResults);
}
@Override
public ViewOutputs.Meta metaBean() {
return ViewOutputs.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 column names of the outputs.
* @return the value of the property, not null
*/
public List<String> getColumnNames() {
return _columnNames;
}
//-----------------------------------------------------------------------
/**
* Gets the rows containing the outputs.
* @return the value of the property, not null
*/
public List<ResultRow> getRows() {
return _rows;
}
//-----------------------------------------------------------------------
/**
* Gets arbitrary outputs that aren't calculated for a particular
* position or trade, e.g. a curve or surface.
* @return the value of the property, not null
*/
public Map<String, ResultItem> getNonPortfolioResults() {
return _nonPortfolioResults;
}
//-----------------------------------------------------------------------
/**
* 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()) {
ViewOutputs other = (ViewOutputs) obj;
return JodaBeanUtils.equal(getColumnNames(), other.getColumnNames()) &&
JodaBeanUtils.equal(getRows(), other.getRows()) &&
JodaBeanUtils.equal(getNonPortfolioResults(), other.getNonPortfolioResults());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getColumnNames());
hash = hash * 31 + JodaBeanUtils.hashCode(getRows());
hash = hash * 31 + JodaBeanUtils.hashCode(getNonPortfolioResults());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("ViewOutputs{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
protected void toString(StringBuilder buf) {
buf.append("columnNames").append('=').append(JodaBeanUtils.toString(getColumnNames())).append(',').append(' ');
buf.append("rows").append('=').append(JodaBeanUtils.toString(getRows())).append(',').append(' ');
buf.append("nonPortfolioResults").append('=').append(JodaBeanUtils.toString(getNonPortfolioResults())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code ViewOutputs}.
*/
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 columnNames} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<String>> _columnNames = DirectMetaProperty.ofImmutable(
this, "columnNames", ViewOutputs.class, (Class) List.class);
/**
* The meta-property for the {@code rows} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<ResultRow>> _rows = DirectMetaProperty.ofImmutable(
this, "rows", ViewOutputs.class, (Class) List.class);
/**
* The meta-property for the {@code nonPortfolioResults} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<Map<String, ResultItem>> _nonPortfolioResults = DirectMetaProperty.ofImmutable(
this, "nonPortfolioResults", ViewOutputs.class, (Class) Map.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"columnNames",
"rows",
"nonPortfolioResults");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -851002990: // columnNames
return _columnNames;
case 3506649: // rows
return _rows;
case -1919647109: // nonPortfolioResults
return _nonPortfolioResults;
}
return super.metaPropertyGet(propertyName);
}
@Override
public ViewOutputs.Builder builder() {
return new ViewOutputs.Builder();
}
@Override
public Class<? extends ViewOutputs> beanType() {
return ViewOutputs.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code columnNames} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<String>> columnNames() {
return _columnNames;
}
/**
* The meta-property for the {@code rows} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<ResultRow>> rows() {
return _rows;
}
/**
* The meta-property for the {@code nonPortfolioResults} property.
* @return the meta-property, not null
*/
public final MetaProperty<Map<String, ResultItem>> nonPortfolioResults() {
return _nonPortfolioResults;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -851002990: // columnNames
return ((ViewOutputs) bean).getColumnNames();
case 3506649: // rows
return ((ViewOutputs) bean).getRows();
case -1919647109: // nonPortfolioResults
return ((ViewOutputs) bean).getNonPortfolioResults();
}
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 ViewOutputs}.
*/
public static class Builder extends DirectFieldsBeanBuilder<ViewOutputs> {
private List<String> _columnNames = new ArrayList<String>();
private List<ResultRow> _rows = new ArrayList<ResultRow>();
private Map<String, ResultItem> _nonPortfolioResults = new HashMap<String, ResultItem>();
/**
* Restricted constructor.
*/
protected Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
protected Builder(ViewOutputs beanToCopy) {
this._columnNames = new ArrayList<String>(beanToCopy.getColumnNames());
this._rows = new ArrayList<ResultRow>(beanToCopy.getRows());
this._nonPortfolioResults = new HashMap<String, ResultItem>(beanToCopy.getNonPortfolioResults());
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -851002990: // columnNames
return _columnNames;
case 3506649: // rows
return _rows;
case -1919647109: // nonPortfolioResults
return _nonPortfolioResults;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@SuppressWarnings("unchecked")
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -851002990: // columnNames
this._columnNames = (List<String>) newValue;
break;
case 3506649: // rows
this._rows = (List<ResultRow>) newValue;
break;
case -1919647109: // nonPortfolioResults
this._nonPortfolioResults = (Map<String, ResultItem>) 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 ViewOutputs build() {
return new ViewOutputs(this);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code columnNames} property in the builder.
* @param columnNames the new value, not null
* @return this, for chaining, not null
*/
public Builder columnNames(List<String> columnNames) {
JodaBeanUtils.notNull(columnNames, "columnNames");
this._columnNames = columnNames;
return this;
}
/**
* Sets the {@code columnNames} property in the builder
* from an array of objects.
* @param columnNames the new value, not null
* @return this, for chaining, not null
*/
public Builder columnNames(String... columnNames) {
return columnNames(Arrays.asList(columnNames));
}
/**
* Sets the {@code rows} property in the builder.
* @param rows the new value, not null
* @return this, for chaining, not null
*/
public Builder rows(List<ResultRow> rows) {
JodaBeanUtils.notNull(rows, "rows");
this._rows = rows;
return this;
}
/**
* Sets the {@code rows} property in the builder
* from an array of objects.
* @param rows the new value, not null
* @return this, for chaining, not null
*/
public Builder rows(ResultRow... rows) {
return rows(Arrays.asList(rows));
}
/**
* Sets the {@code nonPortfolioResults} property in the builder.
* @param nonPortfolioResults the new value, not null
* @return this, for chaining, not null
*/
public Builder nonPortfolioResults(Map<String, ResultItem> nonPortfolioResults) {
JodaBeanUtils.notNull(nonPortfolioResults, "nonPortfolioResults");
this._nonPortfolioResults = nonPortfolioResults;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("ViewOutputs.Builder{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
protected void toString(StringBuilder buf) {
buf.append("columnNames").append('=').append(JodaBeanUtils.toString(_columnNames)).append(',').append(' ');
buf.append("rows").append('=').append(JodaBeanUtils.toString(_rows)).append(',').append(' ');
buf.append("nonPortfolioResults").append('=').append(JodaBeanUtils.toString(_nonPortfolioResults)).append(',').append(' ');
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}