diff --git a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java index cecd8a894..be83cc315 100644 --- a/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java +++ b/abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java @@ -32,7 +32,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** - * Test for abstract factory + * Test for abstract factory. */ public class AbstractFactoryTest { diff --git a/composite/src/main/java/com/iluwatar/composite/Word.java b/composite/src/main/java/com/iluwatar/composite/Word.java index 933d38bde..235d1c31f 100644 --- a/composite/src/main/java/com/iluwatar/composite/Word.java +++ b/composite/src/main/java/com/iluwatar/composite/Word.java @@ -37,6 +37,10 @@ public class Word extends LetterComposite { letters.forEach(this::add); } + /** + * Constructor. + * @param letters to include + */ public Word(char... letters) { for (char letter : letters) { this.add(new Letter(letter)); diff --git a/layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java b/layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java index 403816421..885852519 100644 --- a/layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java +++ b/layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java @@ -23,12 +23,12 @@ package com.iluwatar.layers.service; -import com.iluwatar.layers.dto.CakeInfo; -import com.iluwatar.layers.dto.CakeLayerInfo; -import com.iluwatar.layers.dto.CakeToppingInfo; import com.iluwatar.layers.dao.CakeDao; import com.iluwatar.layers.dao.CakeLayerDao; import com.iluwatar.layers.dao.CakeToppingDao; +import com.iluwatar.layers.dto.CakeInfo; +import com.iluwatar.layers.dto.CakeLayerInfo; +import com.iluwatar.layers.dto.CakeToppingInfo; import com.iluwatar.layers.entity.Cake; import com.iluwatar.layers.entity.CakeLayer; import com.iluwatar.layers.entity.CakeTopping; @@ -40,7 +40,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; - import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Service; diff --git a/page-object/src/main/java/com/iluwatar/pageobject/App.java b/page-object/src/main/java/com/iluwatar/pageobject/App.java index 9c4c21607..ee9f58504 100644 --- a/page-object/src/main/java/com/iluwatar/pageobject/App.java +++ b/page-object/src/main/java/com/iluwatar/pageobject/App.java @@ -70,12 +70,13 @@ public final class App { File applicationFile = new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); - // should work for unix like OS (mac, unix etc...) + // Should work for unix like OS (mac, unix etc...) if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(applicationFile); } else { - // java Desktop not supported - above unlikely to work for Windows so try following instead... + // Java Desktop not supported - above unlikely to work for Windows so try the + // following instead... Runtime.getRuntime().exec("cmd.exe start " + applicationFile); } diff --git a/pom.xml b/pom.xml index 1ab896068..423a3b705 100644 --- a/pom.xml +++ b/pom.xml @@ -384,9 +384,6 @@ - org.apache.maven.plugins maven-checkstyle-plugin @@ -403,7 +400,8 @@ checkstyle-suppressions.xml UTF-8 true - true + warning + false diff --git a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/App.java b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/App.java index 853c6fcfe..0ead44307 100644 --- a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/App.java +++ b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/App.java @@ -23,20 +23,22 @@ package com.iluwatar.producer.consumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** - * Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces coupling between - * Producer and Consumer by separating Identification of work with Execution of Work. - *

- * In producer consumer design pattern a shared queue is used to control the flow and this separation allows you to code - * producer and consumer separately. It also addresses the issue of different timing require to produce item or - * consuming item. by using producer consumer pattern both Producer and Consumer Thread can work with different speed. + * Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces + * coupling between Producer and Consumer by separating Identification of work with + * Execution of Work. + * + *

In producer consumer design pattern a shared queue is used to control the flow and this + * separation allows you to code producer and consumer separately. It also addresses the issue + * of different timing require to produce item or consuming item. by using producer consumer + * pattern both Producer and Consumer Thread can work with different speed. * */ public class App { @@ -44,7 +46,7 @@ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** - * Program entry point + * Program entry point. * * @param args * command line args diff --git a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Consumer.java b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Consumer.java index 3e4e9aadb..5598f3e45 100644 --- a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Consumer.java +++ b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Consumer.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Class responsible for consume the {@link Item} produced by {@link Producer} + * Class responsible for consume the {@link Item} produced by {@link Producer}. */ public class Consumer { @@ -43,12 +43,13 @@ public class Consumer { } /** - * Consume item from the queue + * Consume item from the queue. */ public void consume() throws InterruptedException { Item item = queue.take(); - LOGGER.info("Consumer [{}] consume item [{}] produced by [{}]", name, item.getId(), item.getProducer()); + LOGGER.info("Consumer [{}] consume item [{}] produced by [{}]", name, + item.getId(), item.getProducer()); } } diff --git a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Producer.java b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Producer.java index e8c79afd4..6d4ca0096 100644 --- a/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Producer.java +++ b/producer-consumer/src/main/java/com/iluwatar/producer/consumer/Producer.java @@ -27,7 +27,7 @@ import java.util.Random; /** * Class responsible for producing unit of work that can be expressed as {@link Item} and submitted - * to queue + * to queue. */ public class Producer { @@ -45,7 +45,7 @@ public class Producer { } /** - * Put item in the queue + * Put item in the queue. */ public void produce() throws InterruptedException { diff --git a/promise/src/main/java/com/iluwatar/promise/App.java b/promise/src/main/java/com/iluwatar/promise/App.java index c201d3352..c016b67ff 100644 --- a/promise/src/main/java/com/iluwatar/promise/App.java +++ b/promise/src/main/java/com/iluwatar/promise/App.java @@ -22,8 +22,6 @@ */ package com.iluwatar.promise; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -32,10 +30,12 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** - * - * The Promise object is used for asynchronous computations. A Promise represents an operation - * that hasn't completed yet, but is expected in the future. + * The Promise object is used for asynchronous computations. A Promise represents an operation + * that hasn't completed yet, but is expected in the future. * *

A Promise represents a proxy for a value not necessarily known when the promise is created. It * allows you to associate dependent promises to an asynchronous action's eventual success value or @@ -49,15 +49,14 @@ import java.util.concurrent.Executors; *

  • Prevents callback hell and provides callback aggregation * * - *

    - * In this application the usage of promise is demonstrated with two examples: + *

    In this application the usage of promise is demonstrated with two examples: *

      *
    • Count Lines: In this example a file is downloaded and its line count is calculated. * The calculated line count is then consumed and printed on console. *
    • Lowest Character Frequency: In this example a file is downloaded and its lowest frequency * character is found and printed on console. This happens via a chain of promises, we start with - * a file download promise, then a promise of character frequency, then a promise of lowest frequency - * character which is finally consumed and result is printed on console. + * a file download promise, then a promise of character frequency, then a promise of lowest + * frequency character which is finally consumed and result is printed on console. *
    * * @see CompletableFuture @@ -76,7 +75,7 @@ public class App { } /** - * Program entry point + * Program entry point. * @param args arguments * @throws InterruptedException if main thread is interrupted. * @throws ExecutionException if an execution error occurs. diff --git a/promise/src/main/java/com/iluwatar/promise/Utility.java b/promise/src/main/java/com/iluwatar/promise/Utility.java index 472f7b0a5..09c7f6ddc 100644 --- a/promise/src/main/java/com/iluwatar/promise/Utility.java +++ b/promise/src/main/java/com/iluwatar/promise/Utility.java @@ -23,9 +23,6 @@ package com.iluwatar.promise; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -39,8 +36,11 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** - * Utility to perform various operations + * Utility to perform various operations. */ public class Utility { @@ -71,7 +71,8 @@ public class Utility { } /** - * @return the character with lowest frequency if it exists, {@code Optional.empty()} otherwise. + * Return the character with the lowest frequency, if exists. + * @return the character, {@code Optional.empty()} otherwise. */ public static Character lowestFrequencyChar(Map charFrequency) { Character lowestFrequencyChar = null; @@ -92,7 +93,8 @@ public class Utility { } /** - * @return number of lines in the file at provided location. 0 if file does not exist. + * Count the number of lines in a file. + * @return number of lines, 0 if file does not exist. */ public static Integer countLines(String fileLocation) { int lineCount = 0; diff --git a/role-object/src/main/java/com/iluwatar/roleobject/ApplicationRoleObject.java b/role-object/src/main/java/com/iluwatar/roleobject/ApplicationRoleObject.java index b8296daba..eb76ef34a 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/ApplicationRoleObject.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/ApplicationRoleObject.java @@ -20,13 +20,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; +import static com.iluwatar.roleobject.Role.Borrower; +import static com.iluwatar.roleobject.Role.Investor; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.iluwatar.roleobject.Role.*; - /** * The Role Object pattern suggests to model context-specific views * of an object as separate role objects which are @@ -39,55 +41,60 @@ import static com.iluwatar.roleobject.Role.*; * investor, respectively. Both roles could as well be played by a single {@link Customer} object. * The common superclass for customer-specific roles is provided by {@link CustomerRole}, * which also supports the {@link Customer} interface. - *

    - * The {@link CustomerRole} class is abstract and not meant to be instantiated. - * Concrete subclasses of {@link CustomerRole}, for example {@link BorrowerRole} or {@link InvestorRole}, - * define and implement the interface for specific roles. It is only + * + *

    The {@link CustomerRole} class is abstract and not meant to be instantiated. + * Concrete subclasses of {@link CustomerRole}, for example {@link BorrowerRole} + * or {@link InvestorRole}, define and implement the interface for specific roles. It is only * these subclasses which are instantiated at runtime. - * The {@link BorrowerRole} class defines the context-specific view of {@link Customer} objects as needed by the loan department. + * The {@link BorrowerRole} class defines the context-specific view of {@link Customer} + * objects as needed by the loan department. * It defines additional operations to manage the customer’s * credits and securities. Similarly, the {@link InvestorRole} class adds operations specific * to the investment department’s view of customers. - * A client like the loan application may either work with objects of the {@link CustomerRole} class, using the interface class - * {@link Customer}, or with objects of concrete {@link CustomerRole} subclasses. Suppose the loan application knows a particular - * {@link Customer} instance through its {@link Customer} interface. The loan application may want to check whether the {@link Customer} - * object plays the role of Borrower. - * To this end it calls {@link Customer#hasRole(Role)} with a suitable role specification. For the purpose of - * our example, let’s assume we can name roles with enum. - * If the {@link Customer} object can play the role named “Borrower,” the loan application will ask it - * to return a reference to the corresponding object. + * A client like the loan application may either work with objects of the {@link CustomerRole} + * class, using the interface class {@link Customer}, or with objects of concrete + * {@link CustomerRole} subclasses. Suppose the loan application knows a particular + * {@link Customer} instance through its {@link Customer} interface. The loan application + * may want to check whether the {@link Customer} object plays the role of Borrower. + * To this end it calls {@link Customer#hasRole(Role)} with a suitable role specification. For + * the purpose of our example, let’s assume we can name roles with enum. + * If the {@link Customer} object can play the role named “Borrower,” the loan application will + * ask it to return a reference to the corresponding object. * The loan application may now use this reference to call Borrower-specific operations. */ public class ApplicationRoleObject { - private static final Logger logger = LoggerFactory.getLogger(Role.class); + private static final Logger logger = LoggerFactory.getLogger(Role.class); - public static void main(String[] args) { - Customer customer = Customer.newCustomer(Borrower, Investor); + /** + * Main entry point. + * + * @param args program arguments + */ + public static void main(String[] args) { + Customer customer = Customer.newCustomer(Borrower, Investor); - logger.info(" the new customer created : {}", customer); + logger.info(" the new customer created : {}", customer); - boolean hasBorrowerRole = customer.hasRole(Borrower); - logger.info(" customer has a borrowed role - {}", hasBorrowerRole); - boolean hasInvestorRole = customer.hasRole(Investor); - logger.info(" customer has an investor role - {}", hasInvestorRole); + boolean hasBorrowerRole = customer.hasRole(Borrower); + logger.info(" customer has a borrowed role - {}", hasBorrowerRole); + boolean hasInvestorRole = customer.hasRole(Investor); + logger.info(" customer has an investor role - {}", hasInvestorRole); - customer.getRole(Investor, InvestorRole.class) - .ifPresent(inv -> { - inv.setAmountToInvest(1000); - inv.setName("Billy"); - }); - customer.getRole(Borrower, BorrowerRole.class) - .ifPresent(inv -> inv.setName("Johny")); - - customer.getRole(Investor, InvestorRole.class) - .map(InvestorRole::invest) - .ifPresent(logger::info); - - customer.getRole(Borrower, BorrowerRole.class) - .map(BorrowerRole::borrow) - .ifPresent(logger::info); - } + customer.getRole(Investor, InvestorRole.class) + .ifPresent(inv -> { + inv.setAmountToInvest(1000); + inv.setName("Billy"); + }); + customer.getRole(Borrower, BorrowerRole.class) + .ifPresent(inv -> inv.setName("Johny")); + customer.getRole(Investor, InvestorRole.class) + .map(InvestorRole::invest) + .ifPresent(logger::info); + customer.getRole(Borrower, BorrowerRole.class) + .map(BorrowerRole::borrow) + .ifPresent(logger::info); + } } diff --git a/role-object/src/main/java/com/iluwatar/roleobject/BorrowerRole.java b/role-object/src/main/java/com/iluwatar/roleobject/BorrowerRole.java index 425d9511d..19db1c823 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/BorrowerRole.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/BorrowerRole.java @@ -20,21 +20,23 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; -public class BorrowerRole extends CustomerRole{ - private String name; +public class BorrowerRole extends CustomerRole { - public String getName() { - return name; - } + private String name; - public void setName(String name) { - this.name = name; - } + public String getName() { + return name; + } - public String borrow(){ - return String.format("Borrower %s wants to get some money.",name); - } + public void setName(String name) { + this.name = name; + } + + public String borrow() { + return String.format("Borrower %s wants to get some money.", name); + } } diff --git a/role-object/src/main/java/com/iluwatar/roleobject/Customer.java b/role-object/src/main/java/com/iluwatar/roleobject/Customer.java index ebcddff4b..1d21c5cc8 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/Customer.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/Customer.java @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; import java.util.Optional; @@ -29,51 +30,52 @@ import java.util.Optional; */ public abstract class Customer { - /** - * Add specific role @see {@link Role} - * - * @param role to add - * @return true if the operation has been successful otherwise false - */ - public abstract boolean addRole(Role role); + /** + * Add specific role @see {@link Role}. + * @param role to add + * @return true if the operation has been successful otherwise false + */ + public abstract boolean addRole(Role role); - /** - * Check specific role @see {@link Role} - * - * @param role to check - * @return true if the role exists otherwise false - */ + /** + * Check specific role @see {@link Role}. + * @param role to check + * @return true if the role exists otherwise false + */ - public abstract boolean hasRole(Role role); + public abstract boolean hasRole(Role role); - /** - * Remove specific role @see {@link Role} - * - * @param role to remove - * @return true if the operation has been successful otherwise false - */ - public abstract boolean remRole(Role role); + /** + * Remove specific role @see {@link Role}. + * @param role to remove + * @return true if the operation has been successful otherwise false + */ + public abstract boolean remRole(Role role); - /** - * Get specific instance associated with this role @see {@link Role} - * - * @param role to get - * @param expectedRole instance class expected to get - * @return optional with value if the instance exists and corresponds expected class - */ - public abstract Optional getRole(Role role, Class expectedRole); + /** + * Get specific instance associated with this role @see {@link Role}. + * @param role to get + * @param expectedRole instance class expected to get + * @return optional with value if the instance exists and corresponds expected class + */ + public abstract Optional getRole(Role role, Class expectedRole); - public static Customer newCustomer() { - return new CustomerCore(); - } - - public static Customer newCustomer(Role... role) { - Customer customer = newCustomer(); - for (Role r : role) { - customer.addRole(r); - } - return customer; + public static Customer newCustomer() { + return new CustomerCore(); + } + + /** + * Create {@link Customer} with given roles. + * @param role roles + * @return Customer + */ + public static Customer newCustomer(Role... role) { + Customer customer = newCustomer(); + for (Role r : role) { + customer.addRole(r); } + return customer; + } } diff --git a/role-object/src/main/java/com/iluwatar/roleobject/CustomerCore.java b/role-object/src/main/java/com/iluwatar/roleobject/CustomerCore.java index 5de27aa92..670a53904 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/CustomerCore.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/CustomerCore.java @@ -20,56 +20,60 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; /** - * Core class to store different customer roles + * Core class to store different customer roles. * - * @see CustomerRole - * Note: not thread safe + * @see CustomerRole Note: not thread safe */ public class CustomerCore extends Customer { - private Map roles; + private Map roles; - public CustomerCore() { - roles = new HashMap<>(); - } + public CustomerCore() { + roles = new HashMap<>(); + } - @Override - public boolean addRole(Role role) { - return role - .instance() - .map(inst -> { - roles.put(role, inst); - return true; - }) - .orElse(false); - } + @Override + public boolean addRole(Role role) { + return role + .instance() + .map(inst -> { + roles.put(role, inst); + return true; + }) + .orElse(false); + } - @Override - public boolean hasRole(Role role) { - return roles.containsKey(role); - } + @Override + public boolean hasRole(Role role) { + return roles.containsKey(role); + } - @Override - public boolean remRole(Role role) { - return Objects.nonNull(roles.remove(role)); - } + @Override + public boolean remRole(Role role) { + return Objects.nonNull(roles.remove(role)); + } - @Override - public Optional getRole(Role role, Class expectedRole) { - return Optional - .ofNullable(roles.get(role)) - .filter(expectedRole::isInstance) - .map(expectedRole::cast); - } + @Override + public Optional getRole(Role role, Class expectedRole) { + return Optional + .ofNullable(roles.get(role)) + .filter(expectedRole::isInstance) + .map(expectedRole::cast); + } - @Override - public String toString() { - String roles = Arrays.toString(this.roles.keySet().toArray()); - return "Customer{roles=" + roles + "}"; - } + @Override + public String toString() { + String roles = Arrays.toString(this.roles.keySet().toArray()); + return "Customer{roles=" + roles + "}"; + } } diff --git a/role-object/src/main/java/com/iluwatar/roleobject/CustomerRole.java b/role-object/src/main/java/com/iluwatar/roleobject/CustomerRole.java index 40fe2341b..7f1805924 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/CustomerRole.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/CustomerRole.java @@ -20,9 +20,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; /** - * Key abstraction for segregated roles + * Key abstraction for segregated roles. */ -public abstract class CustomerRole extends CustomerCore{} +public abstract class CustomerRole extends CustomerCore{ +} diff --git a/role-object/src/main/java/com/iluwatar/roleobject/InvestorRole.java b/role-object/src/main/java/com/iluwatar/roleobject/InvestorRole.java index d6ec6bc42..d95289a07 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/InvestorRole.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/InvestorRole.java @@ -20,29 +20,32 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; public class InvestorRole extends CustomerRole { - private String name; - private long amountToInvest; - public String getName() { - return name; - } + private String name; - public void setName(String name) { - this.name = name; - } + private long amountToInvest; - public long getAmountToInvest() { - return amountToInvest; - } + public String getName() { + return name; + } - public void setAmountToInvest(long amountToInvest) { - this.amountToInvest = amountToInvest; - } + public void setName(String name) { + this.name = name; + } - public String invest() { - return String.format("Investor %s has invested %d dollars", name, amountToInvest); - } + public long getAmountToInvest() { + return amountToInvest; + } + + public void setAmountToInvest(long amountToInvest) { + this.amountToInvest = amountToInvest; + } + + public String invest() { + return String.format("Investor %s has invested %d dollars", name, amountToInvest); + } } diff --git a/role-object/src/main/java/com/iluwatar/roleobject/Role.java b/role-object/src/main/java/com/iluwatar/roleobject/Role.java index f6c739891..74863ad84 100644 --- a/role-object/src/main/java/com/iluwatar/roleobject/Role.java +++ b/role-object/src/main/java/com/iluwatar/roleobject/Role.java @@ -20,36 +20,41 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + package com.iluwatar.roleobject; +import java.util.Optional; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Optional; - /** - * Possible roles + * Possible roles. */ public enum Role { - Borrower(BorrowerRole.class), Investor(InvestorRole.class); - private Class typeCst; + Borrower(BorrowerRole.class), Investor(InvestorRole.class); - Role(Class typeCst) { - this.typeCst = typeCst; - } - - private static final Logger logger = LoggerFactory.getLogger(Role.class); - - @SuppressWarnings("unchecked") - public Optional instance() { - Class typeCst = this.typeCst; - try { - return (Optional) Optional.of(typeCst.newInstance()); - } catch (InstantiationException | IllegalAccessException e) { - logger.error("error creating an object", e); - } - return Optional.empty(); + private Class typeCst; + + Role(Class typeCst) { + this.typeCst = typeCst; + } + + private static final Logger logger = LoggerFactory.getLogger(Role.class); + + /** + * Get instance. + */ + @SuppressWarnings("unchecked") + public Optional instance() { + Class typeCst = this.typeCst; + try { + return (Optional) Optional.of(typeCst.newInstance()); + } catch (InstantiationException | IllegalAccessException e) { + logger.error("error creating an object", e); } + return Optional.empty(); + } }