1 | /*
|
---|
2 | * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps.
|
---|
3 | * Copyright (C) 2016 Erik Gruschka
|
---|
4 | * Copyright (C) 2018 Rebecca Schmidt
|
---|
5 | *
|
---|
6 | * This program is free software: you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation, either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | package model;
|
---|
21 |
|
---|
22 | import java.util.ArrayList;
|
---|
23 | import java.util.Collections;
|
---|
24 | import java.util.List;
|
---|
25 | import java.util.ListIterator;
|
---|
26 |
|
---|
27 | import model.TagCatalog.IndoorObject;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Counter for the calls of specific indoor objects, to track which items were used most frequently.
|
---|
31 | *
|
---|
32 | * @author egru
|
---|
33 | * @author rebsc
|
---|
34 | */
|
---|
35 | public class PresetCounter {
|
---|
36 |
|
---|
37 | private List<IndoorObject> rankingList;
|
---|
38 | private List<ObjectCounter> counterList;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Initiates the counterList with the available IndoorObjects.
|
---|
42 | */
|
---|
43 |
|
---|
44 | public PresetCounter() {
|
---|
45 | this.init();
|
---|
46 | }
|
---|
47 |
|
---|
48 | private void init() {
|
---|
49 | counterList = new ArrayList<>();
|
---|
50 |
|
---|
51 | counterList.add(new ObjectCounter(IndoorObject.CONCRETE_WALL, 0));
|
---|
52 | counterList.add(new ObjectCounter(IndoorObject.DOOR_PRIVATE, 0));
|
---|
53 | counterList.add(new ObjectCounter(IndoorObject.DOOR_PUBLIC, 0));
|
---|
54 | counterList.add(new ObjectCounter(IndoorObject.ELEVATOR, 0));
|
---|
55 | counterList.add(new ObjectCounter(IndoorObject.ENTRANCE, 0));
|
---|
56 | counterList.add(new ObjectCounter(IndoorObject.ENTRANCE_EXIT_ONLY, 0));
|
---|
57 | counterList.add(new ObjectCounter(IndoorObject.ACCESS_PRIVATE, 0));
|
---|
58 | counterList.add(new ObjectCounter(IndoorObject.ACCESS_PUBLIC, 0));
|
---|
59 | counterList.add(new ObjectCounter(IndoorObject.GLASS_WALL, 0));
|
---|
60 | counterList.add(new ObjectCounter(IndoorObject.ROOM, 0));
|
---|
61 | counterList.add(new ObjectCounter(IndoorObject.STEPS, 0));
|
---|
62 | counterList.add(new ObjectCounter(IndoorObject.CORRIDOR, 0));
|
---|
63 | counterList.add(new ObjectCounter(IndoorObject.TOILET_FEMALE, 0));
|
---|
64 | counterList.add(new ObjectCounter(IndoorObject.TOILET_MALE, 0));
|
---|
65 | counterList.add(new ObjectCounter(IndoorObject.AREA, 0));
|
---|
66 | counterList.add(new ObjectCounter(IndoorObject.BENCH, 0));
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Increments the counter of a specific IndoorObject in the list.
|
---|
71 | * @param object the IndoorObject, which counter should be incremented
|
---|
72 | */
|
---|
73 | public void count(IndoorObject object) {
|
---|
74 | ListIterator<ObjectCounter> iterator = this.counterList.listIterator();
|
---|
75 |
|
---|
76 | // Go through the list and increment the corresponding objects counter value.
|
---|
77 | while (iterator.hasNext()) {
|
---|
78 | ObjectCounter counterTemp = iterator.next();
|
---|
79 | if (counterTemp.getObject().equals(object)) {
|
---|
80 | counterList.get(iterator.nextIndex()-1).increment();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | //Sort the list.
|
---|
85 | this.sort();
|
---|
86 | }
|
---|
87 |
|
---|
88 | private void sort() {
|
---|
89 | Collections.sort(counterList);
|
---|
90 | Collections.reverse(counterList);
|
---|
91 | }
|
---|
92 |
|
---|
93 | public List<IndoorObject> getRanking() {
|
---|
94 | rankingList = new ArrayList<>();
|
---|
95 |
|
---|
96 | rankingList.add(counterList.get(0).getObject());
|
---|
97 | rankingList.add(counterList.get(1).getObject());
|
---|
98 | rankingList.add(counterList.get(2).getObject());
|
---|
99 | rankingList.add(counterList.get(3).getObject());
|
---|
100 |
|
---|
101 | return rankingList;
|
---|
102 | }
|
---|
103 |
|
---|
104 | private static class ObjectCounter implements Comparable<ObjectCounter> {
|
---|
105 | private IndoorObject object;
|
---|
106 | private int count;
|
---|
107 |
|
---|
108 | ObjectCounter(IndoorObject o, int c) {
|
---|
109 | this.object = o;
|
---|
110 | this.count = c;
|
---|
111 | }
|
---|
112 |
|
---|
113 | public int getCount() {
|
---|
114 | return this.count;
|
---|
115 | }
|
---|
116 |
|
---|
117 | public IndoorObject getObject() {
|
---|
118 | return this.object;
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void increment() {
|
---|
122 | this.count += 1;
|
---|
123 | }
|
---|
124 |
|
---|
125 | @Override
|
---|
126 | public int compareTo(ObjectCounter o) {
|
---|
127 | if (this.getCount() < o.getCount()) {
|
---|
128 | return -1;
|
---|
129 | }
|
---|
130 | if (this.getCount() == o.getCount()) {
|
---|
131 | return 0;
|
---|
132 | }
|
---|
133 | if (this.getCount() > o.getCount()) {
|
---|
134 | return 1;
|
---|
135 | }
|
---|
136 |
|
---|
137 | return 0;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | }
|
---|