4766 |
17 Feb 09 |
nicklas |
1 |
/** |
4766 |
17 Feb 09 |
nicklas |
$Id$ |
4766 |
17 Feb 09 |
nicklas |
3 |
|
4766 |
17 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4766 |
17 Feb 09 |
nicklas |
5 |
|
4766 |
17 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4766 |
17 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4766 |
17 Feb 09 |
nicklas |
8 |
|
4766 |
17 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4766 |
17 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4766 |
17 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4766 |
17 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4766 |
17 Feb 09 |
nicklas |
13 |
|
4766 |
17 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4766 |
17 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4766 |
17 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4766 |
17 Feb 09 |
nicklas |
GNU General Public License for more details. |
4766 |
17 Feb 09 |
nicklas |
18 |
|
4766 |
17 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4766 |
17 Feb 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4766 |
17 Feb 09 |
nicklas |
21 |
*/ |
4766 |
17 Feb 09 |
nicklas |
22 |
package net.sf.basedb.util.overview.cache; |
4766 |
17 Feb 09 |
nicklas |
23 |
|
4766 |
17 Feb 09 |
nicklas |
24 |
import net.sf.basedb.util.overview.node.ChildNodeDirection; |
4766 |
17 Feb 09 |
nicklas |
25 |
|
4766 |
17 Feb 09 |
nicklas |
26 |
/** |
4766 |
17 Feb 09 |
nicklas |
Cache key implementation that bundles another cache key |
4766 |
17 Feb 09 |
nicklas |
with a node direction. The reason is that the node |
4766 |
17 Feb 09 |
nicklas |
tree looks very different for the same item depending |
4766 |
17 Feb 09 |
nicklas |
on the direction the item is loaded. |
4766 |
17 Feb 09 |
nicklas |
31 |
|
4766 |
17 Feb 09 |
nicklas |
@author Nicklas |
4766 |
17 Feb 09 |
nicklas |
@version 2.10 |
4766 |
17 Feb 09 |
nicklas |
@base.modified $Date$ |
4768 |
18 Feb 09 |
nicklas |
35 |
*/ |
4766 |
17 Feb 09 |
nicklas |
36 |
public class DirectionalCacheKey |
4766 |
17 Feb 09 |
nicklas |
37 |
{ |
4766 |
17 Feb 09 |
nicklas |
38 |
private final Object cacheKey; |
4766 |
17 Feb 09 |
nicklas |
39 |
private final ChildNodeDirection direction; |
4766 |
17 Feb 09 |
nicklas |
40 |
|
4766 |
17 Feb 09 |
nicklas |
41 |
public DirectionalCacheKey(Object cacheKey, ChildNodeDirection direction) |
4766 |
17 Feb 09 |
nicklas |
42 |
{ |
4766 |
17 Feb 09 |
nicklas |
43 |
this.cacheKey = cacheKey; |
4766 |
17 Feb 09 |
nicklas |
44 |
this.direction = direction; |
4766 |
17 Feb 09 |
nicklas |
45 |
} |
4766 |
17 Feb 09 |
nicklas |
46 |
|
4768 |
18 Feb 09 |
nicklas |
47 |
/** |
4768 |
18 Feb 09 |
nicklas |
Get the original cache key passed to the constructor. |
4768 |
18 Feb 09 |
nicklas |
49 |
*/ |
4768 |
18 Feb 09 |
nicklas |
50 |
public Object unwrap() |
4768 |
18 Feb 09 |
nicklas |
51 |
{ |
4768 |
18 Feb 09 |
nicklas |
52 |
return cacheKey; |
4768 |
18 Feb 09 |
nicklas |
53 |
} |
4768 |
18 Feb 09 |
nicklas |
54 |
|
4766 |
17 Feb 09 |
nicklas |
55 |
@Override |
4766 |
17 Feb 09 |
nicklas |
56 |
public boolean equals(Object obj) |
4766 |
17 Feb 09 |
nicklas |
57 |
{ |
4766 |
17 Feb 09 |
nicklas |
58 |
if (this == obj) return true; |
4766 |
17 Feb 09 |
nicklas |
59 |
if (obj == null) return false; |
4766 |
17 Feb 09 |
nicklas |
60 |
if (obj.getClass() != this.getClass()) return false; |
4766 |
17 Feb 09 |
nicklas |
61 |
DirectionalCacheKey other = (DirectionalCacheKey)obj; |
4766 |
17 Feb 09 |
nicklas |
62 |
return this.direction == other.direction && this.cacheKey.equals(other.cacheKey); |
4766 |
17 Feb 09 |
nicklas |
63 |
} |
4766 |
17 Feb 09 |
nicklas |
64 |
|
4766 |
17 Feb 09 |
nicklas |
65 |
@Override |
4766 |
17 Feb 09 |
nicklas |
66 |
public int hashCode() |
4766 |
17 Feb 09 |
nicklas |
67 |
{ |
4766 |
17 Feb 09 |
nicklas |
68 |
return cacheKey.hashCode() * 7 + direction.ordinal(); |
4766 |
17 Feb 09 |
nicklas |
69 |
} |
4766 |
17 Feb 09 |
nicklas |
70 |
|
4766 |
17 Feb 09 |
nicklas |
71 |
} |