/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.collect.id; import java.io.Serializable; 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.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; /** * Simple bean for testing. */ @BeanDefinition public final class MockIdentifiable implements IdentifiableBean, Resolvable<MockIdentifiable>, ImmutableBean, Serializable { /** * Identifier of MOCK1. */ public static final StandardId STANDARD_ID_1 = StandardId.of("A", "1"); /** * Identifier of MOCK2. */ public static final StandardId STANDARD_ID_2 = StandardId.of("A", "2"); /** * Mock object. */ public static final MockIdentifiable MOCK1 = MockIdentifiable.builder() .standardId(STANDARD_ID_1) .name("Mock1") .build(); /** * Mock object. */ public static final MockIdentifiable MOCK2 = MockIdentifiable.builder() .standardId(STANDARD_ID_2) .name("Mock2") .build(); /** * Resolvable link to MOCK2. */ public static final StandardLink<MockIdentifiable> LINK_RESOLVABLE_MOCK2 = StandardLink.resolvable(STANDARD_ID_2, MockIdentifiable.class); /** * Resolved link to MOCK2. */ public static final StandardLink<MockIdentifiable> LINK_RESOLVED_MOCK2 = StandardLink.resolved(MOCK2); /** * Mock object with resolvable link. */ public static final MockIdentifiable MOCK1_LINKED_MOCK2 = MOCK1.toBuilder().link(LINK_RESOLVABLE_MOCK2).build(); /** * Mock object with resolved link. */ public static final MockIdentifiable MOCK1_RESOLVED_MOCK2 = MOCK1.toBuilder().link(LINK_RESOLVED_MOCK2).build(); @PropertyDefinition(validate = "notNull", overrideGet = true) private final StandardId standardId; @PropertyDefinition private final String name; @PropertyDefinition private final Link<MockIdentifiable> link; @Override public MockIdentifiable resolveLinks(LinkResolver resolver) { return resolver.resolveLinksIn(this, link, resolved -> toBuilder().link(resolved).build()); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code MockIdentifiable}. * @return the meta-bean, not null */ public static MockIdentifiable.Meta meta() { return MockIdentifiable.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(MockIdentifiable.Meta.INSTANCE); } /** * The serialization version id. */ private static final long serialVersionUID = 1L; /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static MockIdentifiable.Builder builder() { return new MockIdentifiable.Builder(); } private MockIdentifiable( StandardId standardId, String name, Link<MockIdentifiable> link) { JodaBeanUtils.notNull(standardId, "standardId"); this.standardId = standardId; this.name = name; this.link = link; } @Override public MockIdentifiable.Meta metaBean() { return MockIdentifiable.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 standardId. * @return the value of the property, not null */ @Override public StandardId getStandardId() { return standardId; } //----------------------------------------------------------------------- /** * Gets the name. * @return the value of the property */ public String getName() { return name; } //----------------------------------------------------------------------- /** * Gets the link. * @return the value of the property */ public Link<MockIdentifiable> getLink() { return link; } //----------------------------------------------------------------------- /** * 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()) { MockIdentifiable other = (MockIdentifiable) obj; return JodaBeanUtils.equal(getStandardId(), other.getStandardId()) && JodaBeanUtils.equal(getName(), other.getName()) && JodaBeanUtils.equal(getLink(), other.getLink()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getStandardId()); hash = hash * 31 + JodaBeanUtils.hashCode(getName()); hash = hash * 31 + JodaBeanUtils.hashCode(getLink()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("MockIdentifiable{"); buf.append("standardId").append('=').append(getStandardId()).append(',').append(' '); buf.append("name").append('=').append(getName()).append(',').append(' '); buf.append("link").append('=').append(JodaBeanUtils.toString(getLink())); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code MockIdentifiable}. */ 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 standardId} property. */ private final MetaProperty<StandardId> standardId = DirectMetaProperty.ofImmutable( this, "standardId", MockIdentifiable.class, StandardId.class); /** * The meta-property for the {@code name} property. */ private final MetaProperty<String> name = DirectMetaProperty.ofImmutable( this, "name", MockIdentifiable.class, String.class); /** * The meta-property for the {@code link} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Link<MockIdentifiable>> link = DirectMetaProperty.ofImmutable( this, "link", MockIdentifiable.class, (Class) Link.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "standardId", "name", "link"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1284477768: // standardId return standardId; case 3373707: // name return name; case 3321850: // link return link; } return super.metaPropertyGet(propertyName); } @Override public MockIdentifiable.Builder builder() { return new MockIdentifiable.Builder(); } @Override public Class<? extends MockIdentifiable> beanType() { return MockIdentifiable.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code standardId} property. * @return the meta-property, not null */ public MetaProperty<StandardId> standardId() { return standardId; } /** * The meta-property for the {@code name} property. * @return the meta-property, not null */ public MetaProperty<String> name() { return name; } /** * The meta-property for the {@code link} property. * @return the meta-property, not null */ public MetaProperty<Link<MockIdentifiable>> link() { return link; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1284477768: // standardId return ((MockIdentifiable) bean).getStandardId(); case 3373707: // name return ((MockIdentifiable) bean).getName(); case 3321850: // link return ((MockIdentifiable) bean).getLink(); } 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 MockIdentifiable}. */ public static final class Builder extends DirectFieldsBeanBuilder<MockIdentifiable> { private StandardId standardId; private String name; private Link<MockIdentifiable> link; /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(MockIdentifiable beanToCopy) { this.standardId = beanToCopy.getStandardId(); this.name = beanToCopy.getName(); this.link = beanToCopy.getLink(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case -1284477768: // standardId return standardId; case 3373707: // name return name; case 3321850: // link return link; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case -1284477768: // standardId this.standardId = (StandardId) newValue; break; case 3373707: // name this.name = (String) newValue; break; case 3321850: // link this.link = (Link<MockIdentifiable>) 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 MockIdentifiable build() { return new MockIdentifiable( standardId, name, link); } //----------------------------------------------------------------------- /** * Sets the {@code standardId} property in the builder. * @param standardId the new value, not null * @return this, for chaining, not null */ public Builder standardId(StandardId standardId) { JodaBeanUtils.notNull(standardId, "standardId"); this.standardId = standardId; return this; } /** * Sets the {@code name} property in the builder. * @param name the new value * @return this, for chaining, not null */ public Builder name(String name) { this.name = name; return this; } /** * Sets the {@code link} property in the builder. * @param link the new value * @return this, for chaining, not null */ public Builder link(Link<MockIdentifiable> link) { this.link = link; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("MockIdentifiable.Builder{"); buf.append("standardId").append('=').append(JodaBeanUtils.toString(standardId)).append(',').append(' '); buf.append("name").append('=').append(JodaBeanUtils.toString(name)).append(',').append(' '); buf.append("link").append('=').append(JodaBeanUtils.toString(link)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }