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 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.tasktree.filter;
|
---|
16 |
|
---|
17 | import java.util.concurrent.TimeUnit;
|
---|
18 |
|
---|
19 | import com.google.common.base.Optional;
|
---|
20 | import com.google.common.cache.Cache;
|
---|
21 | import com.google.common.cache.CacheBuilder;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * <p>
|
---|
25 | * TODO comment
|
---|
26 | * </p>
|
---|
27 | *
|
---|
28 | * @author Alexander Deicke
|
---|
29 | */
|
---|
30 | public 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 | }
|
---|