1 /* 2 * Copyright (C) 2018 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.i18n.timezone; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** 23 * A container class for debug information. 24 * 25 * @hide 26 */ 27 @libcore.api.CorePlatformApi 28 public class DebugInfo { 29 private final List<DebugEntry> entries; 30 31 @libcore.api.CorePlatformApi DebugInfo()32 public DebugInfo() { 33 this.entries = new ArrayList<>(); 34 } 35 36 /** 37 * Adds a key / string value. 38 * 39 * @return {@code this} for chaining calls 40 */ 41 @libcore.api.CorePlatformApi addStringEntry(String key, String value)42 public DebugInfo addStringEntry(String key, String value) { 43 entries.add(new DebugEntry(key, value)); 44 return this; 45 } 46 47 /** 48 * Adds a key / string value. Converts the supplied int value to a String. 49 * 50 * @return {@code this} for chaining calls 51 */ 52 @libcore.api.CorePlatformApi addStringEntry(String key, int value)53 public DebugInfo addStringEntry(String key, int value) { 54 addStringEntry(key, Integer.toString(value)); 55 return this; 56 } 57 58 /** Returns all the debug entries. */ 59 @libcore.api.CorePlatformApi getDebugEntries()60 public List<DebugEntry> getDebugEntries() { 61 return entries; 62 } 63 64 /** Returns the first debug entry with the given key, or {@code null} if it does not exist. */ getDebugEntry(String key)65 public DebugEntry getDebugEntry(String key) { 66 for (DebugEntry entry : getDebugEntries()) { 67 if (key.equals(entry.getKey())) { 68 return entry; 69 } 70 } 71 return null; 72 } 73 74 /** 75 * A generic key/value for a single piece of debug information. 76 * 77 * @hide 78 */ 79 @libcore.api.CorePlatformApi 80 public static class DebugEntry { 81 private final String key; 82 private final String stringValue; 83 84 @libcore.api.CorePlatformApi DebugEntry(String key, String stringValue)85 public DebugEntry(String key, String stringValue) { 86 this.key = key; 87 this.stringValue = stringValue; 88 } 89 90 @libcore.api.CorePlatformApi getKey()91 public String getKey() { 92 return key; 93 } 94 95 @libcore.api.CorePlatformApi getStringValue()96 public String getStringValue() { 97 return stringValue; 98 } 99 } 100 } 101