Home | History | Annotate | Download | only in result
      1 /*
      2  * Copyright (C) 2010 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.tradefed.result;
     17 
     18 import java.util.HashMap;
     19 import java.util.Map;
     20 
     21 /**
     22  * A class to represent a test summary.  Provides a single field for a summary, in addition to a
     23  * key-value store for more detailed summary.  Also provides a place for the summary source to be
     24  * identified.
     25  */
     26 public class TestSummary {
     27     private TypedString mSummary = null;
     28     private Map<String, TypedString> mKvStore = null;
     29     private String mSource = null;
     30 
     31     public static enum Type {
     32         URI("uri"),
     33         TEXT("text");
     34         private final String mType;
     35         Type() {
     36             mType = "uri";
     37         }
     38 
     39         Type(String type) {
     40             mType = type;
     41         }
     42 
     43         String getType() {
     44             return mType;
     45         }
     46     }
     47 
     48     public static class TypedString {
     49         private Type mType;
     50         private String mString;
     51         public TypedString(String string) {
     52             this(string, Type.URI);
     53         }
     54         public TypedString(String string, Type type) {
     55             mType = type;
     56             mString = string;
     57         }
     58         public Type getType() {
     59             return mType;
     60         }
     61         public String getString() {
     62             return mString;
     63         }
     64 
     65         @Override
     66         public String toString() {
     67             return String.format("%s: %s", mType.toString(), mString);
     68         }
     69     }
     70 
     71     /**
     72      * A convenience constructor that takes the string representation of a URI
     73      *
     74      * @param summaryUri A {@link String} representing a URI
     75      */
     76     public TestSummary(String summaryUri) {
     77         this(new TypedString(summaryUri));
     78     }
     79 
     80     public TestSummary(TypedString summary) {
     81         setSummary(summary);
     82         mKvStore = new HashMap<String, TypedString>();
     83     }
     84 
     85     /**
     86      * Set the source of the summary, in case a consumer wants to implement a contract with a
     87      * specific producer
     88      *
     89      * @param source A {@link String} containing the fully-qualified Java class name of the source
     90      */
     91     public void setSource(String source) {
     92         mSource = source;
     93     }
     94     public void setSummary(TypedString summary) {
     95         mSummary = summary;
     96     }
     97     public void addKvEntry(String key, TypedString value) {
     98         mKvStore.put(key, value);
     99     }
    100 
    101     // trampolines
    102     public void setSummary(String summary) {
    103         setSummary(new TypedString(summary));
    104     }
    105     public void addKvEntry(String key, String value) {
    106         addKvEntry(key, new TypedString(value));
    107     }
    108 
    109     public String getSource() {
    110         return mSource;
    111     }
    112     public TypedString getSummary() {
    113         return mSummary;
    114     }
    115     public Map<String, TypedString> getKvEntries() {
    116         return mKvStore;
    117     }
    118 }
    119