Clean up core-java-8 samples

This commit is contained in:
David Morley
2016-04-21 05:19:51 -05:00
parent fa23486f9a
commit 8cbf2e3b88
24 changed files with 50 additions and 299 deletions
@@ -21,20 +21,20 @@ public class CustomRecursiveAction extends RecursiveAction {
@Override
protected void compute() {
if(workLoad.length() > THRESHOLD) {
if (workLoad.length() > THRESHOLD) {
ForkJoinTask.invokeAll(createSubtasks());
} else {
processing(workLoad);
processing(workLoad);
}
}
private Collection<CustomRecursiveAction> createSubtasks() {
List<CustomRecursiveAction> subtasks =
new ArrayList<>();
new ArrayList<>();
String partOne = workLoad.substring(0, workLoad.length()/2);
String partTwo = workLoad.substring(workLoad.length()/2, workLoad.length());
String partOne = workLoad.substring(0, workLoad.length() / 2);
String partTwo = workLoad.substring(workLoad.length() / 2, workLoad.length());
subtasks.add(new CustomRecursiveAction(partOne));
subtasks.add(new CustomRecursiveAction(partTwo));
@@ -23,7 +23,7 @@ public class CustomRecursiveTask extends RecursiveTask<Integer> {
if (arr.length > THRESHOLD) {
return ForkJoinTask.invokeAll(createSubtasks())
return ForkJoinTask.invokeAll(createSubtasks())
.stream()
.mapToInt(ForkJoinTask::join)
.sum();
@@ -13,7 +13,7 @@ public class UnzipFile {
final byte[] buffer = new byte[1024];
final ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
ZipEntry zipEntry = zis.getNextEntry();
while(zipEntry != null){
while (zipEntry != null) {
final String fileName = zipEntry.getName();
final File newFile = new File("src/main/resources/unzipTest/" + fileName);
final FileOutputStream fos = new FileOutputStream(newFile);
@@ -18,7 +18,7 @@ public class ZipFile {
zipOut.putNextEntry(zipEntry);
final byte[] bytes = new byte[1024];
int length;
while((length = fis.read(bytes)) >= 0) {
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
zipOut.close();
@@ -22,7 +22,7 @@ public class ZipMultipleFiles {
final byte[] bytes = new byte[1024];
int length;
while((length = fis.read(bytes)) >= 0) {
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
fis.close();
+1 -1
View File
@@ -10,7 +10,7 @@
<!-- <logger name="org.springframework" level="WARN" /> -->
<root level="INFO">
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
</root>
</configuration>
@@ -6,7 +6,9 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import static com.baeldung.doublecolon.ComputerUtils.*;
@@ -1,14 +1,13 @@
package com.baeldung.java8;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import com.google.common.collect.Lists;
import org.junit.Test;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import com.google.common.collect.Lists;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
public class Java8CollectionCleanupUnitTest {
@@ -7,6 +7,7 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import static org.junit.Assert.*;
@@ -53,8 +54,8 @@ public class Java8ExecutorServiceTest {
public void creationSubmittingTasksShuttingDownNow_whenShutDownAfterAwating_thenCorrect() {
ExecutorService threadPoolExecutor =
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>());
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>());
for (int i = 0; i < 100; i++) {
threadPoolExecutor.submit(callableTask);
@@ -1,7 +1,6 @@
package com.baeldung.java8;
import com.baeldung.forkjoin.CustomRecursiveAction;
import com.baeldung.forkjoin.CustomRecursiveTask;
import com.baeldung.forkjoin.util.PoolUtil;
@@ -1,16 +1,15 @@
package com.baeldung.java8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.Foo;
import com.baeldung.FooExtended;
import com.baeldung.UseFoo;
import org.junit.Before;
import org.junit.Test;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class Java8FunctionalInteracesLambdasTest {
@@ -1,17 +1,16 @@
package com.baeldung.java8;
import static org.hamcrest.Matchers.equalTo;
import com.baeldung.java8.entity.Human;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.baeldung.java8.entity.Human;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;
import static org.hamcrest.Matchers.equalTo;
public class Java8SortUnitTest {
@@ -1,22 +1,18 @@
package com.baeldung.java8;
import static org.junit.Assert.assertEquals;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.StreamSupport;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class JavaFolderSizeTest {
@@ -93,7 +89,7 @@ public class JavaFolderSizeTest {
final File folder = new File(path);
final long size = getFolderSize(folder);
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
final int unitIndex = (int) (Math.log10(size) / 3);
final double unitValue = 1 << (unitIndex * 10);
@@ -1,13 +1,13 @@
package com.baeldung.java8;
import org.junit.Assert;
import org.junit.Test;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.Scanner;
import org.junit.Assert;
import org.junit.Test;
public class JavaTryWithResourcesTest {
private static final String TEST_STRING_HELLO_WORLD = "Hello World";
@@ -1,14 +1,12 @@
package com.baeldung.java8.base64;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import static org.junit.Assert.*;
public class ApacheCommonsEncodeDecodeTest {
// tests
@@ -1,14 +1,12 @@
package com.baeldung.java8.base64;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.UUID;
import org.junit.Test;
import static org.junit.Assert.*;
public class Java8EncodeDecodeTest {