/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.master.historicaltimeseries.impl;
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.opengamma.util.ArgumentChecker;
/**
* An individual rule for rating for a field name and value.
* <p>
* This class is immutable and thread-safe.
*/
@BeanDefinition
public final class HistoricalTimeSeriesRatingRule implements ImmutableBean {
/**
* The field name.
*/
@PropertyDefinition(validate = "notNull")
private final String _fieldName;
/**
* The field value.
*/
@PropertyDefinition(validate = "notNull")
private final String _fieldValue;
/**
* The rating.
*/
@PropertyDefinition
private final int _rating;
//-------------------------------------------------------------------------
/**
* Obtains an instance of {@code HistoricalTimeSeriesRatingRule}.
*
* @param fieldName the field name, not null
* @param fieldValue the field value, not null
* @param rating the rating, zero or greater
* @return the rule, not null
*/
public static HistoricalTimeSeriesRatingRule of(String fieldName, String fieldValue, int rating) {
return new HistoricalTimeSeriesRatingRule(fieldName, fieldValue, rating);
}
//-------------------------------------------------------------------------
/**
* Creates an instance.
*
* @param fieldName the field name, not null
* @param fieldValue the field value, not null
* @param rating the rating, zero or greater
*/
@ImmutableConstructor
private HistoricalTimeSeriesRatingRule(String fieldName, String fieldValue, int rating) {
ArgumentChecker.notNull(fieldName, "fieldName");
ArgumentChecker.isTrue(HistoricalTimeSeriesRatingFieldNames.VALID_FIELD_NAMES.contains(fieldName), "invalid field name");
ArgumentChecker.notNull(fieldValue, "fieldValue");
ArgumentChecker.isTrue(rating >= 0, "rating cannot be negative");
_fieldName = fieldName;
_fieldValue = fieldValue;
_rating = rating;
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code HistoricalTimeSeriesRatingRule}.
* @return the meta-bean, not null
*/
public static HistoricalTimeSeriesRatingRule.Meta meta() {
return HistoricalTimeSeriesRatingRule.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(HistoricalTimeSeriesRatingRule.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static HistoricalTimeSeriesRatingRule.Builder builder() {
return new HistoricalTimeSeriesRatingRule.Builder();
}
@Override
public HistoricalTimeSeriesRatingRule.Meta metaBean() {
return HistoricalTimeSeriesRatingRule.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 field name.
* @return the value of the property, not null
*/
public String getFieldName() {
return _fieldName;
}
//-----------------------------------------------------------------------
/**
* Gets the field value.
* @return the value of the property, not null
*/
public String getFieldValue() {
return _fieldValue;
}
//-----------------------------------------------------------------------
/**
* Gets the rating.
* @return the value of the property
*/
public int getRating() {
return _rating;
}
//-----------------------------------------------------------------------
/**
* 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()) {
HistoricalTimeSeriesRatingRule other = (HistoricalTimeSeriesRatingRule) obj;
return JodaBeanUtils.equal(getFieldName(), other.getFieldName()) &&
JodaBeanUtils.equal(getFieldValue(), other.getFieldValue()) &&
(getRating() == other.getRating());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getFieldName());
hash = hash * 31 + JodaBeanUtils.hashCode(getFieldValue());
hash = hash * 31 + JodaBeanUtils.hashCode(getRating());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("HistoricalTimeSeriesRatingRule{");
buf.append("fieldName").append('=').append(getFieldName()).append(',').append(' ');
buf.append("fieldValue").append('=').append(getFieldValue()).append(',').append(' ');
buf.append("rating").append('=').append(JodaBeanUtils.toString(getRating()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code HistoricalTimeSeriesRatingRule}.
*/
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 fieldName} property.
*/
private final MetaProperty<String> _fieldName = DirectMetaProperty.ofImmutable(
this, "fieldName", HistoricalTimeSeriesRatingRule.class, String.class);
/**
* The meta-property for the {@code fieldValue} property.
*/
private final MetaProperty<String> _fieldValue = DirectMetaProperty.ofImmutable(
this, "fieldValue", HistoricalTimeSeriesRatingRule.class, String.class);
/**
* The meta-property for the {@code rating} property.
*/
private final MetaProperty<Integer> _rating = DirectMetaProperty.ofImmutable(
this, "rating", HistoricalTimeSeriesRatingRule.class, Integer.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"fieldName",
"fieldValue",
"rating");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 1265009317: // fieldName
return _fieldName;
case 567970967: // fieldValue
return _fieldValue;
case -938102371: // rating
return _rating;
}
return super.metaPropertyGet(propertyName);
}
@Override
public HistoricalTimeSeriesRatingRule.Builder builder() {
return new HistoricalTimeSeriesRatingRule.Builder();
}
@Override
public Class<? extends HistoricalTimeSeriesRatingRule> beanType() {
return HistoricalTimeSeriesRatingRule.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code fieldName} property.
* @return the meta-property, not null
*/
public MetaProperty<String> fieldName() {
return _fieldName;
}
/**
* The meta-property for the {@code fieldValue} property.
* @return the meta-property, not null
*/
public MetaProperty<String> fieldValue() {
return _fieldValue;
}
/**
* The meta-property for the {@code rating} property.
* @return the meta-property, not null
*/
public MetaProperty<Integer> rating() {
return _rating;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 1265009317: // fieldName
return ((HistoricalTimeSeriesRatingRule) bean).getFieldName();
case 567970967: // fieldValue
return ((HistoricalTimeSeriesRatingRule) bean).getFieldValue();
case -938102371: // rating
return ((HistoricalTimeSeriesRatingRule) bean).getRating();
}
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 HistoricalTimeSeriesRatingRule}.
*/
public static final class Builder extends DirectFieldsBeanBuilder<HistoricalTimeSeriesRatingRule> {
private String _fieldName;
private String _fieldValue;
private int _rating;
/**
* Restricted constructor.
*/
private Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(HistoricalTimeSeriesRatingRule beanToCopy) {
this._fieldName = beanToCopy.getFieldName();
this._fieldValue = beanToCopy.getFieldValue();
this._rating = beanToCopy.getRating();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 1265009317: // fieldName
return _fieldName;
case 567970967: // fieldValue
return _fieldValue;
case -938102371: // rating
return _rating;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 1265009317: // fieldName
this._fieldName = (String) newValue;
break;
case 567970967: // fieldValue
this._fieldValue = (String) newValue;
break;
case -938102371: // rating
this._rating = (Integer) 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 HistoricalTimeSeriesRatingRule build() {
return new HistoricalTimeSeriesRatingRule(
_fieldName,
_fieldValue,
_rating);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code fieldName} property in the builder.
* @param fieldName the new value, not null
* @return this, for chaining, not null
*/
public Builder fieldName(String fieldName) {
JodaBeanUtils.notNull(fieldName, "fieldName");
this._fieldName = fieldName;
return this;
}
/**
* Sets the {@code fieldValue} property in the builder.
* @param fieldValue the new value, not null
* @return this, for chaining, not null
*/
public Builder fieldValue(String fieldValue) {
JodaBeanUtils.notNull(fieldValue, "fieldValue");
this._fieldValue = fieldValue;
return this;
}
/**
* Sets the {@code rating} property in the builder.
* @param rating the new value
* @return this, for chaining, not null
*/
public Builder rating(int rating) {
this._rating = rating;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("HistoricalTimeSeriesRatingRule.Builder{");
buf.append("fieldName").append('=').append(JodaBeanUtils.toString(_fieldName)).append(',').append(' ');
buf.append("fieldValue").append('=').append(JodaBeanUtils.toString(_fieldValue)).append(',').append(' ');
buf.append("rating").append('=').append(JodaBeanUtils.toString(_rating));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}