diff --git a/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainActivity.java b/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainActivity.java index 96d3f3d..3aca516 100644 --- a/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainActivity.java +++ b/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainActivity.java @@ -30,7 +30,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Napkin.provideComponent(this, AppComponent.class).inject(this); + Napkin.provideComponent(this).inject(this); mainViewModel.restoreState(state); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.setViewModel(mainViewModel); diff --git a/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainViewModel.java b/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainViewModel.java index c8a403e..9b31cd2 100644 --- a/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainViewModel.java +++ b/app/src/main/java/com/github/aleksandermielczarek/observablecacheexample/ui/MainViewModel.java @@ -94,15 +94,15 @@ public void testCompletable(Completable completable) { } public void restoreObservables() { - observableCache.getObservable(OBSERVABLE_CACHE_KEY_OBSERVABLE, String.class) + observableCache.getObservable(OBSERVABLE_CACHE_KEY_OBSERVABLE) .ifPresent(this::testObservable) - .thanGetSingle(OBSERVABLE_CACHE_KEY_SINGLE, String.class) + .thanGetSingle(OBSERVABLE_CACHE_KEY_SINGLE) .ifPresent(this::testSingle) .thanGetCompletable(OBSERVABLE_CACHE_KEY_COMPLETABLE) .ifPresent(this::testCompletable) - .thanGetObservable(OBSERVABLE_CACHE_KEY_OBSERVABLE_ERROR, String.class) + .thanGetObservable(OBSERVABLE_CACHE_KEY_OBSERVABLE_ERROR) .ifPresent(this::testObservable) - .thanGetSingle(OBSERVABLE_CACHE_KEY_SINGLE_ERROR, String.class) + .thanGetSingle(OBSERVABLE_CACHE_KEY_SINGLE_ERROR) .ifPresent(this::testSingle) .thanGetCompletable(OBSERVABLE_CACHE_KEY_COMPLETABLE_ERROR) .ifPresent(this::testCompletable); diff --git a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/LruObservableCache.java b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/LruObservableCache.java index 4fd2457..805981d 100644 --- a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/LruObservableCache.java +++ b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/LruObservableCache.java @@ -10,7 +10,7 @@ * Created by Aleksander Mielczarek on 30.10.2016. */ -public class LruObservableCache extends ObservableCache { +public final class LruObservableCache extends ObservableCache { public static final int DEFAULT_CACHE_SIZE = 16; diff --git a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ObservableCache.java b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ObservableCache.java index 3df38b8..d4820f6 100644 --- a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ObservableCache.java +++ b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ObservableCache.java @@ -74,10 +74,6 @@ public ObservableFromCache getObservable(String key) { return new ObservableFromCache<>(observableFromCache, this); } - public ObservableFromCache getObservable(String key, Class observableClass) { - return getObservable(key); - } - public SingleFromCache getSingle(String key) { Observable observableFromCache = getFromCache(key); if (observableFromCache != null) { @@ -86,10 +82,6 @@ public SingleFromCache getSingle(String key) { return new SingleFromCache<>(null, this); } - public SingleFromCache getSingle(String key, Class singleClass) { - return getSingle(key); - } - public CompletableFromCache getCompletable(String key) { Observable observableFromCache = getFromCache(key); if (observableFromCache != null) { diff --git a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ValueFromCache.java b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ValueFromCache.java index de1b6a0..9235667 100644 --- a/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ValueFromCache.java +++ b/observablecache/src/main/java/com/github/aleksandermielczarek/observablecache/ValueFromCache.java @@ -21,6 +21,11 @@ public boolean isPresent() { return valueFromCache != null; } + @Nullable + public T get() { + return valueFromCache; + } + public ValueFromCache ifPresent(S valueInCacheAction) { if (isPresent()) { valueInCacheAction.action(valueFromCache); @@ -42,13 +47,6 @@ public ObservableFromCache orElseGetObservable(String key) { return new ObservableFromCache<>(null, observableCache); } - public ObservableFromCache orElseGetObservable(String key, Class observableClass) { - if (!isPresent()) { - return observableCache.getObservable(key, observableClass); - } - return new ObservableFromCache<>(null, observableCache); - } - public SingleFromCache orElseGetSingle(String key) { if (!isPresent()) { return observableCache.getSingle(key); @@ -56,13 +54,6 @@ public SingleFromCache orElseGetSingle(String key) { return new SingleFromCache<>(null, observableCache); } - public SingleFromCache orElseGetSingle(String key, Class singleClass) { - if (!isPresent()) { - return observableCache.getSingle(key, singleClass); - } - return new SingleFromCache<>(null, observableCache); - } - public CompletableFromCache orElseGetCompletable(String key) { if (!isPresent()) { return observableCache.getCompletable(key); @@ -74,18 +65,10 @@ public ObservableFromCache thanGetObservable(String key) { return observableCache.getObservable(key); } - public ObservableFromCache thanGetObservable(String key, Class observableClass) { - return observableCache.getObservable(key, observableClass); - } - public SingleFromCache thanGetSingle(String key) { return observableCache.getSingle(key); } - public SingleFromCache thanGetSingle(String key, Class singleClass) { - return observableCache.getSingle(key, singleClass); - } - public CompletableFromCache thanGetCompletable(String key) { return observableCache.getCompletable(key); }