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 com.android.tradefed.testtype.mobly.MoblyYamlResultHandlerFactory.Type; 20 21 import java.util.Map; 22 23 /** Mobly yaml result 'Controller Info' element handler. */ 24 public class MoblyYamlResultControllerInfoHandler implements IMoblyYamlResultHandler { 25 private static final String TIME_STAMP = "Timestamp"; 26 27 @Override handle(Map<String, Object> docMap)28 public ControllerInfo handle(Map<String, Object> docMap) { 29 ControllerInfo.Builder builder = ControllerInfo.builder(); 30 builder.setTimestamp(String.valueOf(docMap.get(TIME_STAMP))); 31 return builder.build(); 32 } 33 34 public static class ControllerInfo implements ITestResult { 35 private final long mTimestamp; 36 ControllerInfo(String timestamp)37 private ControllerInfo(String timestamp) { 38 mTimestamp = Math.round(Double.parseDouble(timestamp) * 1000); 39 } 40 41 @Override getType()42 public Type getType() { 43 return Type.CONTROLLER_INFO; 44 } 45 getTimeStamp()46 public long getTimeStamp() { 47 return mTimestamp; 48 } 49 builder()50 public static Builder builder() { 51 return new Builder(); 52 } 53 54 public static class Builder { 55 private String mTimestamp; 56 Builder()57 public Builder() {} 58 setTimestamp(String timestamp)59 public Builder setTimestamp(String timestamp) { 60 mTimestamp = timestamp; 61 return this; 62 } 63 build()64 public ControllerInfo build() { 65 return new ControllerInfo(mTimestamp); 66 } 67 } 68 } 69 } 70