Home | History | Annotate | Download | only in item
      1 /*
      2  * Copyright (C) 2017 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.List;
     21 import java.util.Set;
     22 import java.util.regex.Pattern;
     23 
     24 /** A {@link GenericItem} of trace format. */
     25 public class TraceFormatItem extends GenericItem {
     26     private static final String REGEX = "regex";
     27     private static final String PARAMS = "params";
     28     private static final String NUM_PARAMS = "num_params";
     29     private static final String HEX_PARAMS = "hex_params";
     30     private static final String STR_PARAMS = "str_params";
     31     private static final Set<String> ATTRIBUTES =
     32             new HashSet<>(Arrays.asList(REGEX, PARAMS, NUM_PARAMS, HEX_PARAMS, STR_PARAMS));
     33 
     34     /** Create a new {@link TraceFormatItem} */
     35     public TraceFormatItem() {
     36         super(ATTRIBUTES);
     37     }
     38 
     39     @Override
     40     /** TraceFormatItem doesn't support merge */
     41     public IItem merge(IItem other) throws ConflictingItemException {
     42         throw new ConflictingItemException("Trace format items cannot be merged");
     43     }
     44 
     45     /** Get a compiled regex that matches output of this trace format */
     46     public Pattern getRegex() {
     47         return (Pattern) getAttribute(REGEX);
     48     }
     49 
     50     /** Set a compiled regex that matches output of this trace format */
     51     public void setRegex(Pattern regex) {
     52         setAttribute(REGEX, regex);
     53     }
     54 
     55     /**
     56      * Get all parameters found in this trace format. The parameters were converted to camel case
     57      * and match the group names in the regex.
     58      */
     59     public List<String> getParameters() {
     60         return (List<String>) getAttribute(PARAMS);
     61     }
     62 
     63     /**
     64      * Set all parameters found in this trace format. The parameters were converted to camel case
     65      * and match the group names in the regex.
     66      */
     67     public void setParameters(List<String> parameters) {
     68         setAttribute(PARAMS, parameters);
     69     }
     70 
     71     /**
     72      * Get numeric parameters found in this trace format. The parameters were converted to camel
     73      * case and match the group names in the regex.
     74      */
     75     public List<String> getNumericParameters() {
     76         return (List<String>) getAttribute(NUM_PARAMS);
     77     }
     78 
     79     /**
     80      * Set numeric parameters found in this trace format. The parameters were converted to camel
     81      * case and match the group names in the regex.
     82      */
     83     public void setNumericParameters(List<String> numericParameters) {
     84         setAttribute(NUM_PARAMS, numericParameters);
     85     }
     86 
     87     /**
     88      * Get hexadecimal parameters found in this trace format. The parameters were converted to camel
     89      * case and match the group names in the regex.
     90      */
     91     public List<String> getHexParameters() {
     92         return (List<String>) getAttribute(HEX_PARAMS);
     93     }
     94 
     95     /**
     96      * Set hexadecimal parameters found in this trace format. The parameters were converted to camel
     97      * case and match the group names in the regex.
     98      */
     99     public void setHexParameters(List<String> hexParameters) {
    100         setAttribute(HEX_PARAMS, hexParameters);
    101     }
    102 
    103     /**
    104      * Get string parameters found in this trace format. The parameters were converted to camel case
    105      * and match the group names in the regex.
    106      */
    107     public List<String> getStringParameters() {
    108         return (List<String>) getAttribute(STR_PARAMS);
    109     }
    110 
    111     /**
    112      * Set string parameters found in this trace format. The parameters were converted to camel case
    113      * and match the group names in the regex.
    114      */
    115     public void setStringParameters(List<String> stringParameters) {
    116         setAttribute(STR_PARAMS, stringParameters);
    117     }
    118 }
    119