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.HashSet;
     20 import java.util.Set;
     21 
     22 /**
     23  * A generic item containing attributes for time, process, and thread and can be extended for
     24  * items such as {@link AnrItem} and {@link JavaCrashItem}.
     25  */
     26 public class MiscKernelLogItem extends GenericItem {
     27 
     28     /** Constant for JSON output */
     29     public static final String EVENT_TIME = "EVENT_TIME";
     30     /** Constant for JSON output */
     31     public static final String PREAMBLE = "LAST_PREAMBLE";
     32     /** Constant for JSON output */
     33     public static final String CATEGORY = "CATEGORY";
     34     /** Constant for JSON output */
     35     public static final String STACK = "STACK";
     36 
     37     private static final Set<String> ATTRIBUTES = new HashSet<String>(Arrays.asList(
     38             EVENT_TIME, PREAMBLE, CATEGORY, STACK));
     39 
     40     /**
     41      * Constructor for {@link MiscKernelLogItem}.
     42      */
     43     public MiscKernelLogItem() {
     44         super(ATTRIBUTES);
     45     }
     46 
     47     /**
     48      * Constructor for {@link MiscKernelLogItem}.
     49      *
     50      * @param attributes A list of allowed attributes.
     51      */
     52     protected MiscKernelLogItem(Set<String> attributes) {
     53         super(getAllAttributes(attributes));
     54     }
     55 
     56     /**
     57      * Get the time object when the event happened.
     58      */
     59     public Double getEventTime() {
     60         return (Double) getAttribute(EVENT_TIME);
     61     }
     62 
     63     /**
     64      * Set the time object when the event happened.
     65      */
     66     public void setEventTime(Double time) {
     67         setAttribute(EVENT_TIME, time);
     68     }
     69 
     70     /**
     71      * Get the preamble for the event.
     72      */
     73     public String getPreamble() {
     74         return (String) getAttribute(PREAMBLE);
     75     }
     76 
     77     /**
     78      * Set the preamble for the event.
     79      */
     80     public void setPreamble(String preamble) {
     81         setAttribute(PREAMBLE, preamble);
     82     }
     83 
     84     /**
     85      * Get the category of the event.
     86      */
     87     public String getCategory() {
     88         return (String) getAttribute(CATEGORY);
     89     }
     90 
     91     /**
     92      * Set the category of the event.
     93      */
     94     public void setCategory(String category) {
     95         setAttribute(CATEGORY, category);
     96     }
     97 
     98     /**
     99      * Get the stack for the event.
    100      */
    101     public String getStack() {
    102         return (String) getAttribute(STACK);
    103     }
    104 
    105     /**
    106      * Set the stack for the event.
    107      */
    108     public void setStack(String stack) {
    109         setAttribute(STACK, stack);
    110     }
    111 
    112     /**
    113      * Combine an array of attributes with the internal list of attributes.
    114      */
    115     private static Set<String> getAllAttributes(Set<String> attributes) {
    116         Set<String> allAttributes = new HashSet<String>(ATTRIBUTES);
    117         allAttributes.addAll(attributes);
    118         return allAttributes;
    119     }
    120 }
    121