1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2008 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.services.persistence.generic.dao;
18
19 import java.lang.reflect.Field;
20
21 /**
22 * This class is container for a collection containing object, holding both the instance and the field
23 * giving access to the collection.
24 * This container is used in the {@link AbstractIdentityFixer} to remember which collections has to be
25 * replaced in the 2-way merging.
26 *
27 * @svnLink $Revision: 3875 $;$Date: 2009-08-04 14:35:53 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/services/persistence/generic/dao/IdentityFixerCollectionField.java $
28 *
29 * @author Andreas Rueedlinger (ARR)
30 */
31 public class IdentityFixerCollectionField {
32 /** See corresponding getter for information. */
33 private Object m_instance;
34
35 /** See corresponding getter for information. */
36 private Field m_field;
37
38 /**
39 * Constructs a new collection field.
40 * @param instance the instance containing the collection.
41 * @param field the field containing the collection.
42 */
43 public IdentityFixerCollectionField(Object instance, Field field) {
44 assert instance != null;
45 assert field != null;
46 m_instance = instance;
47 m_field = field;
48 }
49
50 /**
51 * @return the contained instance.
52 */
53 public Object getInstance() {
54 return m_instance;
55 }
56
57 /**
58 * @return the contained field.
59 */
60 public Field getField() {
61 return m_field;
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 public int hashCode() {
67 return m_instance.getClass().hashCode() * 31 + m_field.hashCode();
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public boolean equals(Object o) {
73 if (this == o) {
74 return true;
75 } else if (o instanceof IdentityFixerCollectionField) {
76 IdentityFixerCollectionField idcf = (IdentityFixerCollectionField) o;
77 return m_instance == idcf.m_instance && m_field.equals(idcf.m_field);
78 } else {
79 return false;
80 }
81 }
82 }