KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > server > uihandler > statistics > Gestures


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
16  */

17
18 package org.netbeans.server.uihandler.statistics;
19
20 import org.netbeans.server.uihandler.*;
21 import java.util.Collections JavaDoc;
22 import java.util.EnumMap JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.logging.LogRecord JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26 import org.netbeans.lib.uihandler.InputGesture;
27
28 /** Counts numbers of keyboard, toolbar and menu actions.
29  *
30  * @author Jaroslav Tulach
31  */

32 public final class Gestures extends Statistics<Map JavaDoc<InputGesture,Integer JavaDoc>> {
33     public Gestures() {
34         super("Gestures");
35     }
36
37     protected Map JavaDoc<InputGesture, Integer JavaDoc> newData() {
38         return Collections.emptyMap();
39     }
40
41     protected Map JavaDoc<InputGesture, Integer JavaDoc> process(LogRecord JavaDoc rec) {
42         InputGesture ig = InputGesture.valueOf(rec);
43         if (ig == null) {
44             return Collections.emptyMap();
45         } else {
46             return Collections.singletonMap(ig, 1);
47         }
48     }
49
50     protected Map JavaDoc<InputGesture, Integer JavaDoc> join(
51         Map JavaDoc<InputGesture, Integer JavaDoc> one,
52         Map JavaDoc<InputGesture, Integer JavaDoc> two
53     ) {
54         Map JavaDoc<InputGesture, Integer JavaDoc> counts = new EnumMap JavaDoc<InputGesture,Integer JavaDoc>(InputGesture.class);
55         for (InputGesture ig : InputGesture.values()) {
56             Integer JavaDoc i1 = one.get(ig);
57             Integer JavaDoc i2 = two.get(ig);
58             int int1 = i1 == null ? 0 : i1.intValue();
59             int int2 = i2 == null ? 0 : i2.intValue();
60             if (int1 + int2 > 0) {
61                 counts.put(ig, int1 + int2);
62             }
63         }
64         return counts;
65     }
66
67     protected Map JavaDoc<InputGesture, Integer JavaDoc> finishSessionUpload(
68         String JavaDoc userId,
69         int sessionNumber,
70         boolean initialParse,
71         Map JavaDoc<InputGesture, Integer JavaDoc> data
72     ) {
73         return data;
74     }
75 }
76
Popular Tags