1 /*
2  * Copyright 2020 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 androidx.camera.integration.camera2.pipe.dataholders
18 
19 import androidx.camera.integration.camera2.pipe.extensions.compareTo
20 import androidx.camera.integration.camera2.pipe.extensions.minus
21 
22 /** Data source for continuous value graph visualizations. */
23 data class GraphDataHolderValueImpl(
24     /**
25      * Defines the hard upper and lower bound of the value. Absolute is specified to leave room to
26      * keep track of current min and max values as points are added in the future
27      */
28     private val absoluteMin: Number,
29     private val absoluteMax: Number,
30     override var graphData: GraphDataSortedRingBuffer
31 ) : GraphDataHolder {
32 
33     private val absoluteRange: Number
34 
35     init {
36         if (absoluteMax::class != absoluteMin::class)
37             throw IllegalArgumentException("Min and max" + " values must be of the same type")
38         if (absoluteMax <= absoluteMin)
39             throw IllegalArgumentException("Max value must be greater" + " than min value")
40         this.absoluteRange = absoluteMax - absoluteMin
41     }
42 
getMinnull43     fun getMin(): Number = absoluteMin
44 
45     fun getMax(): Number = absoluteMax
46 
47     fun getRange(): Number = absoluteRange
48 }
49