source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/tasktree/filter/FilterStatisticCache.java @ 1040

Last change on this file since 1040 was 1040, checked in by adeicke, 11 years ago
  • Removed lombok related annotations and util class
  • Added comments and formating due to match project defaults
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.usability.tasktree.filter;
16
17import java.util.concurrent.TimeUnit;
18
19import com.google.common.base.Optional;
20import com.google.common.cache.Cache;
21import com.google.common.cache.CacheBuilder;
22
23/**
24 * <p>
25 * TODO comment
26 * </p>
27 *
28 * @author Alexander Deicke
29 */
30public class FilterStatisticCache {
31
32    private static final FilterStatisticCache instance = new FilterStatisticCache();
33
34    @SuppressWarnings("rawtypes")
35    private Cache<TaskTreeNodeFilter, FilterStatistic> cache;
36
37    private FilterStatisticCache() {
38        this.cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build();
39    }
40
41    public static FilterStatisticCache instance() {
42        return instance;
43    }
44
45    @SuppressWarnings("rawtypes")
46    public void addFilterStatistic(TaskTreeNodeFilter nodeFilter, FilterStatistic filterStatistic) {
47        this.cache.put(nodeFilter, filterStatistic);
48    }
49
50    @SuppressWarnings("rawtypes")
51    public Optional<FilterStatistic> getFilterStatistic(TaskTreeNodeFilter nodeFilter) {
52        return Optional.fromNullable(this.cache.getIfPresent(nodeFilter));
53    }
54
55    public void clear() {
56        this.cache.invalidateAll();
57    }
58
59}
Note: See TracBrowser for help on using the repository browser.