1 /* 2 * Copyright (C) 2021 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.window.util; 18 19 import android.annotation.NonNull; 20 21 import java.util.function.Consumer; 22 23 /** 24 * Produces data through {@link DataProducer#getData} and provides a mechanism for receiving 25 * a callback when the data managed by the produces has changed. 26 * 27 * @param <T> The type of data this producer returns through {@link DataProducer#getData}. 28 */ 29 public interface DataProducer<T> { 30 /** 31 * Emits the first available data at that point in time. 32 * @param dataConsumer a {@link Consumer} that will receive one value. 33 */ getData(@onNull Consumer<T> dataConsumer)34 void getData(@NonNull Consumer<T> dataConsumer); 35 36 /** 37 * Adds a callback to be notified when the data returned 38 * from {@link DataProducer#getData} has changed. 39 */ addDataChangedCallback(@onNull Consumer<T> callback)40 void addDataChangedCallback(@NonNull Consumer<T> callback); 41 42 /** Removes a callback previously added with {@link #addDataChangedCallback(Consumer)}. */ removeDataChangedCallback(@onNull Consumer<T> callback)43 void removeDataChangedCallback(@NonNull Consumer<T> callback); 44 } 45