FileDocCategorySizeDatePackage
CharCounter.javaAPI DocExample1849Sat Apr 17 23:31:20 BST 2004javathreads.examples.ch08.example4

CharCounter

public class CharCounter extends Object

Fields Summary
public HashMap
correctChars
public HashMap
incorrectChars
private AbstractTableModel
atm
Constructors Summary
Methods Summary
public voidaddModel(javax.swing.table.AbstractTableModel atm)

        this.atm = atm;
    
public voidcorrectChar(int c)


        
        synchronized(correctChars) {
            Integer key = new Integer(c);
            Integer num = (Integer) correctChars.get(key);
            if (num == null)
                correctChars.put(key, new Integer(1));
            else correctChars.put(key, new Integer(num.intValue() + 1));
            if (atm != null)
                atm.fireTableDataChanged();
        }
    
public intgetCorrectNum(int c)

        synchronized(correctChars) {
            Integer key = new Integer(c);
            Integer num = (Integer) correctChars.get(key);
            if (num == null)
                return 0;
            return num.intValue();
        }
    
public intgetIncorrectNum(int c)

        synchronized(incorrectChars) {
            Integer key = new Integer(c);
            Integer num = (Integer) incorrectChars.get(key);
            if (num == null)
                return 0;
            return num.intValue();
        }
    
public voidincorrectChar(int c)

        synchronized(incorrectChars) {
            Integer key = new Integer(c);
            Integer num = (Integer) incorrectChars.get(key);
            if (num == null)
                incorrectChars.put(key, new Integer(-1));
            else incorrectChars.put(key, new Integer(num.intValue() - 1));
            if (atm != null)
                atm.fireTableDataChanged();
        }