001    package org.kuali.maven.plugins.graph.tree;
002    
003    /**
004     * Thread safe counter
005     */
006    public class Counter implements Comparable<Counter> {
007    
008        private int count;
009    
010        public Counter() {
011            this(0);
012        }
013    
014        public Counter(int count) {
015            super();
016            this.count = count;
017        }
018    
019        public synchronized int increment() {
020            if (count == Integer.MAX_VALUE) {
021                throw new RuntimeException("Maximum counter value exceeded");
022            } else {
023                return count++;
024            }
025        }
026    
027        public synchronized int getCount() {
028            return count;
029        }
030    
031        @Override
032        public synchronized int compareTo(Counter other) {
033            return count > other.count ? 1 : count < other.count ? -1 : 0;
034        }
035    
036    }