1 /* 2 * Copyright 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 package androidx.work 17 18 /** 19 * An abstract class that allows the user to define how to merge a list of inputs to a 20 * [ListenableWorker]. 21 * 22 * Before workers run, they receive input [Data] from their parent workers, as well as anything 23 * specified directly to them via [WorkRequest.Builder.setInputData]. An InputMerger takes all of 24 * these objects and converts them to a single merged [Data] to be used as the worker input. 25 * [WorkManager] offers two concrete InputMerger implementations: [OverwritingInputMerger] and 26 * [ArrayCreatingInputMerger]. 27 * 28 * Note that the list of inputs to merge is in an unspecified order. You should not make assumptions 29 * about the order of inputs. 30 */ 31 abstract class InputMerger { 32 /** 33 * Merges a list of [Data] and outputs a single Data object. 34 * 35 * @param inputs A list of [Data] 36 * @return The merged output 37 */ mergenull38 abstract fun merge(inputs: List<Data>): Data 39 } 40 41 private val TAG = Logger.tagWithPrefix("InputMerger") 42 43 internal fun fromClassName(className: String): InputMerger? { 44 try { 45 val clazz = Class.forName(className) 46 return clazz.getDeclaredConstructor().newInstance() as InputMerger 47 } catch (e: Exception) { 48 Logger.get().error(TAG, "Trouble instantiating $className", e) 49 } 50 return null 51 } 52