FileDocCategorySizeDatePackage
EventContainer.javaAPI DocAndroid 1.5 API15832Wed May 06 22:41:08 BST 2009com.android.ddmlib.log

EventContainer

public class EventContainer extends Object
Represents an event and its data.

Fields Summary
public int
mTag
public int
pid
public int
tid
public int
sec
public int
nsec
private Object
mData
Constructors Summary
EventContainer(com.android.ddmlib.log.LogReceiver.LogEntry entry, int tag, Object data)
Creates an {@link EventContainer} from a {@link LogEntry}.

param
entry the LogEntry from which pid, tid, and time info is copied.
param
tag the event tag value
param
data the data of the EventContainer.

        getType(data);
        mTag = tag;
        mData = data;

        pid = entry.pid;
        tid = entry.tid;
        sec = entry.sec;
        nsec = entry.nsec;
    
EventContainer(int tag, int pid, int tid, int sec, int nsec, Object data)
Creates an {@link EventContainer} with raw data

        getType(data);
        mTag = tag;
        mData = data;
        
        this.pid = pid;
        this.tid = tid;
        this.sec = sec;
        this.nsec = nsec;
    
Methods Summary
public final java.lang.IntegergetInt()
Returns the data as an int.

throws
InvalidTypeException if the data type is not {@link EventValueType#INT}.
see
#getType()

        if (getType(mData) == EventValueType.INT) {
            return (Integer)mData;
        }

        throw new InvalidTypeException();
    
public final java.lang.LonggetLong()
Returns the data as a long.

throws
InvalidTypeException if the data type is not {@link EventValueType#LONG}.
see
#getType()

        if (getType(mData) == EventValueType.LONG) {
            return (Long)mData;
        }

        throw new InvalidTypeException();
    
public final java.lang.StringgetString()
Returns the data as a String.

throws
InvalidTypeException if the data type is not {@link EventValueType#STRING}.
see
#getType()

        if (getType(mData) == EventValueType.STRING) {
            return (String)mData;
        }

        throw new InvalidTypeException();
    
public final com.android.ddmlib.log.EventContainer$EventValueTypegetType(java.lang.Object data)
Returns the type of an object.

        if (data instanceof Integer) {
            return EventValueType.INT;
        } else if (data instanceof Long) {
            return EventValueType.LONG;
        } else if (data instanceof String) {
            return EventValueType.STRING;
        } else if (data instanceof Object[]) {
            // loop through the list to see if we have another list
            Object[] objects = (Object[])data;
            for (Object obj : objects) {
                EventValueType type = getType(obj);
                if (type == EventValueType.LIST || type == EventValueType.TREE) {
                    return EventValueType.TREE;
                }
            }
            return EventValueType.LIST;
        }

        return EventValueType.UNKNOWN;
    
public com.android.ddmlib.log.EventContainer$EventValueTypegetType()
Returns the type of the data.

        return getType(mData);
    
private final java.lang.ObjectgetValue(java.lang.Object data, int valueIndex, boolean recursive)

        EventValueType type = getType(data);
        
        switch (type) {
            case INT:
            case LONG:
            case STRING:
                return data;
            case LIST:
                if (recursive) {
                    Object[] list = (Object[]) data;
                    if (valueIndex >= 0 && valueIndex < list.length) {
                        return getValue(list[valueIndex], valueIndex, false);
                    }
                }
        }
        
        return null;
    
public java.lang.ObjectgetValue(int valueIndex)
Returns a value by index. The return type is defined by its type.

param
valueIndex the index of the value. If the data is not a list, this is ignored.

        return getValue(mData, valueIndex, true);
    
private final doublegetValueAsDouble(java.lang.Object data, int valueIndex, boolean recursive)

        EventValueType type = getType(data);
        
        switch (type) {
            case INT:
                return ((Integer)data).doubleValue();
            case LONG:
                return ((Long)data).doubleValue();
            case STRING:
                throw new InvalidTypeException();
            case LIST:
                if (recursive) {
                    Object[] list = (Object[]) data;
                    if (valueIndex >= 0 && valueIndex < list.length) {
                        return getValueAsDouble(list[valueIndex], valueIndex, false);
                    }
                }
        }
        
        throw new InvalidTypeException();
    
public doublegetValueAsDouble(int valueIndex)
Returns a value by index as a double.

param
valueIndex the index of the value. If the data is not a list, this is ignored.
throws
InvalidTypeException if the data type is not {@link EventValueType#INT}, {@link EventValueType#LONG}, {@link EventValueType#LIST}, or if the item in the list at index valueIndex is not of type {@link EventValueType#INT} or {@link EventValueType#LONG}.
see
#getType()

        return getValueAsDouble(mData, valueIndex, true);
    
private final java.lang.StringgetValueAsString(java.lang.Object data, int valueIndex, boolean recursive)

        EventValueType type = getType(data);
        
        switch (type) {
            case INT:
                return ((Integer)data).toString();
            case LONG:
                return ((Long)data).toString();
            case STRING:
                return (String)data;
            case LIST:
                if (recursive) {
                    Object[] list = (Object[]) data;
                    if (valueIndex >= 0 && valueIndex < list.length) {
                        return getValueAsString(list[valueIndex], valueIndex, false);
                    }
                } else {
                    throw new InvalidTypeException(
                            "getValueAsString() doesn't support EventValueType.TREE");
                }
        }

        throw new InvalidTypeException(
                "getValueAsString() unsupported type:" + type);
    
public java.lang.StringgetValueAsString(int valueIndex)
Returns a value by index as a String.

param
valueIndex the index of the value. If the data is not a list, this is ignored.
throws
InvalidTypeException if the data type is not {@link EventValueType#INT}, {@link EventValueType#LONG}, {@link EventValueType#STRING}, {@link EventValueType#LIST}, or if the item in the list at index valueIndex is not of type {@link EventValueType#INT}, {@link EventValueType#LONG}, or {@link EventValueType#STRING}
see
#getType()

        return getValueAsString(mData, valueIndex, true);
    
public booleantestValue(int index, java.lang.Object value, com.android.ddmlib.log.EventContainer$CompareMethod compareMethod)
Checks that the index-th value of this event against a provided value.

param
index the index of the value to test
param
value the value to test against
param
compareMethod the method of testing
return
true if the test passed.
throws
InvalidTypeException in case of type mismatch between the value to test and the value to test against, or if the compare method is incompatible with the type of the values.
see
CompareMethod

        EventValueType type = getType(mData);
        if (index > 0 && type != EventValueType.LIST) {
            throw new InvalidTypeException();
        }
        
        Object data = mData;
        if (type == EventValueType.LIST) {
            data = ((Object[])mData)[index];
        }

        if (data.getClass().equals(data.getClass()) == false) {
            throw new InvalidTypeException();
        }

        switch (compareMethod) {
            case EQUAL_TO:
                return data.equals(value);
            case LESSER_THAN:
                if (data instanceof Integer) {
                    return (((Integer)data).compareTo((Integer)value) <= 0);
                } else if (data instanceof Long) {
                    return (((Long)data).compareTo((Long)value) <= 0);
                }

                // other types can't use this compare method.
                throw new InvalidTypeException();
            case LESSER_THAN_STRICT:
                if (data instanceof Integer) {
                    return (((Integer)data).compareTo((Integer)value) < 0);
                } else if (data instanceof Long) {
                    return (((Long)data).compareTo((Long)value) < 0);
                }

                // other types can't use this compare method.
                throw new InvalidTypeException();
            case GREATER_THAN:
                if (data instanceof Integer) {
                    return (((Integer)data).compareTo((Integer)value) >= 0);
                } else if (data instanceof Long) {
                    return (((Long)data).compareTo((Long)value) >= 0);
                }

                // other types can't use this compare method.
                throw new InvalidTypeException();
            case GREATER_THAN_STRICT:
                if (data instanceof Integer) {
                    return (((Integer)data).compareTo((Integer)value) > 0);
                } else if (data instanceof Long) {
                    return (((Long)data).compareTo((Long)value) > 0);
                }

                // other types can't use this compare method.
                throw new InvalidTypeException();
            case BIT_CHECK:
                if (data instanceof Integer) {
                    return (((Integer)data).intValue() & ((Integer)value).intValue()) != 0;
                } else if (data instanceof Long) {
                    return (((Long)data).longValue() & ((Long)value).longValue()) != 0;
                }

                // other types can't use this compare method.
                throw new InvalidTypeException();
            default :
                throw new InvalidTypeException();
        }