source: src/main/java/genius/core/analysis/BidSpaceCache.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.4 KB
Line 
1package genius.core.analysis;
2
3import java.util.Arrays;
4
5import genius.core.utility.AbstractUtilitySpace;
6
7/**
8 * Caches the BidSpace such that we don't have to recompute it each time. Only
9 * one BidSpace can be stored at a time to limit the memory costs.
10 *
11 * @author Mark Hendrikx
12 */
13public class BidSpaceCache {
14
15 /** String representation of the stored domains. */
16 private static String[] identifier;
17 /** Reference to the cached BidSpace. */
18 private static BidSpace cachedBidSpace;
19
20 /**
21 * Method used to load a BidSpace. If the BidSpace is already cached, then
22 * the cached BidSpace is used. Otherwise, the BidSpace is constructed.
23 *
24 * @param spaces
25 * from which a BidSpace must be constructed.
26 * @return BidSpace belonging to the given UtilitySpace's.
27 */
28 public static BidSpace getBidSpace(AbstractUtilitySpace... spaces) {
29 // determine the unique identifier of the given utilityspaces.
30 String[] ident = new String[spaces.length];
31 for (int i = 0; i < spaces.length; i++) {
32 ident[i] = spaces[i].getFileName();
33 }
34
35 // check if the space is already cached. If not, createFrom bidspace.
36 if (!Arrays.equals(ident, identifier)) {
37 try {
38 cachedBidSpace = new BidSpace(spaces);
39 identifier = ident;
40 } catch (Exception e) {
41 e.printStackTrace();
42 }
43 }
44 return cachedBidSpace;
45 }
46}
Note: See TracBrowser for help on using the repository browser.