Source:
<code>public void testRandomNumbersGenerator() { LearningEnvironmentBuilder envBuilder = TestUtils.testEnvBuilder().withRandom(MockRandom::new); int partitions = 10; int iterations = 2; DatasetTrainer<Model<Object, Vector>, Void> trainer = new DatasetTrainer<Model<Object, Vector>, Void>() { @Override public <K, V> Model<Object, Vector> fit(DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Void> lbExtractor) { Dataset<EmptyContext, TestUtils.DataWrapper<Integer>> ds = datasetBuilder.build(envBuilder, new EmptyContextBuilder<>(), (PartitionDataBuilder<K, V, EmptyContext, TestUtils.DataWrapper<Integer>>)(env, upstreamData, upstreamDataSize, ctx) -> TestUtils.DataWrapper.of(env.partition())); Vector v = null; for (int iter = 0; iter < iterations; iter++) { <START> v = ds.compute((dw, env) -> VectorUtils.fill(-1, partitions).set(env.partition(), env.randomNumbersGenerator().nextInt()), <END> (v1, v2) -> v1 != null ? (v2 != null ? VectorUtils.zipWith(v1, v2, (d1, d2) -> d1 != -1 ? d1 : d2) : v1) : v2); } return Model.constantModel(v); } @Override protected boolean checkState(Model<Object, Vector> mdl) { return false; } @Override protected <K, V> Model<Object, Vector> updateModel(Model<Object, Vector> mdl, DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Void> lbExtractor) { return null; } }; trainer.setEnvironmentBuilder(envBuilder); Model<Object, Vector> mdl = trainer.fit(getCacheMock(partitions), partitions, null, null); Vector exp = VectorUtils.zeroes(partitions); for (int i = 0; i < partitions; i++) exp.set(i, i * iterations); Vector res = mdl.apply(null); assertEquals(exp, res); }</code><technical_language>refactor this code - hard reading</technical_language>

Target:
public void testRandomNumbersGenerator() { LearningEnvironmentBuilder envBuilder = TestUtils.testEnvBuilder().withRandomDependency(MockRandom::new); int partitions = 10; int iterations = 2; DatasetTrainer<Model<Object, Vector>, Void> trainer = new DatasetTrainer<Model<Object, Vector>, Void>() { @Override public <K, V> Model<Object, Vector> fit(DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Void> lbExtractor) { Dataset<EmptyContext, TestUtils.DataWrapper<Integer>> ds = datasetBuilder.build(envBuilder, new EmptyContextBuilder<>(), (PartitionDataBuilder<K, V, EmptyContext, TestUtils.DataWrapper<Integer>>)(env, upstreamData, upstreamDataSize, ctx) -> TestUtils.DataWrapper.of(env.partition())); Vector v = null; for (int iter = 0; iter < iterations; iter++) { v = ds.compute((dw, env) -> VectorUtils.fill(-1, partitions).set(env.partition(), env.randomNumbersGenerator().nextInt()), (v1, v2) -> zipOverridingEmpty(v1, v2, -1)); } return constantModel(v); } @Override protected boolean checkState(Model<Object, Vector> mdl) { return false; } @Override protected <K, V> Model<Object, Vector> updateModel(Model<Object, Vector> mdl, DatasetBuilder<K, V> datasetBuilder, IgniteBiFunction<K, V, Vector> featureExtractor, IgniteBiFunction<K, V, Void> lbExtractor) { return null; } }; trainer.withEnvironmentBuilder(envBuilder); Model<Object, Vector> mdl = trainer.fit(getCacheMock(partitions), partitions, null, null); Vector exp = VectorUtils.zeroes(partitions); for (int i = 0; i < partitions; i++) exp.set(i, i * iterations); Vector res = mdl.apply(null); assertEquals(exp, res); }