com.opengamma.strata.report.trade.TradeReportColumn Maven / Gradle / Ivy
/**
* Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.report.trade;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
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;
/**
* Describes a column in a trade report.
*
* Processing of the fields is intentionally delayed so that the fields can be interpreted
* in the context of the calculation results, and errors are delayed until the report is run.
*/
@BeanDefinition
public class TradeReportColumn
implements ImmutableBean {
/**
* The column header.
*/
@PropertyDefinition(validate = "notNull")
private final String header;
/**
* The reference to a value to display in this column.
*/
@PropertyDefinition(get = "optional")
private final String value;
/**
* Whether to ignore failures, or report the errors.
*/
@PropertyDefinition
private final boolean ignoreFailures;
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code TradeReportColumn}.
* @return the meta-bean, not null
*/
public static TradeReportColumn.Meta meta() {
return TradeReportColumn.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(TradeReportColumn.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static TradeReportColumn.Builder builder() {
return new TradeReportColumn.Builder();
}
/**
* Restricted constructor.
* @param builder the builder to copy from, not null
*/
protected TradeReportColumn(TradeReportColumn.Builder builder) {
JodaBeanUtils.notNull(builder.header, "header");
this.header = builder.header;
this.value = builder.value;
this.ignoreFailures = builder.ignoreFailures;
}
@Override
public TradeReportColumn.Meta metaBean() {
return TradeReportColumn.Meta.INSTANCE;
}
@Override
public Property property(String propertyName) {
return metaBean().metaProperty(propertyName).createProperty(this);
}
@Override
public Set propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the column header.
* @return the value of the property, not null
*/
public String getHeader() {
return header;
}
//-----------------------------------------------------------------------
/**
* Gets the reference to a value to display in this column.
* @return the optional value of the property, not null
*/
public Optional getValue() {
return Optional.ofNullable(value);
}
//-----------------------------------------------------------------------
/**
* Gets whether to ignore failures, or report the errors.
* @return the value of the property
*/
public boolean isIgnoreFailures() {
return ignoreFailures;
}
//-----------------------------------------------------------------------
/**
* 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()) {
TradeReportColumn other = (TradeReportColumn) obj;
return JodaBeanUtils.equal(header, other.header) &&
JodaBeanUtils.equal(value, other.value) &&
(ignoreFailures == other.ignoreFailures);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(header);
hash = hash * 31 + JodaBeanUtils.hashCode(value);
hash = hash * 31 + JodaBeanUtils.hashCode(ignoreFailures);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("TradeReportColumn{");
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("header").append('=').append(JodaBeanUtils.toString(header)).append(',').append(' ');
buf.append("value").append('=').append(JodaBeanUtils.toString(value)).append(',').append(' ');
buf.append("ignoreFailures").append('=').append(JodaBeanUtils.toString(ignoreFailures)).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code TradeReportColumn}.
*/
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 header} property.
*/
private final MetaProperty header = DirectMetaProperty.ofImmutable(
this, "header", TradeReportColumn.class, String.class);
/**
* The meta-property for the {@code value} property.
*/
private final MetaProperty value = DirectMetaProperty.ofImmutable(
this, "value", TradeReportColumn.class, String.class);
/**
* The meta-property for the {@code ignoreFailures} property.
*/
private final MetaProperty ignoreFailures = DirectMetaProperty.ofImmutable(
this, "ignoreFailures", TradeReportColumn.class, Boolean.TYPE);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"header",
"value",
"ignoreFailures");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1221270899: // header
return header;
case 111972721: // value
return value;
case -335122405: // ignoreFailures
return ignoreFailures;
}
return super.metaPropertyGet(propertyName);
}
@Override
public TradeReportColumn.Builder builder() {
return new TradeReportColumn.Builder();
}
@Override
public Class extends TradeReportColumn> beanType() {
return TradeReportColumn.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code header} property.
* @return the meta-property, not null
*/
public final MetaProperty header() {
return header;
}
/**
* The meta-property for the {@code value} property.
* @return the meta-property, not null
*/
public final MetaProperty value() {
return value;
}
/**
* The meta-property for the {@code ignoreFailures} property.
* @return the meta-property, not null
*/
public final MetaProperty ignoreFailures() {
return ignoreFailures;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1221270899: // header
return ((TradeReportColumn) bean).getHeader();
case 111972721: // value
return ((TradeReportColumn) bean).value;
case -335122405: // ignoreFailures
return ((TradeReportColumn) bean).isIgnoreFailures();
}
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 TradeReportColumn}.
*/
public static class Builder extends DirectFieldsBeanBuilder {
private String header;
private String value;
private boolean ignoreFailures;
/**
* Restricted constructor.
*/
protected Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
protected Builder(TradeReportColumn beanToCopy) {
this.header = beanToCopy.getHeader();
this.value = beanToCopy.value;
this.ignoreFailures = beanToCopy.isIgnoreFailures();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -1221270899: // header
return header;
case 111972721: // value
return value;
case -335122405: // ignoreFailures
return ignoreFailures;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -1221270899: // header
this.header = (String) newValue;
break;
case 111972721: // value
this.value = (String) newValue;
break;
case -335122405: // ignoreFailures
this.ignoreFailures = (Boolean) 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 propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public TradeReportColumn build() {
return new TradeReportColumn(this);
}
//-----------------------------------------------------------------------
/**
* Sets the column header.
* @param header the new value, not null
* @return this, for chaining, not null
*/
public Builder header(String header) {
JodaBeanUtils.notNull(header, "header");
this.header = header;
return this;
}
/**
* Sets the reference to a value to display in this column.
* @param value the new value
* @return this, for chaining, not null
*/
public Builder value(String value) {
this.value = value;
return this;
}
/**
* Sets whether to ignore failures, or report the errors.
* @param ignoreFailures the new value
* @return this, for chaining, not null
*/
public Builder ignoreFailures(boolean ignoreFailures) {
this.ignoreFailures = ignoreFailures;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("TradeReportColumn.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("header").append('=').append(JodaBeanUtils.toString(header)).append(',').append(' ');
buf.append("value").append('=').append(JodaBeanUtils.toString(value)).append(',').append(' ');
buf.append("ignoreFailures").append('=').append(JodaBeanUtils.toString(ignoreFailures)).append(',').append(' ');
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}