📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
		@@ -23,8 +23,7 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.singleton;
 | 
			
		||||
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * <p>Singleton pattern ensures that the class can have only one existing instance per Java
 | 
			
		||||
@@ -61,10 +60,9 @@ import org.slf4j.LoggerFactory;
 | 
			
		||||
 * {@link InitializingOnDemandHolderIdiom}. However, this implementation requires at least Java 8
 | 
			
		||||
 * API level to work.</p>
 | 
			
		||||
 */
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class App {
 | 
			
		||||
 | 
			
		||||
  private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Program entry point.
 | 
			
		||||
   *
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public final class ThreadSafeDoubleCheckLocking {
 | 
			
		||||
  public static ThreadSafeDoubleCheckLocking getInstance() {
 | 
			
		||||
    // local variable increases performance by 25 percent
 | 
			
		||||
    // Joshua Bloch "Effective Java, Second Edition", p. 283-284
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    var result = instance;
 | 
			
		||||
    // Check if singleton instance is initialized.
 | 
			
		||||
    // If it is initialized then we can return the instance.
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ import org.junit.jupiter.api.Test;
 | 
			
		||||
 * @author Jeroen Meulemeester
 | 
			
		||||
 * @author Richard Jones
 | 
			
		||||
 */
 | 
			
		||||
public abstract class SingletonTest<S> {
 | 
			
		||||
abstract class SingletonTest<S> {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * The singleton's getInstance method.
 | 
			
		||||
@@ -69,7 +69,7 @@ public abstract class SingletonTest<S> {
 | 
			
		||||
   * Test the singleton in a non-concurrent setting.
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testMultipleCallsReturnTheSameObjectInSameThread() {
 | 
			
		||||
  void testMultipleCallsReturnTheSameObjectInSameThread() {
 | 
			
		||||
    // Create several instances in the same calling thread
 | 
			
		||||
    var instance1 = this.singletonInstanceMethod.get();
 | 
			
		||||
    var instance2 = this.singletonInstanceMethod.get();
 | 
			
		||||
@@ -84,7 +84,7 @@ public abstract class SingletonTest<S> {
 | 
			
		||||
   * Test singleton instance in a concurrent setting.
 | 
			
		||||
   */
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testMultipleCallsReturnTheSameObjectInDifferentThreads() throws Exception {
 | 
			
		||||
  void testMultipleCallsReturnTheSameObjectInDifferentThreads() throws Exception {
 | 
			
		||||
    assertTimeout(ofMillis(10000), () -> {
 | 
			
		||||
      // Create 10000 tasks and inside each callable instantiate the singleton class
 | 
			
		||||
      final var tasks = IntStream.range(0, 10000)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user