/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.core.holiday.impl;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
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.DirectBean;
import org.joda.beans.impl.direct.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.threeten.bp.LocalDate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.opengamma.core.holiday.Holiday;
import com.opengamma.core.holiday.HolidayType;
import com.opengamma.id.ExternalId;
import com.opengamma.id.MutableUniqueIdentifiable;
import com.opengamma.id.UniqueId;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.money.Currency;
/**
* Simple implementation of {@code Holiday}.
* <p>
* This is the simplest possible implementation of the {@link Holiday} interface.
* <p>
* This class is mutable and not thread-safe.
* It is intended to be used in the engine via the read-only {@code Holiday} interface.
*/
@BeanDefinition
public class SimpleHoliday extends DirectBean
implements Holiday, MutableUniqueIdentifiable, Serializable {
/** Serialization version. */
private static final long serialVersionUID = 1L;
/**
* The unique identifier of the holiday.
*/
@PropertyDefinition(overrideGet = true, overrideSet = true)
private UniqueId _uniqueId;
/**
* The type of the holiday.
*/
@PropertyDefinition(overrideGet = true)
private HolidayType _type;
/**
* The region external identifier bundle, used when this is a holiday of type BANK.
* This must be null if the type is not BANK.
*/
@PropertyDefinition(overrideGet = true)
private ExternalId _regionExternalId;
/**
* The exchange external identifier bundle, used when this is a holiday of type SETTLEMENT or TRADING.
* This must be null if the type is not SETTLEMENT or TRADING.
*/
@PropertyDefinition(overrideGet = true)
private ExternalId _exchangeExternalId;
/**
* The custom external identifier bundle, used when this is a holiday of type CUSTOM.
* This must be null if the type is not CUSTOM.
*/
@PropertyDefinition(overrideGet = true)
private ExternalId _customExternalId;
/**
* The currency, used when this is a holiday of type CURRENCY.
* This must be null if the type is not CURRENCY.
*/
@PropertyDefinition(overrideGet = true)
private Currency _currency;
/**
* The list of dates that the target (currency/region/exchange) is on holiday, not null.
*/
@PropertyDefinition(overrideGet = true)
private final List<LocalDate> _holidayDates = Lists.newArrayList();
/**
* Creates an instance.
*/
public SimpleHoliday() {
}
/**
* Creates an instance populated with a set of dates.
*
* @param dates the dates to add, not null
*/
public SimpleHoliday(final Iterable<LocalDate> dates) {
addHolidayDates(dates);
}
//-------------------------------------------------------------------------
/**
* Adds a holiday date to the list.
*
* @param date the date to add, not null
*/
public void addHolidayDate(final LocalDate date) {
ArgumentChecker.notNull(date, "date");
if (_holidayDates.contains(date) == false) {
int index = Collections.binarySearch(_holidayDates, date);
index = (index < 0 ? -(index + 1) : index);
_holidayDates.add(index, date);
}
}
/**
* Adds a set of holiday dates to the list.
*
* @param dates the dates to add, not null
*/
public void addHolidayDates(final Iterable<LocalDate> dates) {
ArgumentChecker.notNull(dates, "dates");
Set<LocalDate> deduplicatedAdditions = new HashSet<>();
Iterables.addAll(deduplicatedAdditions, dates);
deduplicatedAdditions.removeAll(_holidayDates);
_holidayDates.addAll(deduplicatedAdditions);
Collections.sort(_holidayDates);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code SimpleHoliday}.
* @return the meta-bean, not null
*/
public static SimpleHoliday.Meta meta() {
return SimpleHoliday.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(SimpleHoliday.Meta.INSTANCE);
}
@Override
public SimpleHoliday.Meta metaBean() {
return SimpleHoliday.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the unique identifier of the holiday.
* @return the value of the property
*/
@Override
public UniqueId getUniqueId() {
return _uniqueId;
}
/**
* Sets the unique identifier of the holiday.
* @param uniqueId the new value of the property
*/
@Override
public void setUniqueId(UniqueId uniqueId) {
this._uniqueId = uniqueId;
}
/**
* Gets the the {@code uniqueId} property.
* @return the property, not null
*/
public final Property<UniqueId> uniqueId() {
return metaBean().uniqueId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the type of the holiday.
* @return the value of the property
*/
@Override
public HolidayType getType() {
return _type;
}
/**
* Sets the type of the holiday.
* @param type the new value of the property
*/
public void setType(HolidayType type) {
this._type = type;
}
/**
* Gets the the {@code type} property.
* @return the property, not null
*/
public final Property<HolidayType> type() {
return metaBean().type().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the region external identifier bundle, used when this is a holiday of type BANK.
* This must be null if the type is not BANK.
* @return the value of the property
*/
@Override
public ExternalId getRegionExternalId() {
return _regionExternalId;
}
/**
* Sets the region external identifier bundle, used when this is a holiday of type BANK.
* This must be null if the type is not BANK.
* @param regionExternalId the new value of the property
*/
public void setRegionExternalId(ExternalId regionExternalId) {
this._regionExternalId = regionExternalId;
}
/**
* Gets the the {@code regionExternalId} property.
* This must be null if the type is not BANK.
* @return the property, not null
*/
public final Property<ExternalId> regionExternalId() {
return metaBean().regionExternalId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the exchange external identifier bundle, used when this is a holiday of type SETTLEMENT or TRADING.
* This must be null if the type is not SETTLEMENT or TRADING.
* @return the value of the property
*/
@Override
public ExternalId getExchangeExternalId() {
return _exchangeExternalId;
}
/**
* Sets the exchange external identifier bundle, used when this is a holiday of type SETTLEMENT or TRADING.
* This must be null if the type is not SETTLEMENT or TRADING.
* @param exchangeExternalId the new value of the property
*/
public void setExchangeExternalId(ExternalId exchangeExternalId) {
this._exchangeExternalId = exchangeExternalId;
}
/**
* Gets the the {@code exchangeExternalId} property.
* This must be null if the type is not SETTLEMENT or TRADING.
* @return the property, not null
*/
public final Property<ExternalId> exchangeExternalId() {
return metaBean().exchangeExternalId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the custom external identifier bundle, used when this is a holiday of type CUSTOM.
* This must be null if the type is not CUSTOM.
* @return the value of the property
*/
@Override
public ExternalId getCustomExternalId() {
return _customExternalId;
}
/**
* Sets the custom external identifier bundle, used when this is a holiday of type CUSTOM.
* This must be null if the type is not CUSTOM.
* @param customExternalId the new value of the property
*/
public void setCustomExternalId(ExternalId customExternalId) {
this._customExternalId = customExternalId;
}
/**
* Gets the the {@code customExternalId} property.
* This must be null if the type is not CUSTOM.
* @return the property, not null
*/
public final Property<ExternalId> customExternalId() {
return metaBean().customExternalId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the currency, used when this is a holiday of type CURRENCY.
* This must be null if the type is not CURRENCY.
* @return the value of the property
*/
@Override
public Currency getCurrency() {
return _currency;
}
/**
* Sets the currency, used when this is a holiday of type CURRENCY.
* This must be null if the type is not CURRENCY.
* @param currency the new value of the property
*/
public void setCurrency(Currency currency) {
this._currency = currency;
}
/**
* Gets the the {@code currency} property.
* This must be null if the type is not CURRENCY.
* @return the property, not null
*/
public final Property<Currency> currency() {
return metaBean().currency().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the list of dates that the target (currency/region/exchange) is on holiday, not null.
* @return the value of the property, not null
*/
@Override
public List<LocalDate> getHolidayDates() {
return _holidayDates;
}
/**
* Sets the list of dates that the target (currency/region/exchange) is on holiday, not null.
* @param holidayDates the new value of the property, not null
*/
public void setHolidayDates(List<LocalDate> holidayDates) {
JodaBeanUtils.notNull(holidayDates, "holidayDates");
this._holidayDates.clear();
this._holidayDates.addAll(holidayDates);
}
/**
* Gets the the {@code holidayDates} property.
* @return the property, not null
*/
public final Property<List<LocalDate>> holidayDates() {
return metaBean().holidayDates().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public SimpleHoliday clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
SimpleHoliday other = (SimpleHoliday) obj;
return JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) &&
JodaBeanUtils.equal(getType(), other.getType()) &&
JodaBeanUtils.equal(getRegionExternalId(), other.getRegionExternalId()) &&
JodaBeanUtils.equal(getExchangeExternalId(), other.getExchangeExternalId()) &&
JodaBeanUtils.equal(getCustomExternalId(), other.getCustomExternalId()) &&
JodaBeanUtils.equal(getCurrency(), other.getCurrency()) &&
JodaBeanUtils.equal(getHolidayDates(), other.getHolidayDates());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getUniqueId());
hash = hash * 31 + JodaBeanUtils.hashCode(getType());
hash = hash * 31 + JodaBeanUtils.hashCode(getRegionExternalId());
hash = hash * 31 + JodaBeanUtils.hashCode(getExchangeExternalId());
hash = hash * 31 + JodaBeanUtils.hashCode(getCustomExternalId());
hash = hash * 31 + JodaBeanUtils.hashCode(getCurrency());
hash = hash * 31 + JodaBeanUtils.hashCode(getHolidayDates());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(256);
buf.append("SimpleHoliday{");
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("uniqueId").append('=').append(JodaBeanUtils.toString(getUniqueId())).append(',').append(' ');
buf.append("type").append('=').append(JodaBeanUtils.toString(getType())).append(',').append(' ');
buf.append("regionExternalId").append('=').append(JodaBeanUtils.toString(getRegionExternalId())).append(',').append(' ');
buf.append("exchangeExternalId").append('=').append(JodaBeanUtils.toString(getExchangeExternalId())).append(',').append(' ');
buf.append("customExternalId").append('=').append(JodaBeanUtils.toString(getCustomExternalId())).append(',').append(' ');
buf.append("currency").append('=').append(JodaBeanUtils.toString(getCurrency())).append(',').append(' ');
buf.append("holidayDates").append('=').append(JodaBeanUtils.toString(getHolidayDates())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code SimpleHoliday}.
*/
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 uniqueId} property.
*/
private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofReadWrite(
this, "uniqueId", SimpleHoliday.class, UniqueId.class);
/**
* The meta-property for the {@code type} property.
*/
private final MetaProperty<HolidayType> _type = DirectMetaProperty.ofReadWrite(
this, "type", SimpleHoliday.class, HolidayType.class);
/**
* The meta-property for the {@code regionExternalId} property.
*/
private final MetaProperty<ExternalId> _regionExternalId = DirectMetaProperty.ofReadWrite(
this, "regionExternalId", SimpleHoliday.class, ExternalId.class);
/**
* The meta-property for the {@code exchangeExternalId} property.
*/
private final MetaProperty<ExternalId> _exchangeExternalId = DirectMetaProperty.ofReadWrite(
this, "exchangeExternalId", SimpleHoliday.class, ExternalId.class);
/**
* The meta-property for the {@code customExternalId} property.
*/
private final MetaProperty<ExternalId> _customExternalId = DirectMetaProperty.ofReadWrite(
this, "customExternalId", SimpleHoliday.class, ExternalId.class);
/**
* The meta-property for the {@code currency} property.
*/
private final MetaProperty<Currency> _currency = DirectMetaProperty.ofReadWrite(
this, "currency", SimpleHoliday.class, Currency.class);
/**
* The meta-property for the {@code holidayDates} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<LocalDate>> _holidayDates = DirectMetaProperty.ofReadWrite(
this, "holidayDates", SimpleHoliday.class, (Class) List.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"uniqueId",
"type",
"regionExternalId",
"exchangeExternalId",
"customExternalId",
"currency",
"holidayDates");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return _uniqueId;
case 3575610: // type
return _type;
case -62093222: // regionExternalId
return _regionExternalId;
case 323354825: // exchangeExternalId
return _exchangeExternalId;
case -1550240617: // customExternalId
return _customExternalId;
case 575402001: // currency
return _currency;
case -367347: // holidayDates
return _holidayDates;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends SimpleHoliday> builder() {
return new DirectBeanBuilder<SimpleHoliday>(new SimpleHoliday());
}
@Override
public Class<? extends SimpleHoliday> beanType() {
return SimpleHoliday.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code uniqueId} property.
* @return the meta-property, not null
*/
public final MetaProperty<UniqueId> uniqueId() {
return _uniqueId;
}
/**
* The meta-property for the {@code type} property.
* @return the meta-property, not null
*/
public final MetaProperty<HolidayType> type() {
return _type;
}
/**
* The meta-property for the {@code regionExternalId} property.
* @return the meta-property, not null
*/
public final MetaProperty<ExternalId> regionExternalId() {
return _regionExternalId;
}
/**
* The meta-property for the {@code exchangeExternalId} property.
* @return the meta-property, not null
*/
public final MetaProperty<ExternalId> exchangeExternalId() {
return _exchangeExternalId;
}
/**
* The meta-property for the {@code customExternalId} property.
* @return the meta-property, not null
*/
public final MetaProperty<ExternalId> customExternalId() {
return _customExternalId;
}
/**
* The meta-property for the {@code currency} property.
* @return the meta-property, not null
*/
public final MetaProperty<Currency> currency() {
return _currency;
}
/**
* The meta-property for the {@code holidayDates} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<LocalDate>> holidayDates() {
return _holidayDates;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return ((SimpleHoliday) bean).getUniqueId();
case 3575610: // type
return ((SimpleHoliday) bean).getType();
case -62093222: // regionExternalId
return ((SimpleHoliday) bean).getRegionExternalId();
case 323354825: // exchangeExternalId
return ((SimpleHoliday) bean).getExchangeExternalId();
case -1550240617: // customExternalId
return ((SimpleHoliday) bean).getCustomExternalId();
case 575402001: // currency
return ((SimpleHoliday) bean).getCurrency();
case -367347: // holidayDates
return ((SimpleHoliday) bean).getHolidayDates();
}
return super.propertyGet(bean, propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
((SimpleHoliday) bean).setUniqueId((UniqueId) newValue);
return;
case 3575610: // type
((SimpleHoliday) bean).setType((HolidayType) newValue);
return;
case -62093222: // regionExternalId
((SimpleHoliday) bean).setRegionExternalId((ExternalId) newValue);
return;
case 323354825: // exchangeExternalId
((SimpleHoliday) bean).setExchangeExternalId((ExternalId) newValue);
return;
case -1550240617: // customExternalId
((SimpleHoliday) bean).setCustomExternalId((ExternalId) newValue);
return;
case 575402001: // currency
((SimpleHoliday) bean).setCurrency((Currency) newValue);
return;
case -367347: // holidayDates
((SimpleHoliday) bean).setHolidayDates((List<LocalDate>) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((SimpleHoliday) bean)._holidayDates, "holidayDates");
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}