• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.loganalysis.item;
18 
19 import java.util.Arrays;
20 import java.util.HashSet;
21 import java.util.Set;
22 
23 /**
24  * An {@link IItem} used to store information of the battery discharge.
25  */
26 public class BatteryDischargeStatsInfoItem extends GenericItem {
27 
28     /** Constant for JSON output */
29     public static final String MAX_PERCENTAGE = "MAX_PERCENTAGE";
30     /** Constant for JSON output */
31     public static final String MIN_PERCENTAGE = "MIN_PERCENTAGE";
32     /** Constant for JSON output */
33     public static final String DISCHARGE_PERCENTAGE = "DISCHARGE_PERCENTAGE";
34     /** Constant for JSON output */
35     public static final String DISCHARGE_DURATION = "DISCHARGE_DURATION";
36     /** Constant for JSON output */
37     public static final String PROJECTED_BATTERY_LIFE = "PROJECTED_BATTERY_LIFE";
38 
39     private static final Set<String> ATTRIBUTES = new HashSet<>(Arrays.asList(MAX_PERCENTAGE,
40         MIN_PERCENTAGE, DISCHARGE_PERCENTAGE, DISCHARGE_DURATION, PROJECTED_BATTERY_LIFE));
41 
42     /**
43      * The constructor for {@link BatteryDischargeStatsInfoItem}.
44      */
BatteryDischargeStatsInfoItem()45     public BatteryDischargeStatsInfoItem() {
46         super(ATTRIBUTES);
47     }
48 
49     /**
50      * Set the maximum percentage.
51      */
setMaxPercentage(int percentage)52     public void setMaxPercentage(int percentage) {
53         setAttribute(MAX_PERCENTAGE, percentage);
54     }
55 
56     /**
57      * Set the minimum percentage.
58      */
setMinPercentage(int percentage)59     public void setMinPercentage(int percentage) {
60         setAttribute(MIN_PERCENTAGE, percentage);
61     }
62 
63     /**
64      * Set the discharge percentage.
65      */
setDischargePercentage(int dischargePercentage)66     public void setDischargePercentage(int dischargePercentage) {
67         setAttribute(DISCHARGE_PERCENTAGE, dischargePercentage);
68     }
69 
70     /**
71      * Set the discharge duration.
72      */
setDischargeDuration(long dischargeDuration)73     public void setDischargeDuration(long dischargeDuration) {
74         setAttribute(DISCHARGE_DURATION, dischargeDuration);
75     }
76 
77     /**
78      * Set the projected battery life.
79      */
setProjectedBatteryLife(long projectedBatteryLife)80     public void setProjectedBatteryLife(long projectedBatteryLife) {
81         setAttribute(PROJECTED_BATTERY_LIFE, projectedBatteryLife);
82     }
83 
84     /**
85      * Get the maximum percentage.
86      */
getMaxPercentage()87     public int getMaxPercentage() {
88         return (int) getAttribute(MAX_PERCENTAGE);
89     }
90 
91     /**
92      * Get the minimum percentage.
93      */
getMinPercentage()94     public int getMinPercentage() {
95         return (int) getAttribute(MIN_PERCENTAGE);
96     }
97 
98     /**
99      * Get the discharge percentage.
100      */
getDischargePercentage()101     public int getDischargePercentage() {
102         return (int) getAttribute(DISCHARGE_PERCENTAGE);
103     }
104 
105     /**
106      * Get the discharge duration.
107      */
getDischargeDuration()108     public long getDischargeDuration() {
109         return (long) getAttribute(DISCHARGE_DURATION);
110     }
111 
112     /**
113      * Get the projected battery life.
114      */
getProjectedBatteryLife()115     public long getProjectedBatteryLife() {
116         return (long) getAttribute(PROJECTED_BATTERY_LIFE);
117     }
118 
119 }
120