/** * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.engine.marketdata.spec; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import org.apache.commons.lang.StringUtils; 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.opengamma.util.ArgumentChecker; /** * LiveMarketDataSpecification */ @BeanDefinition public final class LiveMarketDataSpecification implements ImmutableBean, MarketDataSpecification { private static final long serialVersionUID = 1L; /** * The data source */ @PropertyDefinition private final String _dataSource; /** * Avoid creating multiple instances since the live case is so common and most requests should come through this * helper. */ public static final LiveMarketDataSpecification LIVE_SPEC = new LiveMarketDataSpecification(null); /** * Creates a live market data specification * * @param dataSource the data source, not-null * @return the live market data specification, not null */ public static LiveMarketDataSpecification of(String dataSource) { dataSource = StringUtils.trimToNull(dataSource); ArgumentChecker.notNull(dataSource, "dataSource"); return new LiveMarketDataSpecification(dataSource); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code LiveMarketDataSpecification}. * @return the meta-bean, not null */ public static LiveMarketDataSpecification.Meta meta() { return LiveMarketDataSpecification.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(LiveMarketDataSpecification.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static LiveMarketDataSpecification.Builder builder() { return new LiveMarketDataSpecification.Builder(); } private LiveMarketDataSpecification( String dataSource) { this._dataSource = dataSource; } @Override public LiveMarketDataSpecification.Meta metaBean() { return LiveMarketDataSpecification.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 data source * @return the value of the property */ public String getDataSource() { return _dataSource; } //----------------------------------------------------------------------- /** * 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()) { LiveMarketDataSpecification other = (LiveMarketDataSpecification) obj; return JodaBeanUtils.equal(getDataSource(), other.getDataSource()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getDataSource()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("LiveMarketDataSpecification{"); buf.append("dataSource").append('=').append(JodaBeanUtils.toString(getDataSource())); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code LiveMarketDataSpecification}. */ 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 dataSource} property. */ private final MetaProperty<String> _dataSource = DirectMetaProperty.ofImmutable( this, "dataSource", LiveMarketDataSpecification.class, String.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "dataSource"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 1272470629: // dataSource return _dataSource; } return super.metaPropertyGet(propertyName); } @Override public LiveMarketDataSpecification.Builder builder() { return new LiveMarketDataSpecification.Builder(); } @Override public Class<? extends LiveMarketDataSpecification> beanType() { return LiveMarketDataSpecification.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code dataSource} property. * @return the meta-property, not null */ public MetaProperty<String> dataSource() { return _dataSource; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1272470629: // dataSource return ((LiveMarketDataSpecification) bean).getDataSource(); } 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 LiveMarketDataSpecification}. */ public static final class Builder extends DirectFieldsBeanBuilder<LiveMarketDataSpecification> { private String _dataSource; /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(LiveMarketDataSpecification beanToCopy) { this._dataSource = beanToCopy.getDataSource(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 1272470629: // dataSource return _dataSource; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case 1272470629: // dataSource this._dataSource = (String) 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 LiveMarketDataSpecification build() { return new LiveMarketDataSpecification( _dataSource); } //----------------------------------------------------------------------- /** * Sets the {@code dataSource} property in the builder. * @param dataSource the new value * @return this, for chaining, not null */ public Builder dataSource(String dataSource) { this._dataSource = dataSource; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("LiveMarketDataSpecification.Builder{"); buf.append("dataSource").append('=').append(JodaBeanUtils.toString(_dataSource)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }