src/core/net/sf/basedb/util/overview/cache/IndexedCacheKey.java

Code
Comments
Other
Rev Date Author Line
4740 05 Feb 09 nicklas 1 /**
4740 05 Feb 09 nicklas 2   $Id$
4740 05 Feb 09 nicklas 3
4740 05 Feb 09 nicklas 4   Copyright (C) 2008 Nicklas Nordborg
4740 05 Feb 09 nicklas 5
4740 05 Feb 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4740 05 Feb 09 nicklas 7   Available at http://base.thep.lu.se/
4740 05 Feb 09 nicklas 8
4740 05 Feb 09 nicklas 9   BASE is free software; you can redistribute it and/or
4740 05 Feb 09 nicklas 10   modify it under the terms of the GNU General Public License
4740 05 Feb 09 nicklas 11   as published by the Free Software Foundation; either version 3
4740 05 Feb 09 nicklas 12   of the License, or (at your option) any later version.
4740 05 Feb 09 nicklas 13
4740 05 Feb 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4740 05 Feb 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4740 05 Feb 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4740 05 Feb 09 nicklas 17   GNU General Public License for more details.
4740 05 Feb 09 nicklas 18
4740 05 Feb 09 nicklas 19   You should have received a copy of the GNU General Public License
4740 05 Feb 09 nicklas 20   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 27   Cache key implementation that bundles another cache key
4768 18 Feb 09 nicklas 28   with an index. This type of key is used when moving in
5748 19 Sep 11 nicklas 29   the reverse direction from a raw bioassay to physical bioassay
5748 19 Sep 11 nicklas 30   and extracts. The reason is that in this case only
5748 19 Sep 11 nicklas 31   the extract that belong to the raw bioassay should be loaded. 
5748 19 Sep 11 nicklas 32   Thus, we also need different cache entries.
4740 05 Feb 09 nicklas 33
4740 05 Feb 09 nicklas 34   @author Nicklas
4740 05 Feb 09 nicklas 35   @version 2.10
4740 05 Feb 09 nicklas 36   @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 44     Create a cache key using the id of the BasicItem as the index.
5748 19 Sep 11 nicklas 45     @param cacheKey The parent cache key
5748 19 Sep 11 nicklas 46     @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 60     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 }