Ignore:
Timestamp:
2016-07-11T22:48:15+02:00 (10 years ago)
Author:
donvip
Message:

checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java

    r32122 r32637  
    3333 */
    3434public 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                 public 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        
     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   
    136136}
Note: See TracChangeset for help on using the changeset viewer.