Static analysis fixes

This commit is contained in:
Gavriil Sitnikov 2017-03-01 22:28:22 +03:00
parent eb357198a2
commit 4f5353d261
3 changed files with 22 additions and 18 deletions

View File

@ -63,16 +63,8 @@ public class Migration<TKey> {
-> Single.error(new MigrationException(String.format("Can't get version of '%s' from %s", key, versionsStore), throwable)));
}
/**
* Migrates some object by key to latest version.
*
* @param key Key of object to migrate.
*/
@NonNull
public Completable migrateToLatestVersion(@NonNull final TKey key) {
return loadCurrentVersion(key)
.flatMap(currentVersion -> {
final VersionUpdater versionUpdater = new VersionUpdater<>(key, versionsStore, currentVersion);
private Single<Long> makeMigrationChain(@NonNull final TKey key, @NonNull final VersionUpdater versionUpdater) {
Single<Long> chain = Single.fromCallable(() -> versionUpdater.initialVersion);
for (final Migrator<TKey, ?, ?> migrator : migrators) {
chain = chain.flatMap(updatedVersion ->
@ -83,7 +75,20 @@ public class Migration<TKey> {
-> versionUpdater.updateVersion(newVersion, latestVersion, migrator))
: Single.just(updatedVersion)));
}
return chain
return chain;
}
/**
* Migrates some object by key to latest version.
*
* @param key Key of object to migrate.
*/
@NonNull
public Completable migrateToLatestVersion(@NonNull final TKey key) {
return loadCurrentVersion(key)
.flatMap(currentVersion -> {
final VersionUpdater versionUpdater = new VersionUpdater<>(key, versionsStore, currentVersion);
return makeMigrationChain(key, versionUpdater)
.doOnSuccess(lastUpdatedVersion -> {
if (lastUpdatedVersion < latestVersion) {
throw OnErrorThrowable.from(new NextLoopMigrationException());

View File

@ -105,7 +105,8 @@ public class Storable<TKey, TObject, TStoreObject> {
this.storeObjectType = storeObjectType;
this.store = store;
this.converter = converter;
final ObserveStrategy nonNullObserveStrategy = observeStrategy != null ? observeStrategy : getDefaultObserveStrategyFor(objectType, storeObjectType);
final ObserveStrategy nonNullObserveStrategy
= observeStrategy != null ? observeStrategy : getDefaultObserveStrategyFor(objectType, storeObjectType);
scheduler = storeScheduler != null ? storeScheduler : Schedulers.from(Executors.newSingleThreadExecutor());
storeValueObservable
= createStoreValueObservable(nonNullObserveStrategy, migration, defaultValue);
@ -390,6 +391,8 @@ public class Storable<TKey, TObject, TStoreObject> {
sourceBuilder.migration, sourceBuilder.defaultValue, sourceBuilder.storeScheduler);
}
@SuppressWarnings("CPD-START")
//CPD: it is same code as constructor of Storable
private BuilderCore(@NonNull final TKey key,
@NonNull final Type objectType,
@NonNull final Type storeObjectType,
@ -410,6 +413,7 @@ public class Storable<TKey, TObject, TStoreObject> {
this.storeScheduler = storeScheduler;
}
@SuppressWarnings("CPD-END")
protected void setStoreSchedulerInternal(@Nullable final Scheduler storeScheduler) {
this.storeScheduler = storeScheduler;
}
@ -507,11 +511,6 @@ public class Storable<TKey, TObject, TStoreObject> {
return new Storable<>(this);
}
@Override
protected void setObserveStrategyInternal(@Nullable final ObserveStrategy observeStrategy) {
super.setObserveStrategyInternal(observeStrategy);
}
}
}

View File

@ -42,7 +42,7 @@ public class NonNullStorable<TKey, TObject, TStoreObject> extends Storable<TKey,
@NonNull
@Override
public TObject getSync() {
public TObject getSync() throws Throwable {
final TObject result = super.getSync();
if (result == null) {
throw new ShouldNotHappenException();