diff --git a/src/main/java/ru/touchin/roboswag/core/observables/storable/Migration.java b/src/main/java/ru/touchin/roboswag/core/observables/storable/Migration.java index 42f6059..0f36f5e 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/storable/Migration.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/storable/Migration.java @@ -63,6 +63,21 @@ public class Migration { -> Single.error(new MigrationException(String.format("Can't get version of '%s' from %s", key, versionsStore), throwable))); } + @NonNull + private Single makeMigrationChain(@NonNull final TKey key, @NonNull final VersionUpdater versionUpdater) { + Single chain = Single.fromCallable(() -> versionUpdater.initialVersion); + for (final Migrator 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 { return loadCurrentVersion(key) .flatMap(currentVersion -> { final VersionUpdater versionUpdater = new VersionUpdater<>(key, versionsStore, currentVersion); - Single chain = Single.fromCallable(() -> versionUpdater.initialVersion); - for (final Migrator 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()); diff --git a/src/main/java/ru/touchin/roboswag/core/observables/storable/Storable.java b/src/main/java/ru/touchin/roboswag/core/observables/storable/Storable.java index dc532ab..1c362e8 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/storable/Storable.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/storable/Storable.java @@ -105,7 +105,8 @@ public class Storable { 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 { 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 { this.storeScheduler = storeScheduler; } + @SuppressWarnings("CPD-END") protected void setStoreSchedulerInternal(@Nullable final Scheduler storeScheduler) { this.storeScheduler = storeScheduler; } @@ -507,11 +511,6 @@ public class Storable { return new Storable<>(this); } - @Override - protected void setObserveStrategyInternal(@Nullable final ObserveStrategy observeStrategy) { - super.setObserveStrategyInternal(observeStrategy); - } - } } diff --git a/src/main/java/ru/touchin/roboswag/core/observables/storable/concrete/NonNullStorable.java b/src/main/java/ru/touchin/roboswag/core/observables/storable/concrete/NonNullStorable.java index 16840a9..95dc8ec 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/storable/concrete/NonNullStorable.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/storable/concrete/NonNullStorable.java @@ -42,7 +42,7 @@ public class NonNullStorable extends Storable