4740 |
05 Feb 09 |
nicklas |
1 |
/** |
4740 |
05 Feb 09 |
nicklas |
$Id$ |
4740 |
05 Feb 09 |
nicklas |
3 |
|
4740 |
05 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4740 |
05 Feb 09 |
nicklas |
5 |
|
4740 |
05 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4740 |
05 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4740 |
05 Feb 09 |
nicklas |
8 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4740 |
05 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4740 |
05 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4740 |
05 Feb 09 |
nicklas |
13 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4740 |
05 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4740 |
05 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4740 |
05 Feb 09 |
nicklas |
GNU General Public License for more details. |
4740 |
05 Feb 09 |
nicklas |
18 |
|
4740 |
05 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4740 |
05 Feb 09 |
nicklas |
21 |
*/ |
4740 |
05 Feb 09 |
nicklas |
22 |
package net.sf.basedb.util.overview.cache; |
4740 |
05 Feb 09 |
nicklas |
23 |
|
5748 |
19 Sep 11 |
nicklas |
24 |
import net.sf.basedb.core.BasicItem; |
5748 |
19 Sep 11 |
nicklas |
25 |
|
4740 |
05 Feb 09 |
nicklas |
26 |
/** |
4768 |
18 Feb 09 |
nicklas |
Cache key implementation that bundles another cache key |
4768 |
18 Feb 09 |
nicklas |
with an index. This type of key is used when moving in |
5748 |
19 Sep 11 |
nicklas |
the reverse direction from a raw bioassay to physical bioassay |
5748 |
19 Sep 11 |
nicklas |
and extracts. The reason is that in this case only |
5748 |
19 Sep 11 |
nicklas |
the extract that belong to the raw bioassay should be loaded. |
5748 |
19 Sep 11 |
nicklas |
Thus, we also need different cache entries. |
4740 |
05 Feb 09 |
nicklas |
33 |
|
4740 |
05 Feb 09 |
nicklas |
@author Nicklas |
4740 |
05 Feb 09 |
nicklas |
@version 2.10 |
4740 |
05 Feb 09 |
nicklas |
@base.modified $Date$ |
4768 |
18 Feb 09 |
nicklas |
37 |
*/ |
4740 |
05 Feb 09 |
nicklas |
38 |
public class IndexedCacheKey |
4740 |
05 Feb 09 |
nicklas |
39 |
{ |
4768 |
18 Feb 09 |
nicklas |
40 |
private final Object cacheKey; |
4740 |
05 Feb 09 |
nicklas |
41 |
private final int index; |
4740 |
05 Feb 09 |
nicklas |
42 |
|
5748 |
19 Sep 11 |
nicklas |
43 |
/** |
5748 |
19 Sep 11 |
nicklas |
Create a cache key using the id of the BasicItem as the index. |
5748 |
19 Sep 11 |
nicklas |
@param cacheKey The parent cache key |
5748 |
19 Sep 11 |
nicklas |
@param item A BasicItem or null (0 is used as index) |
5748 |
19 Sep 11 |
nicklas |
47 |
*/ |
5748 |
19 Sep 11 |
nicklas |
48 |
public IndexedCacheKey(Object cacheKey, BasicItem item) |
5748 |
19 Sep 11 |
nicklas |
49 |
{ |
5748 |
19 Sep 11 |
nicklas |
50 |
this(cacheKey, item == null ? 0 : item.getId()); |
5748 |
19 Sep 11 |
nicklas |
51 |
} |
5748 |
19 Sep 11 |
nicklas |
52 |
|
4768 |
18 Feb 09 |
nicklas |
53 |
public IndexedCacheKey(Object cacheKey, int index) |
4740 |
05 Feb 09 |
nicklas |
54 |
{ |
4768 |
18 Feb 09 |
nicklas |
55 |
this.cacheKey = cacheKey; |
4740 |
05 Feb 09 |
nicklas |
56 |
this.index = index; |
4740 |
05 Feb 09 |
nicklas |
57 |
} |
4740 |
05 Feb 09 |
nicklas |
58 |
|
4768 |
18 Feb 09 |
nicklas |
59 |
/** |
4768 |
18 Feb 09 |
nicklas |
Get the original cache key passed to the constructor. |
4768 |
18 Feb 09 |
nicklas |
61 |
*/ |
4768 |
18 Feb 09 |
nicklas |
62 |
public Object unwrap() |
4768 |
18 Feb 09 |
nicklas |
63 |
{ |
4768 |
18 Feb 09 |
nicklas |
64 |
return cacheKey; |
4768 |
18 Feb 09 |
nicklas |
65 |
} |
4768 |
18 Feb 09 |
nicklas |
66 |
|
4740 |
05 Feb 09 |
nicklas |
67 |
@Override |
4740 |
05 Feb 09 |
nicklas |
68 |
public boolean equals(Object obj) |
4740 |
05 Feb 09 |
nicklas |
69 |
{ |
4740 |
05 Feb 09 |
nicklas |
70 |
if (this == obj) return true; |
4740 |
05 Feb 09 |
nicklas |
71 |
if (obj == null) return false; |
4740 |
05 Feb 09 |
nicklas |
72 |
if (obj.getClass() != this.getClass()) return false; |
4740 |
05 Feb 09 |
nicklas |
73 |
IndexedCacheKey other = (IndexedCacheKey)obj; |
4768 |
18 Feb 09 |
nicklas |
74 |
return this.index == other.index && this.cacheKey.equals(other.cacheKey); |
4740 |
05 Feb 09 |
nicklas |
75 |
} |
4740 |
05 Feb 09 |
nicklas |
76 |
|
4740 |
05 Feb 09 |
nicklas |
77 |
@Override |
4740 |
05 Feb 09 |
nicklas |
78 |
public int hashCode() |
4740 |
05 Feb 09 |
nicklas |
79 |
{ |
4768 |
18 Feb 09 |
nicklas |
80 |
return cacheKey.hashCode() * 7 + index; |
4740 |
05 Feb 09 |
nicklas |
81 |
} |
4740 |
05 Feb 09 |
nicklas |
82 |
|
4740 |
05 Feb 09 |
nicklas |
83 |
} |