[Java] TreeMap w/ Explanation & Readability
```\nclass CountIntervals {\n    // Interval treemap start -> finish.\n    TreeMap s;\n    int count;\n    public CountIntervals() {\n        s = new TreeMap();
```\nclass CountIntervals {\n    // Interval treemap start -> finish.\n    TreeMap<Integer, Integer> s;\n    int count;\n    public CountIntervals() {\n        s = new TreeMap<Integer, Integer>();\n        count = 0;\n    }\n    \n    public void add(int left, int right) {\n        // Add interval if there is no overlapping.\n        if (s.floorKey(right) == null || s.get(s.floorKey(right)) < left) {\n            s.put(left, right);\n            count += (right - left + 1);\n        } else {\n            int start = left;\n            int end = right;\n            \n            // Remove overlapping intervals and update count.\n            while (true) {\n                int l = s.floorKey(end);\n                int r = s.get(l);\n                start = Math.min(start, l);\n                end = Math.max(end, r);\n                count -= (r - l + 1);\n                s.remove(l);\n                // Break the loop until there is no overlapping with interval (start, end).\n                if (s.floorKey(end) == null || s.get(s.floorKey(end)) < start) {\n                    break;\n                }\n            }\n            // Add (start, end) to TreeMap and update count.\n            s.put(start, end);\n            count += (end - start + 1);\n        }\n    }\n    \n    public int count() {\n        return count;\n    }\n}
['Tree']