/projects/OG-Master/src/com/opengamma/master/AbstractDocument.java

https://github.com/gsteri1/OG-Platform · Java · 428 lines · 203 code · 42 blank · 183 comment · 12 complexity · 7df733d21f3fc193150c9da373fea27f MD5 · raw file

  1. /**
  2. * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
  3. *
  4. * Please see distribution for license.
  5. */
  6. package com.opengamma.master;
  7. import java.util.Map;
  8. import javax.time.Instant;
  9. import org.joda.beans.BeanBuilder;
  10. import org.joda.beans.BeanDefinition;
  11. import org.joda.beans.JodaBeanUtils;
  12. import org.joda.beans.MetaProperty;
  13. import org.joda.beans.Property;
  14. import org.joda.beans.PropertyDefinition;
  15. import org.joda.beans.impl.direct.DirectBean;
  16. import org.joda.beans.impl.direct.DirectMetaBean;
  17. import org.joda.beans.impl.direct.DirectMetaProperty;
  18. import org.joda.beans.impl.direct.DirectMetaPropertyMap;
  19. import com.opengamma.id.MutableUniqueIdentifiable;
  20. import com.opengamma.id.ObjectId;
  21. import com.opengamma.id.ObjectIdentifiable;
  22. import com.opengamma.id.UniqueId;
  23. import com.opengamma.id.UniqueIdentifiable;
  24. import com.opengamma.util.PublicSPI;
  25. /**
  26. * A document used to pass into and out of a master.
  27. * <p>
  28. * This abstract class is intended for providing the standard design for documents
  29. * stored in a master.
  30. */
  31. @PublicSPI
  32. @BeanDefinition
  33. public abstract class AbstractDocument extends DirectBean
  34. implements UniqueIdentifiable, MutableUniqueIdentifiable, ObjectIdentifiable {
  35. /**
  36. * The start of an interval that the version of the document is accurate for.
  37. * This field is populated and managed by the master.
  38. */
  39. @PropertyDefinition
  40. private Instant _versionFromInstant;
  41. /**
  42. * The end of an interval that the version of the document is accurate for.
  43. * Null indicates this is the latest version.
  44. * This field is populated and managed by the master.
  45. */
  46. @PropertyDefinition
  47. private Instant _versionToInstant;
  48. /**
  49. * The start of an interval that the correction of the version of the document is accurate for.
  50. * This field is populated and managed by the master.
  51. */
  52. @PropertyDefinition
  53. private Instant _correctionFromInstant;
  54. /**
  55. * The end of an interval that the correction of the version of the document is accurate for.
  56. * Null indicates this is the latest correction.
  57. * This field is populated and managed by the master.
  58. */
  59. @PropertyDefinition
  60. private Instant _correctionToInstant;
  61. /**
  62. * Creates an instance.
  63. */
  64. public AbstractDocument() {
  65. }
  66. //-------------------------------------------------------------------------
  67. /**
  68. * Gets the unique identifier of the document.
  69. * <p>
  70. * This may be derived from an object held within the document.
  71. *
  72. * @return the unique identifier, may be null, not null when returned from a query
  73. */
  74. @Override
  75. public abstract UniqueId getUniqueId();
  76. /**
  77. * Sets the unique identifier of the document.
  78. * <p>
  79. * This may be stored in an object held within the document.
  80. *
  81. * @param uniqueId the unique identifier, may be null
  82. */
  83. @Override
  84. public abstract void setUniqueId(UniqueId uniqueId);
  85. //-------------------------------------------------------------------------
  86. /**
  87. * Gets the object identifier of the document.
  88. * <p>
  89. * This may be derived from an object held within the document.
  90. *
  91. * @return the object identifier, may be null, not null when returned from a query
  92. */
  93. @Override
  94. public ObjectId getObjectId() {
  95. return getUniqueId().getObjectId();
  96. }
  97. //-------------------------------------------------------------------------
  98. /**
  99. * Checks if this is the latest version and correction of the document.
  100. * <p>
  101. * An earlier version, or a deleted document, will return false.
  102. *
  103. * @return true if this is the latest document version/correction
  104. */
  105. public boolean isLatest() {
  106. return getVersionToInstant() == null && getCorrectionToInstant() == null;
  107. }
  108. //------------------------- AUTOGENERATED START -------------------------
  109. ///CLOVER:OFF
  110. /**
  111. * The meta-bean for {@code AbstractDocument}.
  112. * @return the meta-bean, not null
  113. */
  114. public static AbstractDocument.Meta meta() {
  115. return AbstractDocument.Meta.INSTANCE;
  116. }
  117. static {
  118. JodaBeanUtils.registerMetaBean(AbstractDocument.Meta.INSTANCE);
  119. }
  120. @Override
  121. public AbstractDocument.Meta metaBean() {
  122. return AbstractDocument.Meta.INSTANCE;
  123. }
  124. @Override
  125. protected Object propertyGet(String propertyName, boolean quiet) {
  126. switch (propertyName.hashCode()) {
  127. case 2006263519: // versionFromInstant
  128. return getVersionFromInstant();
  129. case 1577022702: // versionToInstant
  130. return getVersionToInstant();
  131. case 1808757913: // correctionFromInstant
  132. return getCorrectionFromInstant();
  133. case 973465896: // correctionToInstant
  134. return getCorrectionToInstant();
  135. }
  136. return super.propertyGet(propertyName, quiet);
  137. }
  138. @Override
  139. protected void propertySet(String propertyName, Object newValue, boolean quiet) {
  140. switch (propertyName.hashCode()) {
  141. case 2006263519: // versionFromInstant
  142. setVersionFromInstant((Instant) newValue);
  143. return;
  144. case 1577022702: // versionToInstant
  145. setVersionToInstant((Instant) newValue);
  146. return;
  147. case 1808757913: // correctionFromInstant
  148. setCorrectionFromInstant((Instant) newValue);
  149. return;
  150. case 973465896: // correctionToInstant
  151. setCorrectionToInstant((Instant) newValue);
  152. return;
  153. }
  154. super.propertySet(propertyName, newValue, quiet);
  155. }
  156. @Override
  157. public boolean equals(Object obj) {
  158. if (obj == this) {
  159. return true;
  160. }
  161. if (obj != null && obj.getClass() == this.getClass()) {
  162. AbstractDocument other = (AbstractDocument) obj;
  163. return JodaBeanUtils.equal(getVersionFromInstant(), other.getVersionFromInstant()) &&
  164. JodaBeanUtils.equal(getVersionToInstant(), other.getVersionToInstant()) &&
  165. JodaBeanUtils.equal(getCorrectionFromInstant(), other.getCorrectionFromInstant()) &&
  166. JodaBeanUtils.equal(getCorrectionToInstant(), other.getCorrectionToInstant());
  167. }
  168. return false;
  169. }
  170. @Override
  171. public int hashCode() {
  172. int hash = getClass().hashCode();
  173. hash += hash * 31 + JodaBeanUtils.hashCode(getVersionFromInstant());
  174. hash += hash * 31 + JodaBeanUtils.hashCode(getVersionToInstant());
  175. hash += hash * 31 + JodaBeanUtils.hashCode(getCorrectionFromInstant());
  176. hash += hash * 31 + JodaBeanUtils.hashCode(getCorrectionToInstant());
  177. return hash;
  178. }
  179. //-----------------------------------------------------------------------
  180. /**
  181. * Gets the start of an interval that the version of the document is accurate for.
  182. * This field is populated and managed by the master.
  183. * @return the value of the property
  184. */
  185. public Instant getVersionFromInstant() {
  186. return _versionFromInstant;
  187. }
  188. /**
  189. * Sets the start of an interval that the version of the document is accurate for.
  190. * This field is populated and managed by the master.
  191. * @param versionFromInstant the new value of the property
  192. */
  193. public void setVersionFromInstant(Instant versionFromInstant) {
  194. this._versionFromInstant = versionFromInstant;
  195. }
  196. /**
  197. * Gets the the {@code versionFromInstant} property.
  198. * This field is populated and managed by the master.
  199. * @return the property, not null
  200. */
  201. public final Property<Instant> versionFromInstant() {
  202. return metaBean().versionFromInstant().createProperty(this);
  203. }
  204. //-----------------------------------------------------------------------
  205. /**
  206. * Gets the end of an interval that the version of the document is accurate for.
  207. * Null indicates this is the latest version.
  208. * This field is populated and managed by the master.
  209. * @return the value of the property
  210. */
  211. public Instant getVersionToInstant() {
  212. return _versionToInstant;
  213. }
  214. /**
  215. * Sets the end of an interval that the version of the document is accurate for.
  216. * Null indicates this is the latest version.
  217. * This field is populated and managed by the master.
  218. * @param versionToInstant the new value of the property
  219. */
  220. public void setVersionToInstant(Instant versionToInstant) {
  221. this._versionToInstant = versionToInstant;
  222. }
  223. /**
  224. * Gets the the {@code versionToInstant} property.
  225. * Null indicates this is the latest version.
  226. * This field is populated and managed by the master.
  227. * @return the property, not null
  228. */
  229. public final Property<Instant> versionToInstant() {
  230. return metaBean().versionToInstant().createProperty(this);
  231. }
  232. //-----------------------------------------------------------------------
  233. /**
  234. * Gets the start of an interval that the correction of the version of the document is accurate for.
  235. * This field is populated and managed by the master.
  236. * @return the value of the property
  237. */
  238. public Instant getCorrectionFromInstant() {
  239. return _correctionFromInstant;
  240. }
  241. /**
  242. * Sets the start of an interval that the correction of the version of the document is accurate for.
  243. * This field is populated and managed by the master.
  244. * @param correctionFromInstant the new value of the property
  245. */
  246. public void setCorrectionFromInstant(Instant correctionFromInstant) {
  247. this._correctionFromInstant = correctionFromInstant;
  248. }
  249. /**
  250. * Gets the the {@code correctionFromInstant} property.
  251. * This field is populated and managed by the master.
  252. * @return the property, not null
  253. */
  254. public final Property<Instant> correctionFromInstant() {
  255. return metaBean().correctionFromInstant().createProperty(this);
  256. }
  257. //-----------------------------------------------------------------------
  258. /**
  259. * Gets the end of an interval that the correction of the version of the document is accurate for.
  260. * Null indicates this is the latest correction.
  261. * This field is populated and managed by the master.
  262. * @return the value of the property
  263. */
  264. public Instant getCorrectionToInstant() {
  265. return _correctionToInstant;
  266. }
  267. /**
  268. * Sets the end of an interval that the correction of the version of the document is accurate for.
  269. * Null indicates this is the latest correction.
  270. * This field is populated and managed by the master.
  271. * @param correctionToInstant the new value of the property
  272. */
  273. public void setCorrectionToInstant(Instant correctionToInstant) {
  274. this._correctionToInstant = correctionToInstant;
  275. }
  276. /**
  277. * Gets the the {@code correctionToInstant} property.
  278. * Null indicates this is the latest correction.
  279. * This field is populated and managed by the master.
  280. * @return the property, not null
  281. */
  282. public final Property<Instant> correctionToInstant() {
  283. return metaBean().correctionToInstant().createProperty(this);
  284. }
  285. //-----------------------------------------------------------------------
  286. /**
  287. * The meta-bean for {@code AbstractDocument}.
  288. */
  289. public static class Meta extends DirectMetaBean {
  290. /**
  291. * The singleton instance of the meta-bean.
  292. */
  293. static final Meta INSTANCE = new Meta();
  294. /**
  295. * The meta-property for the {@code versionFromInstant} property.
  296. */
  297. private final MetaProperty<Instant> _versionFromInstant = DirectMetaProperty.ofReadWrite(
  298. this, "versionFromInstant", AbstractDocument.class, Instant.class);
  299. /**
  300. * The meta-property for the {@code versionToInstant} property.
  301. */
  302. private final MetaProperty<Instant> _versionToInstant = DirectMetaProperty.ofReadWrite(
  303. this, "versionToInstant", AbstractDocument.class, Instant.class);
  304. /**
  305. * The meta-property for the {@code correctionFromInstant} property.
  306. */
  307. private final MetaProperty<Instant> _correctionFromInstant = DirectMetaProperty.ofReadWrite(
  308. this, "correctionFromInstant", AbstractDocument.class, Instant.class);
  309. /**
  310. * The meta-property for the {@code correctionToInstant} property.
  311. */
  312. private final MetaProperty<Instant> _correctionToInstant = DirectMetaProperty.ofReadWrite(
  313. this, "correctionToInstant", AbstractDocument.class, Instant.class);
  314. /**
  315. * The meta-properties.
  316. */
  317. private final Map<String, MetaProperty<Object>> _map = new DirectMetaPropertyMap(
  318. this, null,
  319. "versionFromInstant",
  320. "versionToInstant",
  321. "correctionFromInstant",
  322. "correctionToInstant");
  323. /**
  324. * Restricted constructor.
  325. */
  326. protected Meta() {
  327. }
  328. @Override
  329. protected MetaProperty<?> metaPropertyGet(String propertyName) {
  330. switch (propertyName.hashCode()) {
  331. case 2006263519: // versionFromInstant
  332. return _versionFromInstant;
  333. case 1577022702: // versionToInstant
  334. return _versionToInstant;
  335. case 1808757913: // correctionFromInstant
  336. return _correctionFromInstant;
  337. case 973465896: // correctionToInstant
  338. return _correctionToInstant;
  339. }
  340. return super.metaPropertyGet(propertyName);
  341. }
  342. @Override
  343. public BeanBuilder<? extends AbstractDocument> builder() {
  344. throw new UnsupportedOperationException("AbstractDocument is an abstract class");
  345. }
  346. @Override
  347. public Class<? extends AbstractDocument> beanType() {
  348. return AbstractDocument.class;
  349. }
  350. @Override
  351. public Map<String, MetaProperty<Object>> metaPropertyMap() {
  352. return _map;
  353. }
  354. //-----------------------------------------------------------------------
  355. /**
  356. * The meta-property for the {@code versionFromInstant} property.
  357. * @return the meta-property, not null
  358. */
  359. public final MetaProperty<Instant> versionFromInstant() {
  360. return _versionFromInstant;
  361. }
  362. /**
  363. * The meta-property for the {@code versionToInstant} property.
  364. * @return the meta-property, not null
  365. */
  366. public final MetaProperty<Instant> versionToInstant() {
  367. return _versionToInstant;
  368. }
  369. /**
  370. * The meta-property for the {@code correctionFromInstant} property.
  371. * @return the meta-property, not null
  372. */
  373. public final MetaProperty<Instant> correctionFromInstant() {
  374. return _correctionFromInstant;
  375. }
  376. /**
  377. * The meta-property for the {@code correctionToInstant} property.
  378. * @return the meta-property, not null
  379. */
  380. public final MetaProperty<Instant> correctionToInstant() {
  381. return _correctionToInstant;
  382. }
  383. }
  384. ///CLOVER:ON
  385. //-------------------------- AUTOGENERATED END --------------------------
  386. }