Static analysis fixes
This commit is contained in:
parent
eb357198a2
commit
4f5353d261
|
|
@ -63,6 +63,21 @@ public class Migration<TKey> {
|
|||
-> Single.error(new MigrationException(String.format("Can't get version of '%s' from %s", key, versionsStore), throwable)));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
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 ->
|
||||
migrator.canMigrate(key, updatedVersion)
|
||||
.flatMap(canMigrate -> canMigrate
|
||||
? migrator.migrate(key, updatedVersion)
|
||||
.doOnSuccess(newVersion
|
||||
-> versionUpdater.updateVersion(newVersion, latestVersion, migrator))
|
||||
: Single.just(updatedVersion)));
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates some object by key to latest version.
|
||||
*
|
||||
|
|
@ -73,17 +88,7 @@ public class Migration<TKey> {
|
|||
return loadCurrentVersion(key)
|
||||
.flatMap(currentVersion -> {
|
||||
final VersionUpdater versionUpdater = new VersionUpdater<>(key, versionsStore, currentVersion);
|
||||
Single<Long> chain = Single.fromCallable(() -> versionUpdater.initialVersion);
|
||||
for (final Migrator<TKey, ?, ?> migrator : migrators) {
|
||||
chain = chain.flatMap(updatedVersion ->
|
||||
migrator.canMigrate(key, updatedVersion)
|
||||
.flatMap(canMigrate -> canMigrate
|
||||
? migrator.migrate(key, updatedVersion)
|
||||
.doOnSuccess(newVersion
|
||||
-> versionUpdater.updateVersion(newVersion, latestVersion, migrator))
|
||||
: Single.just(updatedVersion)));
|
||||
}
|
||||
return chain
|
||||
return makeMigrationChain(key, versionUpdater)
|
||||
.doOnSuccess(lastUpdatedVersion -> {
|
||||
if (lastUpdatedVersion < latestVersion) {
|
||||
throw OnErrorThrowable.from(new NextLoopMigrationException());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue