1e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood/* 2e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * Copyright (C) 2010 The Android Open Source Project 3e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * 4e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * Licensed under the Apache License, Version 2.0 (the "License"); 5e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * you may not use this file except in compliance with the License. 6e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * You may obtain a copy of the License at 7e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * 8e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * http://www.apache.org/licenses/LICENSE-2.0 9e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * 10e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * Unless required by applicable law or agreed to in writing, software 11e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * distributed under the License is distributed on an "AS IS" BASIS, 12e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * See the License for the specific language governing permissions and 14e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * limitations under the License. 15e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood */ 16e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwoodpackage com.android.quicksearchbox.util; 17e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 18e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood/** 19e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * {@link NowOrLater} class that converts from one type to another. 20e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood */ 21e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwoodpublic abstract class NowOrLaterWrapper<A, B> implements NowOrLater<B> { 22e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 23e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood private final NowOrLater<A> mWrapped; 24e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 25e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public NowOrLaterWrapper(NowOrLater<A> wrapped) { 26e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood mWrapped = wrapped; 27e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood } 28e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 29e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public void getLater(final Consumer<? super B> consumer) { 30e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood mWrapped.getLater(new Consumer<A>(){ 31e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public boolean consume(A value) { 32e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood return consumer.consume(get(value)); 33e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood }}); 34e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood } 35e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 36e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public B getNow() { 37e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood return get(mWrapped.getNow()); 38e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood } 39e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 40e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public boolean haveNow() { 41e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood return mWrapped.haveNow(); 42e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood } 43e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 44e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood /** 45e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * Perform the appropriate conversion. This will be called once for every call to 46e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * {@link #getLater(Consumer)} or {@link #getNow()}. The thread that it's called on will depend 47e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood * on the behaviour of the wrapped object and the caller. 48e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood */ 49e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood public abstract B get(A value); 50e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood 51e29d52aa72c96c3147fa91d83aeb8dafc6d1f578Mathew Inwood} 52