Skip to content

Commit

Permalink
[FLINK-6982] [guava] Reduce guava dependency usages
Browse files Browse the repository at this point in the history
This closes apache#4453.
  • Loading branch information
zentol committed Aug 7, 2017
1 parent 4406d48 commit 0910bc5
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 115 deletions.
7 changes: 0 additions & 7 deletions flink-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ under the License.

<!-- test dependencies -->

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils-junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import org.apache.flink.testutils.junit.RetryRule;
import org.apache.flink.util.Preconditions;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.math3.stat.inference.KolmogorovSmirnovTest;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -274,14 +274,12 @@ private void verifySamplerFraction(double fraction, boolean withReplacement) {
* Test sampler without replacement, and verify that there should not exist any duplicate element in sampled result.
*/
private void verifyRandomSamplerDuplicateElements(final RandomSampler<Double> sampler) {
List<Double> list = Lists.newLinkedList(new Iterable<Double>() {
@Override
public Iterator<Double> iterator() {
return sampler.sample(source.iterator());
}
});
Set<Double> set = Sets.newHashSet(list);
assertTrue("There should not have duplicate element for sampler without replacement.", list.size() == set.size());
Iterator<Double> values = sampler.sample(source.iterator());
Set<Double> set = new HashSet<>();
while (values.hasNext()) {
double next = values.next();
assertTrue("Sampler returned duplicate element (" + next + "). Set=" + set, set.add(next));
}
}

private int getSize(Iterator<?> iterator) {
Expand Down Expand Up @@ -370,7 +368,7 @@ private double[] getSampledOutput(RandomSampler<Double> sampler, boolean sampleO
Iterator<Double> sampled;
if (sampleOnPartitions) {
DistributedRandomSampler<Double> reservoirRandomSampler = (DistributedRandomSampler<Double>) sampler;
List<IntermediateSampleData<Double>> intermediateResult = Lists.newLinkedList();
List<IntermediateSampleData<Double>> intermediateResult = new LinkedList<>();
for (int i = 0; i < DEFAULT_PARTITION_NUMBER; i++) {
Iterator<IntermediateSampleData<Double>> partialIntermediateResult = reservoirRandomSampler.sampleInPartition(sourcePartitions[i].iterator());
while (partialIntermediateResult.hasNext()) {
Expand All @@ -381,7 +379,7 @@ private double[] getSampledOutput(RandomSampler<Double> sampler, boolean sampleO
} else {
sampled = sampler.sample(source.iterator());
}
List<Double> list = Lists.newArrayList();
List<Double> list = new ArrayList<>();
while (sampled.hasNext()) {
list.add(sampled.next());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

package org.apache.flink.api.java.tuple;

import com.google.common.io.Files;
import org.apache.flink.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
Expand Down Expand Up @@ -95,7 +94,7 @@ private static File getPackage(File root, String packageString) {
}

private static void insertCodeIntoFile(String code, File file) throws IOException {
String fileContent = Files.toString(file, StandardCharsets.UTF_8);
String fileContent = FileUtils.readFileUtf8(file);

try (Scanner s = new Scanner(fileContent)) {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -137,7 +136,7 @@ private static void insertCodeIntoFile(String code, File file) throws IOExceptio
sb.append(line).append("\n");
}
s.close();
Files.write(sb.toString(), file, StandardCharsets.UTF_8);
FileUtils.writeFileUtf8(file, sb.toString());
}
}

Expand Down
Loading

0 comments on commit 0910bc5

Please sign in to comment.