1 /* 2 * Copyright (C) 2019 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 17 package com.android.tradefed.testtype.mobly; 18 19 import java.util.Map; 20 21 /** Mobly yaml result 'User Data' element handler. */ 22 public class MoblyYamlResultUserDataHandler implements IMoblyYamlResultHandler { 23 24 private static final String TIME_STAMP = "timestamp"; 25 26 @Override handle(Map<String, Object> docMap)27 public UserData handle(Map<String, Object> docMap) { 28 UserData.Builder builder = UserData.builder(); 29 builder.setTimestamp(String.valueOf(docMap.get(TIME_STAMP))); 30 return builder.build(); 31 } 32 33 public static class UserData implements ITestResult { 34 private final long mTimestamp; 35 UserData(String timestamp)36 private UserData(String timestamp) { 37 mTimestamp = Long.parseLong(timestamp); 38 } 39 40 @Override getType()41 public MoblyYamlResultHandlerFactory.Type getType() { 42 return MoblyYamlResultHandlerFactory.Type.USER_DATA; 43 } 44 getTimeStamp()45 public long getTimeStamp() { 46 return mTimestamp; 47 } 48 builder()49 public static Builder builder() { 50 return new Builder(); 51 } 52 53 public static class Builder { 54 private String mTimestamp; 55 setTimestamp(String timestamp)56 public Builder setTimestamp(String timestamp) { 57 mTimestamp = timestamp; 58 return this; 59 } 60 build()61 public UserData build() { 62 return new UserData(mTimestamp); 63 } 64 } 65 } 66 } 67