/**
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.calc.marketdata;
import java.util.Set;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.light.LightMetaBean;
import com.opengamma.strata.basics.ReferenceData;
import com.opengamma.strata.data.MarketDataId;
import com.opengamma.strata.data.scenario.MarketDataBox;
/**
* A market data filter that matches a specific identifier.
*
* @param <T> the type of the market data handled by the filter
*/
@BeanDefinition(style = "light", constructorScope = "package")
final class IdFilter<T>
implements MarketDataFilter<T, MarketDataId<T>>, ImmutableBean {
/**
* The identifier that is matched by this filter.
*/
@PropertyDefinition(validate = "notNull")
private final MarketDataId<T> id;
//-------------------------------------------------------------------------
@Override
public Class<?> getMarketDataIdType() {
return id.getClass();
}
@Override
public boolean matches(MarketDataId<T> marketDataId, MarketDataBox<T> marketData, ReferenceData refData) {
return marketDataId.equals(id);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code IdFilter}.
*/
private static MetaBean META_BEAN = LightMetaBean.of(IdFilter.class);
/**
* The meta-bean for {@code IdFilter}.
* @return the meta-bean, not null
*/
public static MetaBean meta() {
return META_BEAN;
}
static {
JodaBeanUtils.registerMetaBean(META_BEAN);
}
/**
* Creates an instance.
* @param id the value of the property, not null
*/
IdFilter(
MarketDataId<T> id) {
JodaBeanUtils.notNull(id, "id");
this.id = id;
}
@Override
public MetaBean metaBean() {
return META_BEAN;
}
@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 identifier that is matched by this filter.
* @return the value of the property, not null
*/
public MarketDataId<T> getId() {
return id;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
IdFilter<?> other = (IdFilter<?>) obj;
return JodaBeanUtils.equal(id, other.id);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(id);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(64);
buf.append("IdFilter{");
buf.append("id").append('=').append(JodaBeanUtils.toString(id));
buf.append('}');
return buf.toString();
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}