view src/org/dancres/blitz/stats/OpSwitch.java @ 27:511648fa4d64 Version 2.1

Version to 2.1
author Dan Creswell <dan.creswell@gmail.com>
date Mon, 04 Jan 2010 13:00:40 +0000
parents 3dc0c5604566
children
line wrap: on
line source

package org.dancres.blitz.stats;

/**
   Controls the tracking of a particular operation type against a particular
   type.
 */
public class OpSwitch implements Switch {
    public static final int TAKE_OPS = 1;
    public static final int WRITE_OPS = 2;
    public static final int READ_OPS = 4;

    public static final String ALL_TYPES = "*";

    private String theType;
    private int theOp;
    private boolean isEnabled;
    /**
       @param aType specifies a particular entry classname or the wildcard
       ALL_TYPES
       @param anOp should be an OR'd combination of TAKE_OPS, WRITE_OPS and
       READ_OPS
     */
    public OpSwitch(String aType, int anOp, boolean enable) {
        theType = aType;
        theOp = anOp;
        isEnabled = enable;
    }

    public String getType() {
        return theType;
    }

    public int getOp() {
        return theOp;
    }

    public boolean isEnabled() {
        return isEnabled;
    }

    public boolean isWildcard() {
        return theType.equals(ALL_TYPES);
    }

    /**
       Equal if the switch is an OpSwitch and it has the same type and
       operation.
     */
    public boolean equals(Object anObject) {
        if (anObject instanceof OpSwitch) {
            OpSwitch myOther = (OpSwitch) anObject;

            if (myOther.theType.equals(theType)) {
                return (myOther.theOp == theOp);
            }
        }

        return false;
    }
}