[1040] | 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 |
|
---|
[1030] | 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 |
|
---|
[1040] | 23 | /**
|
---|
| 24 | * <p>
|
---|
| 25 | * TODO comment
|
---|
| 26 | * </p>
|
---|
| 27 | *
|
---|
| 28 | * @author Alexander Deicke
|
---|
| 29 | */
|
---|
[1030] | 30 | public class FilterStatisticCache {
|
---|
| 31 |
|
---|
| 32 | private static final FilterStatisticCache instance = new FilterStatisticCache();
|
---|
[1040] | 33 |
|
---|
[1030] | 34 | @SuppressWarnings("rawtypes")
|
---|
| 35 | private Cache<TaskTreeNodeFilter, FilterStatistic> cache;
|
---|
[1040] | 36 |
|
---|
[1030] | 37 | private FilterStatisticCache() {
|
---|
| 38 | this.cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build();
|
---|
| 39 | }
|
---|
[1040] | 40 |
|
---|
[1030] | 41 | public static FilterStatisticCache instance() {
|
---|
| 42 | return instance;
|
---|
| 43 | }
|
---|
[1040] | 44 |
|
---|
[1030] | 45 | @SuppressWarnings("rawtypes")
|
---|
| 46 | public void addFilterStatistic(TaskTreeNodeFilter nodeFilter, FilterStatistic filterStatistic) {
|
---|
| 47 | this.cache.put(nodeFilter, filterStatistic);
|
---|
| 48 | }
|
---|
[1040] | 49 |
|
---|
[1030] | 50 | @SuppressWarnings("rawtypes")
|
---|
| 51 | public Optional<FilterStatistic> getFilterStatistic(TaskTreeNodeFilter nodeFilter) {
|
---|
| 52 | return Optional.fromNullable(this.cache.getIfPresent(nodeFilter));
|
---|
| 53 | }
|
---|
[1040] | 54 |
|
---|
[1030] | 55 | public void clear() {
|
---|
| 56 | this.cache.invalidateAll();
|
---|
| 57 | }
|
---|
[1040] | 58 |
|
---|
[1030] | 59 | }
|
---|