From 4d8f92e58753a71683e8d14d68784f86907601a9 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sat, 5 Aug 2017 16:14:20 +0300 Subject: [PATCH] formatting cleanup --- .../cyclicbarrier/CyclicBarrierDemo.java | 12 ++--- .../diningphilosophers/Philosopher.java | 3 +- .../executorservice/ExecutorServiceDemo.java | 26 +++++------ .../concurrent/future/FutureDemo.java | 46 +++++++++---------- .../threadfactory/BaeldungThreadFactory.java | 26 +++++------ .../concurrent/threadfactory/Task.java | 10 ++-- .../filesystem/jndi/LookupFSJNDI.java | 13 +++--- .../com/baeldung/hashcode/entities/User.java | 11 +++-- .../baeldung/jmx/JMXTutorialMainlauncher.java | 1 - .../java/com/baeldung/socket/EchoClient.java | 3 +- .../com/baeldung/stream/InfiniteStreams.java | 1 - .../com/baeldung/string/StringHelper.java | 9 +--- .../baeldung/stringtokenizer/MyTokenizer.java | 6 +-- .../CustomTemporalAdjuster.java | 12 ++--- .../com/baeldung/transferqueue/Consumer.java | 1 - .../accumulator/LongAccumulatorUnitTest.java | 12 ++--- .../hashcode/application/ApplicationTest.java | 2 +- .../LambdaExceptionWrappersUnitTest.java | 1 - .../list/listoflist/ListOfListsUnitTest.java | 24 ++++------ .../CoreThreadPoolIntegrationTest.java | 1 - 20 files changed, 96 insertions(+), 124 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java b/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java index 977dae4fdb..758bdecd0c 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java +++ b/core-java/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierDemo.java @@ -15,14 +15,12 @@ public class CyclicBarrierDemo { private int NUM_PARTIAL_RESULTS; private int NUM_WORKERS; - private void runSimulation(int numWorkers, int numberOfPartialResults) { NUM_PARTIAL_RESULTS = numberOfPartialResults; NUM_WORKERS = numWorkers; cyclicBarrier = new CyclicBarrier(NUM_WORKERS, new AggregatorThread()); - System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute " - + NUM_PARTIAL_RESULTS + " partial results each"); + System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute " + NUM_PARTIAL_RESULTS + " partial results each"); for (int i = 0; i < NUM_WORKERS; i++) { Thread worker = new Thread(new NumberCruncherThread()); worker.setName("Thread " + i); @@ -38,8 +36,7 @@ public class CyclicBarrierDemo { List partialResult = new ArrayList<>(); for (int i = 0; i < NUM_PARTIAL_RESULTS; i++) { Integer num = random.nextInt(10); - System.out.println(thisThreadName - + ": Crunching some numbers! Final result - " + num); + System.out.println(thisThreadName + ": Crunching some numbers! Final result - " + num); partialResult.add(num); } partialResults.add(partialResult); @@ -57,13 +54,12 @@ public class CyclicBarrierDemo { @Override public void run() { String thisThreadName = Thread.currentThread().getName(); - System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS - + " workers, having " + NUM_PARTIAL_RESULTS + " results each."); + System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS + " workers, having " + NUM_PARTIAL_RESULTS + " results each."); int sum = 0; for (List threadResult : partialResults) { System.out.print("Adding "); for (Integer partialResult : threadResult) { - System.out.print(partialResult+" "); + System.out.print(partialResult + " "); sum += partialResult; } System.out.println(); diff --git a/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java b/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java index c5672706ad..4de420900a 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java +++ b/core-java/src/main/java/com/baeldung/concurrent/diningphilosophers/Philosopher.java @@ -15,7 +15,8 @@ public class Philosopher implements Runnable { Thread.sleep(((int) (Math.random() * 100))); } - @Override public void run() { + @Override + public void run() { try { while (true) { doAction(System.nanoTime() + ": Thinking"); // thinking diff --git a/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java b/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java index ae2b279d9a..83a9fb6692 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java +++ b/core-java/src/main/java/com/baeldung/concurrent/executorservice/ExecutorServiceDemo.java @@ -6,22 +6,22 @@ import java.util.concurrent.TimeUnit; public class ExecutorServiceDemo { - ExecutorService executor = Executors.newFixedThreadPool(10); + ExecutorService executor = Executors.newFixedThreadPool(10); - public void execute() { + public void execute() { - executor.submit(() -> { - new Task(); - }); + executor.submit(() -> { + new Task(); + }); - executor.shutdown(); - executor.shutdownNow(); - try { - executor.awaitTermination(20l, TimeUnit.NANOSECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } + executor.shutdown(); + executor.shutdownNow(); + try { + executor.awaitTermination(20l, TimeUnit.NANOSECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } - } + } } diff --git a/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java b/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java index 7cb611be0f..4794d5cb61 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java +++ b/core-java/src/main/java/com/baeldung/concurrent/future/FutureDemo.java @@ -9,36 +9,36 @@ import java.util.concurrent.TimeoutException; public class FutureDemo { - public String invoke() { + public String invoke() { - String str = null; + String str = null; - ExecutorService executorService = Executors.newFixedThreadPool(10); + ExecutorService executorService = Executors.newFixedThreadPool(10); - Future future = executorService.submit(() -> { - // Task - Thread.sleep(10000l); - return "Hellow world"; - }); + Future future = executorService.submit(() -> { + // Task + Thread.sleep(10000l); + return "Hellow world"; + }); - future.cancel(false); + future.cancel(false); - try { - future.get(20, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException e1) { - e1.printStackTrace(); - } + try { + future.get(20, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e1) { + e1.printStackTrace(); + } - if (future.isDone() && !future.isCancelled()) { - try { - str = future.get(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - } + if (future.isDone() && !future.isCancelled()) { + try { + str = future.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + } - return str; + return str; - } + } } diff --git a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java index 8744027e40..f708804cae 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java +++ b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/BaeldungThreadFactory.java @@ -4,20 +4,20 @@ import java.util.concurrent.ThreadFactory; public class BaeldungThreadFactory implements ThreadFactory { - private int threadId; - private String name; + private int threadId; + private String name; - public BaeldungThreadFactory(String name) { - threadId = 1; - this.name = name; - } + public BaeldungThreadFactory(String name) { + threadId = 1; + this.name = name; + } - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r, name + "-Thread_" + threadId); - System.out.println("created new thread with id : " + threadId + " and name : " + t.getName()); - threadId++; - return t; - } + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r, name + "-Thread_" + threadId); + System.out.println("created new thread with id : " + threadId + " and name : " + t.getName()); + threadId++; + return t; + } } diff --git a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java index 04ba62d457..a69623c667 100644 --- a/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java +++ b/core-java/src/main/java/com/baeldung/concurrent/threadfactory/Task.java @@ -2,9 +2,9 @@ package com.baeldung.concurrent.threadfactory; public class Task implements Runnable { - @Override - public void run() { - // task details - } - + @Override + public void run() { + // task details + } + } diff --git a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java index 4afce56e39..7e6bb5d3b2 100644 --- a/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java +++ b/core-java/src/main/java/com/baeldung/filesystem/jndi/LookupFSJNDI.java @@ -14,26 +14,25 @@ public class LookupFSJNDI { super(); init(); } - + private void init() throws NamingException { Hashtable env = new Hashtable(); - - env.put (Context.INITIAL_CONTEXT_FACTORY, - "com.sun.jndi.fscontext.RefFSContextFactory"); + + env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); // URI to namespace (actual directory) env.put(Context.PROVIDER_URL, "file:./src/test/resources"); - + ctx = new InitialContext(env); } public InitialContext getCtx() { return ctx; } - + public File getFile(String fileName) { File file; try { - file = (File)getCtx().lookup(fileName); + file = (File) getCtx().lookup(fileName); } catch (NamingException e) { file = null; } diff --git a/core-java/src/main/java/com/baeldung/hashcode/entities/User.java b/core-java/src/main/java/com/baeldung/hashcode/entities/User.java index c1c5a82d31..c46c3de65a 100644 --- a/core-java/src/main/java/com/baeldung/hashcode/entities/User.java +++ b/core-java/src/main/java/com/baeldung/hashcode/entities/User.java @@ -18,13 +18,16 @@ public class User { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null) return false; - if (this.getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null) + return false; + if (this.getClass() != o.getClass()) + return false; User user = (User) o; return id != user.id && (!name.equals(user.name) && !email.equals(user.email)); } - + @Override public int hashCode() { int hash = 7; diff --git a/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java b/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java index 220b9a8ec6..21044f82c4 100644 --- a/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java +++ b/core-java/src/main/java/com/baeldung/jmx/JMXTutorialMainlauncher.java @@ -10,7 +10,6 @@ public class JMXTutorialMainlauncher { private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class); - public static void main(String[] args) { // TODO Auto-generated method stub diff --git a/core-java/src/main/java/com/baeldung/socket/EchoClient.java b/core-java/src/main/java/com/baeldung/socket/EchoClient.java index cf5c253276..fa3901d5da 100644 --- a/core-java/src/main/java/com/baeldung/socket/EchoClient.java +++ b/core-java/src/main/java/com/baeldung/socket/EchoClient.java @@ -8,9 +8,8 @@ import java.net.*; public class EchoClient { - private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class); - + private Socket clientSocket; private PrintWriter out; private BufferedReader in; diff --git a/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java b/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java index ae00fc7cb4..d79a7c3ecb 100644 --- a/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java +++ b/core-java/src/main/java/com/baeldung/stream/InfiniteStreams.java @@ -1,6 +1,5 @@ package com.baeldung.stream; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java/src/main/java/com/baeldung/string/StringHelper.java b/core-java/src/main/java/com/baeldung/string/StringHelper.java index dac0d1272e..a9cc71d36a 100644 --- a/core-java/src/main/java/com/baeldung/string/StringHelper.java +++ b/core-java/src/main/java/com/baeldung/string/StringHelper.java @@ -12,15 +12,10 @@ class StringHelper { } static String removeLastCharOptional(String s) { - return Optional.ofNullable(s) - .filter(str -> str.length() != 0) - .map(str -> str.substring(0, str.length() - 1)) - .orElse(s); + return Optional.ofNullable(s).filter(str -> str.length() != 0).map(str -> str.substring(0, str.length() - 1)).orElse(s); } static String removeLastCharRegexOptional(String s) { - return Optional.ofNullable(s) - .map(str -> str.replaceAll(".$", "")) - .orElse(s); + return Optional.ofNullable(s).map(str -> str.replaceAll(".$", "")).orElse(s); } } diff --git a/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java b/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java index 130218acc2..21164a976c 100644 --- a/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java +++ b/core-java/src/main/java/com/baeldung/stringtokenizer/MyTokenizer.java @@ -25,11 +25,7 @@ public class MyTokenizer { } public List getTokensWithCollection(String str) { - return Collections - .list(new StringTokenizer(str, ",")) - .stream() - .map(token -> (String) token) - .collect(Collectors.toList()); + return Collections.list(new StringTokenizer(str, ",")).stream().map(token -> (String) token).collect(Collectors.toList()); } public List getTokensFromFile(String path, String delim) { diff --git a/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java b/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java index bfb6681f7c..5631616ea8 100644 --- a/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java +++ b/core-java/src/main/java/com/baeldung/temporaladjuster/CustomTemporalAdjuster.java @@ -11,12 +11,12 @@ public class CustomTemporalAdjuster implements TemporalAdjuster { @Override public Temporal adjustInto(Temporal temporal) { switch (DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))) { - case FRIDAY: - return temporal.plus(3, ChronoUnit.DAYS); - case SATURDAY: - return temporal.plus(2, ChronoUnit.DAYS); - default: - return temporal.plus(1, ChronoUnit.DAYS); + case FRIDAY: + return temporal.plus(3, ChronoUnit.DAYS); + case SATURDAY: + return temporal.plus(2, ChronoUnit.DAYS); + default: + return temporal.plus(1, ChronoUnit.DAYS); } } } diff --git a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java index 69d7ff2390..a5f70d9df5 100644 --- a/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java +++ b/core-java/src/main/java/com/baeldung/transferqueue/Consumer.java @@ -9,7 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger; public class Consumer implements Runnable { private static final Logger LOG = LoggerFactory.getLogger(Consumer.class); - private final TransferQueue transferQueue; private final String name; private final int numberOfMessagesToConsume; diff --git a/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java b/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java index 2f1abef64e..8cddf31245 100644 --- a/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java +++ b/core-java/src/test/java/com/baeldung/concurrent/accumulator/LongAccumulatorUnitTest.java @@ -15,28 +15,24 @@ public class LongAccumulatorUnitTest { @Test public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException { - //given + // given ExecutorService executorService = Executors.newFixedThreadPool(8); LongBinaryOperator sum = Long::sum; LongAccumulator accumulator = new LongAccumulator(sum, 0L); int numberOfThreads = 4; int numberOfIncrements = 100; - //when - Runnable accumulateAction = () -> IntStream - .rangeClosed(0, numberOfIncrements) - .forEach(accumulator::accumulate); + // when + Runnable accumulateAction = () -> IntStream.rangeClosed(0, numberOfIncrements).forEach(accumulator::accumulate); for (int i = 0; i < numberOfThreads; i++) { executorService.execute(accumulateAction); } - - //then + // then executorService.awaitTermination(500, TimeUnit.MILLISECONDS); executorService.shutdown(); assertEquals(accumulator.get(), 20200); - } } diff --git a/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java b/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java index 70abd69fad..bf7a24347d 100644 --- a/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java +++ b/core-java/src/test/java/com/baeldung/hashcode/application/ApplicationTest.java @@ -24,7 +24,7 @@ public class ApplicationTest { @Test public void main_NoInputState_TextPrintedToConsole() throws Exception { - Application.main(new String[]{}); + Application.main(new String[] {}); assertEquals("User found in the collection", outContent.toString()); } } \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java b/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java index 0fd6f7dfe8..fe10266043 100644 --- a/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java +++ b/core-java/src/test/java/com/baeldung/java8/lambda/exceptions/LambdaExceptionWrappersUnitTest.java @@ -15,7 +15,6 @@ public class LambdaExceptionWrappersUnitTest { private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersUnitTest.class); - private List integers; @Before diff --git a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java index 7a23afa12f..5327e5f4f0 100644 --- a/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java +++ b/core-java/src/test/java/com/baeldung/list/listoflist/ListOfListsUnitTest.java @@ -29,12 +29,9 @@ public class ListOfListsUnitTest { @Test public void givenListOfLists_thenCheckNames() { - assertEquals("Pen 1", ((Pen) listOfLists.get(0) - .get(0)).getName()); - assertEquals("Pencil 1", ((Pencil) listOfLists.get(1) - .get(0)).getName()); - assertEquals("Rubber 1", ((Rubber) listOfLists.get(2) - .get(0)).getName()); + assertEquals("Pen 1", ((Pen) listOfLists.get(0).get(0)).getName()); + assertEquals("Pencil 1", ((Pencil) listOfLists.get(1).get(0)).getName()); + assertEquals("Rubber 1", ((Rubber) listOfLists.get(2).get(0)).getName()); } @SuppressWarnings("unchecked") @@ -43,11 +40,9 @@ public class ListOfListsUnitTest { ((ArrayList) listOfLists.get(1)).remove(0); listOfLists.remove(1); - assertEquals("Rubber 1", ((Rubber) listOfLists.get(1) - .get(0)).getName()); + assertEquals("Rubber 1", ((Rubber) listOfLists.get(1).get(0)).getName()); listOfLists.remove(0); - assertEquals("Rubber 1", ((Rubber) listOfLists.get(0) - .get(0)).getName()); + assertEquals("Rubber 1", ((Rubber) listOfLists.get(0).get(0)).getName()); } @Test @@ -67,11 +62,8 @@ public class ListOfListsUnitTest { list.add(pencils); list.add(rubbers); - assertEquals("Pen 1", ((Pen) list.get(0) - .get(0)).getName()); - assertEquals("Pencil 1", ((Pencil) list.get(1) - .get(0)).getName()); - assertEquals("Rubber 1", ((Rubber) list.get(2) - .get(0)).getName()); + assertEquals("Pen 1", ((Pen) list.get(0).get(0)).getName()); + assertEquals("Pencil 1", ((Pencil) list.get(1).get(0)).getName()); + assertEquals("Rubber 1", ((Rubber) list.get(2).get(0)).getName()); } } diff --git a/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java b/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java index 9d8d3c884b..5fb85bb2c4 100644 --- a/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java +++ b/core-java/src/test/java/com/baeldung/threadpool/CoreThreadPoolIntegrationTest.java @@ -13,7 +13,6 @@ public class CoreThreadPoolIntegrationTest { private static final Logger LOG = LoggerFactory.getLogger(CoreThreadPoolIntegrationTest.class); - @Test(timeout = 1000) public void whenCallingExecuteWithRunnable_thenRunnableIsExecuted() throws InterruptedException {