/** * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.sesame.engine; import java.util.ArrayList; import java.util.Arrays; import java.util.List; 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.google.common.collect.ImmutableList; import com.opengamma.util.ArgumentChecker; /** * */ @BeanDefinition public final class ResultRow implements ImmutableBean { @PropertyDefinition(validate = "notNull") private final Object _input; @PropertyDefinition(validate = "notNull") private final List<ResultItem> _items; @ImmutableConstructor /* package */ ResultRow(Object input, List<ResultItem> items) { _input = ArgumentChecker.notNull(input, "input"); _items = ImmutableList.copyOf(ArgumentChecker.notNull(items, "items")); } public ResultItem get(int columnIndex) { if (columnIndex < 0 || columnIndex >= _items.size()) { throw new IndexOutOfBoundsException("Index " + columnIndex + " is out of bounds. column count = " + _items.size()); } return _items.get(columnIndex); } @Override public String toString() { return "ResultRow [_input=" + _input + ", _items=" + _items + "]"; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code ResultRow}. * @return the meta-bean, not null */ public static ResultRow.Meta meta() { return ResultRow.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(ResultRow.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static ResultRow.Builder builder() { return new ResultRow.Builder(); } @Override public ResultRow.Meta metaBean() { return ResultRow.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 input. * @return the value of the property, not null */ public Object getInput() { return _input; } //----------------------------------------------------------------------- /** * Gets the items. * @return the value of the property, not null */ public List<ResultItem> getItems() { return _items; } //----------------------------------------------------------------------- /** * 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()) { ResultRow other = (ResultRow) obj; return JodaBeanUtils.equal(getInput(), other.getInput()) && JodaBeanUtils.equal(getItems(), other.getItems()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getInput()); hash = hash * 31 + JodaBeanUtils.hashCode(getItems()); return hash; } //----------------------------------------------------------------------- /** * The meta-bean for {@code ResultRow}. */ 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 input} property. */ private final MetaProperty<Object> _input = DirectMetaProperty.ofImmutable( this, "input", ResultRow.class, Object.class); /** * The meta-property for the {@code items} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<List<ResultItem>> _items = DirectMetaProperty.ofImmutable( this, "items", ResultRow.class, (Class) List.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "input", "items"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 100358090: // input return _input; case 100526016: // items return _items; } return super.metaPropertyGet(propertyName); } @Override public ResultRow.Builder builder() { return new ResultRow.Builder(); } @Override public Class<? extends ResultRow> beanType() { return ResultRow.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code input} property. * @return the meta-property, not null */ public MetaProperty<Object> input() { return _input; } /** * The meta-property for the {@code items} property. * @return the meta-property, not null */ public MetaProperty<List<ResultItem>> items() { return _items; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100358090: // input return ((ResultRow) bean).getInput(); case 100526016: // items return ((ResultRow) bean).getItems(); } 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 ResultRow}. */ public static final class Builder extends DirectFieldsBeanBuilder<ResultRow> { private Object _input; private List<ResultItem> _items = new ArrayList<ResultItem>(); /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResultRow beanToCopy) { this._input = beanToCopy.getInput(); this._items = new ArrayList<ResultItem>(beanToCopy.getItems()); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case 100358090: // input return _input; case 100526016: // items return _items; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case 100358090: // input this._input = (Object) newValue; break; case 100526016: // items this._items = (List<ResultItem>) 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 ResultRow build() { return new ResultRow( _input, _items); } //----------------------------------------------------------------------- /** * Sets the {@code input} property in the builder. * @param input the new value, not null * @return this, for chaining, not null */ public Builder input(Object input) { JodaBeanUtils.notNull(input, "input"); this._input = input; return this; } /** * Sets the {@code items} property in the builder. * @param items the new value, not null * @return this, for chaining, not null */ public Builder items(List<ResultItem> items) { JodaBeanUtils.notNull(items, "items"); this._items = items; return this; } /** * Sets the {@code items} property in the builder * from an array of objects. * @param items the new value, not null * @return this, for chaining, not null */ public Builder items(ResultItem... items) { return items(Arrays.asList(items)); } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("ResultRow.Builder{"); buf.append("input").append('=').append(JodaBeanUtils.toString(_input)).append(',').append(' '); buf.append("items").append('=').append(JodaBeanUtils.toString(_items)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }