/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.master.user; import java.util.ArrayList; 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.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.google.common.collect.Ordering; /** * Result providing the event history of a single object in a master. * <p> * When a master is queried for event history, this class is used to return the result. * It stores a list of events, in chronological order, representing changes that were made. * This approach to history is used by those masters that do not require bi-temporal versioning. */ @BeanDefinition public abstract class EventHistoryResult implements Bean { /** * The event history, sorted from oldest to newest. */ @PropertyDefinition private final List<HistoryEvent> _events = new ArrayList<>(); /** * Creates an instance. */ protected EventHistoryResult() { } /** * Creates an instance. * <p> * The result will be sorted even if the input is not. * * @param events the history events, not null */ protected EventHistoryResult(Iterable<HistoryEvent> events) { JodaBeanUtils.notNull(events, "history"); _events.addAll(Ordering.<HistoryEvent>natural().sortedCopy(events)); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code EventHistoryResult}. * @return the meta-bean, not null */ public static EventHistoryResult.Meta meta() { return EventHistoryResult.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(EventHistoryResult.Meta.INSTANCE); } @Override public EventHistoryResult.Meta metaBean() { return EventHistoryResult.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 event history, sorted from oldest to newest. * @return the value of the property, not null */ public List<HistoryEvent> getEvents() { return _events; } /** * Sets the event history, sorted from oldest to newest. * @param events the new value of the property, not null */ public void setEvents(List<HistoryEvent> events) { JodaBeanUtils.notNull(events, "events"); this._events.clear(); this._events.addAll(events); } /** * Gets the the {@code events} property. * @return the property, not null */ public final Property<List<HistoryEvent>> events() { return metaBean().events().createProperty(this); } //----------------------------------------------------------------------- @Override public EventHistoryResult clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { EventHistoryResult other = (EventHistoryResult) obj; return JodaBeanUtils.equal(getEvents(), other.getEvents()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getEvents()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("EventHistoryResult{"); 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("events").append('=').append(JodaBeanUtils.toString(getEvents())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code EventHistoryResult}. */ 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 events} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<List<HistoryEvent>> _events = DirectMetaProperty.ofReadWrite( this, "events", EventHistoryResult.class, (Class) List.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "events"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1291329255: // events return _events; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends EventHistoryResult> builder() { throw new UnsupportedOperationException("EventHistoryResult is an abstract class"); } @Override public Class<? extends EventHistoryResult> beanType() { return EventHistoryResult.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code events} property. * @return the meta-property, not null */ public final MetaProperty<List<HistoryEvent>> events() { return _events; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1291329255: // events return ((EventHistoryResult) bean).getEvents(); } return super.propertyGet(bean, propertyName, quiet); } @SuppressWarnings("unchecked") @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -1291329255: // events ((EventHistoryResult) bean).setEvents((List<HistoryEvent>) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((EventHistoryResult) bean)._events, "events"); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }