Home | History | Annotate | Download | only in item
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.loganalysis.item;
     17 
     18 import java.util.Arrays;
     19 import java.util.Date;
     20 import java.util.HashSet;
     21 import java.util.Set;
     22 
     23 /**
     24  * An {@link IItem} used to store miscellaneous logcat info.
     25  */
     26 public class MiscLogcatItem extends GenericItem {
     27     /** Constant for JSON output */
     28     public static final String EVENT_TIME = "EVENT_TIME";
     29     /** Constant for JSON output */
     30     public static final String PID = "PID";
     31     /** Constant for JSON output */
     32     public static final String TID = "TID";
     33     /** Constant for JSON output */
     34     public static final String APP = "APP";
     35     /** Constant for JSON output */
     36     public static final String TAG = "TAG";
     37     /** Constant for JSON output */
     38     public static final String LAST_PREAMBLE = "LAST_PREAMBLE";
     39     /** Constant for JSON output */
     40     public static final String PROCESS_PREAMBLE = "PROCESS_PREAMBLE";
     41     /** Constant for JSON output */
     42     public static final String CATEGORY = "CATEGORY";
     43     /** Constant for JSON output */
     44     public static final String STACK = "STACK";
     45 
     46     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
     47             EVENT_TIME, PID, TID, APP, TAG, LAST_PREAMBLE, PROCESS_PREAMBLE, CATEGORY, STACK));
     48 
     49     /**
     50      * Constructor for {@link MiscLogcatItem}.
     51      */
     52     public MiscLogcatItem() {
     53         super(ATTRIBUTES);
     54     }
     55 
     56     /**
     57      * Constructor for {@link MiscLogcatItem}.
     58      *
     59      * @param attributes A list of allowed attributes.
     60      */
     61     protected MiscLogcatItem(Set<String> attributes) {
     62         super(getAllAttributes(attributes));
     63     }
     64 
     65     /**
     66      * Get the {@link Date} object when the event happened.
     67      */
     68     public Date getEventTime() {
     69         return (Date) getAttribute(EVENT_TIME);
     70     }
     71 
     72     /**
     73      * Set the {@link Date} object when the event happened.
     74      */
     75     public void setEventTime(Date time) {
     76         setAttribute(EVENT_TIME, time);
     77     }
     78 
     79     /**
     80      * Get the PID of the event.
     81      */
     82     public Integer getPid() {
     83         return (Integer) getAttribute(PID);
     84     }
     85 
     86     /**
     87      * Set the PID of the event.
     88      */
     89     public void setPid(Integer pid) {
     90         setAttribute(PID, pid);
     91     }
     92 
     93     /**
     94      * Get the TID of the event.
     95      */
     96     public Integer getTid() {
     97         return (Integer) getAttribute(TID);
     98     }
     99 
    100     /**
    101      * Set the TID of the event.
    102      */
    103     public void setTid(Integer tid) {
    104         setAttribute(TID, tid);
    105     }
    106 
    107     /**
    108      * Get the app or package name of the event.
    109      */
    110     public String getApp() {
    111         return (String) getAttribute(APP);
    112     }
    113 
    114     /**
    115      * Set the app or package name of the event.
    116      */
    117     public void setApp(String app) {
    118         setAttribute(APP, app);
    119     }
    120 
    121     /**
    122      * Get the tag of the event.
    123      */
    124     public String getTag() {
    125         return (String) getAttribute(TAG);
    126     }
    127 
    128     /**
    129      * Set the tag of the event.
    130      */
    131     public void setTag(String tag) {
    132         setAttribute(TAG, tag);
    133     }
    134 
    135     /**
    136      * Get the last preamble for the event.
    137      */
    138     public String getLastPreamble() {
    139         return (String) getAttribute(LAST_PREAMBLE);
    140     }
    141 
    142     /**
    143      * Set the last preamble for the event.
    144      */
    145     public void setLastPreamble(String preamble) {
    146         setAttribute(LAST_PREAMBLE, preamble);
    147     }
    148 
    149     /**
    150      * Get the process preamble for the event.
    151      */
    152     public String getProcessPreamble() {
    153         return (String) getAttribute(PROCESS_PREAMBLE);
    154     }
    155 
    156     /**
    157      * Set the process preamble for the event.
    158      */
    159     public void setProcessPreamble(String preamble) {
    160         setAttribute(PROCESS_PREAMBLE, preamble);
    161     }
    162 
    163     /**
    164      * Combine an array of attributes with the internal list of attributes.
    165      */
    166     private static Set<String> getAllAttributes(Set<String> attributes) {
    167         Set<String> allAttributes = new HashSet<String>(ATTRIBUTES);
    168         allAttributes.addAll(attributes);
    169         return allAttributes;
    170     }
    171 
    172     /**
    173      * Get the category of the event.
    174      */
    175     public String getCategory() {
    176         return (String) getAttribute(CATEGORY);
    177     }
    178 
    179     /**
    180      * Set the category of the event.
    181      */
    182     public void setCategory(String category) {
    183         setAttribute(CATEGORY, category);
    184     }
    185 
    186     /**
    187      * Get the stack for the event.
    188      */
    189     public String getStack() {
    190         return (String) getAttribute(STACK);
    191     }
    192 
    193     /**
    194      * Set the stack for the event.
    195      */
    196     public void setStack(String stack) {
    197         setAttribute(STACK, stack);
    198     }
    199 }
    200