Changeset 33887 in osm for applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java
- Timestamp:
- 2017-11-25T01:25:40+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java
r32637 r33887 28 28 /** 29 29 * Counter for the calls of specific indoor objects, to track which items were used most frequently. 30 * 30 * 31 31 * @author egru 32 32 * 33 33 */ 34 34 public class PresetCounter { 35 35 36 36 private List<IndoorObject> rankingList; 37 37 private List<ObjectCounter> counterList; 38 38 39 39 /** 40 40 * Initiates the counterList with the available IndoorObjects. 41 41 */ 42 42 43 43 public PresetCounter() { 44 44 this.init(); 45 45 } 46 46 47 47 private void init() { 48 48 counterList = new ArrayList<>(); 49 49 50 50 counterList.add(new ObjectCounter(IndoorObject.CONCRETE_WALL, 0)); 51 51 counterList.add(new ObjectCounter(IndoorObject.DOOR, 0)); … … 60 60 counterList.add(new ObjectCounter(IndoorObject.TOILET_MALE, 0)); 61 61 } 62 62 63 63 /** 64 64 * Increments the counter of a specific IndoorObject in the list. … … 67 67 public void count(IndoorObject object) { 68 68 ListIterator<ObjectCounter> iterator = this.counterList.listIterator(); 69 69 70 70 // Go through the list and increment the corresponding objects counter value. 71 71 while (iterator.hasNext()) { 72 72 ObjectCounter counterTemp = iterator.next(); 73 73 if (counterTemp.getObject().equals(object)) { 74 counterList.get(iterator.nextIndex()-1).increment(); 74 counterList.get(iterator.nextIndex()-1).increment(); 75 75 } 76 76 } 77 77 78 78 //Sort the list. 79 79 this.sort(); 80 80 } 81 81 82 82 private void sort() { 83 83 Collections.sort(counterList); 84 84 Collections.reverse(counterList); 85 85 } 86 86 87 87 public List<IndoorObject> getRanking() { 88 rankingList = new ArrayList< IndoorObject>();89 88 rankingList = new ArrayList<>(); 89 90 90 rankingList.add(counterList.get(0).getObject()); 91 91 rankingList.add(counterList.get(1).getObject()); 92 92 rankingList.add(counterList.get(2).getObject()); 93 93 rankingList.add(counterList.get(3).getObject()); 94 94 95 95 return rankingList; 96 96 } 97 98 private class ObjectCounter implements Comparable<ObjectCounter> { 97 98 private static class ObjectCounter implements Comparable<ObjectCounter> { 99 99 private IndoorObject object; 100 100 private int count; 101 101 102 102 ObjectCounter(IndoorObject o, int c) { 103 103 this.object = o; 104 104 this.count = c; 105 105 } 106 106 107 107 public int getCount() { 108 108 return this.count; 109 109 } 110 110 111 111 public IndoorObject getObject() { 112 112 return this.object; 113 113 } 114 114 115 115 public void increment() { 116 116 this.count += 1; 117 117 } 118 118 119 119 @Override 120 120 public int compareTo(ObjectCounter o) { … … 128 128 return 1; 129 129 } 130 130 131 131 return 0; 132 132 } 133 133 134 134 } 135 135 136 136 }
Note:
See TracChangeset
for help on using the changeset viewer.