aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/filter/TypeFilter.java
blob: ea0ccff94e4158c5ad4407933771928a71b5c112 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cgeo.geocaching.filter;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.CacheType;

import java.util.LinkedList;
import java.util.List;

class TypeFilter extends AbstractFilter {
    private final CacheType cacheType;

    public TypeFilter(final CacheType cacheType) {
        super(cacheType.id);
        this.cacheType = cacheType;
    }

    @Override
    public boolean accepts(final Geocache cache) {
        return cacheType == cache.getType();
    }

    @Override
    public String getName() {
        return cacheType.getL10n();
    }

    public static class Factory implements IFilterFactory {

        @Override
        public List<IFilter> getFilters() {
            final CacheType[] types = CacheType.values();
            final List<IFilter> filters = new LinkedList<IFilter>();
            for (CacheType cacheType : types) {
                if (cacheType != CacheType.ALL) {
                    filters.add(new TypeFilter(cacheType));
                }
            }
            return filters;
        }

    }
}