blob: cd254717aa8e92e15763bd54df466efa5306f634 (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package com.mapswithme.maps.bookmarks.data;
import android.support.annotation.NonNull;
import com.mapswithme.util.Predicate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public interface FilterStrategy
{
@NonNull
List<BookmarkCategory> filter(@NonNull List<BookmarkCategory> items);
class All implements FilterStrategy
{
@NonNull
@Override
public List<BookmarkCategory> filter(@NonNull List<BookmarkCategory> items)
{
return items;
}
}
class Private extends PredicativeStrategy<Boolean>
{
public Private()
{
super(new Predicate.Equals<>(new BookmarkCategory.Downloaded(), false));
}
}
class Downloaded extends PredicativeStrategy<Boolean>
{
Downloaded()
{
super(new Predicate.Equals<>(new BookmarkCategory.Downloaded(), true));
}
}
class PredicativeStrategy<T> implements FilterStrategy
{
@NonNull
private final Predicate<T, BookmarkCategory> mPredicate;
private PredicativeStrategy(@NonNull Predicate<T, BookmarkCategory> predicate)
{
mPredicate = predicate;
}
@NonNull
@Override
public List<BookmarkCategory> filter(@NonNull List<BookmarkCategory> items)
{
List<BookmarkCategory> result = new ArrayList<>();
for (BookmarkCategory each : items)
{
if (mPredicate.apply(each))
result.add(each);
}
return Collections.unmodifiableList(result);
}
@NonNull
public static FilterStrategy makeDownloadedInstance()
{
return new Downloaded();
}
@NonNull
public static FilterStrategy makePrivateInstance()
{
return new Private();
}
}
}
|