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