Resolves checkstyle errors for delegation dependency-injection dirty-flag double-buffer double-checked-locking double-dispatch (#1068)
* Reduces checkstyle errors in delegation * Reduces checkstyle errors in dependency-injection * Reduces checkstyle errors in dirty-flag * Reduces checkstyle errors in double-buffer * Reduces checkstyle errors in double-checked-locking * Reduces checkstyle errors in double-dispatch
This commit is contained in:
committed by
Ilkka Seppälä
parent
01e489c77b
commit
f2c91eb836
@ -23,45 +23,49 @@
|
||||
|
||||
package com.iluwatar.dirtyflag;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This application demonstrates the <b>Dirty Flag</b> pattern. The dirty flag behavioral pattern
|
||||
* allows you to avoid expensive operations that would just need to be done again anyway. This is a
|
||||
* simple pattern that really just explains how to add a bool value to your class that you can set
|
||||
* anytime a property changes. This will let your class know that any results it may have previously
|
||||
* calculated will need to be calculated again when they’re requested. Once the results are
|
||||
* re-calculated, then the bool value can be cleared.
|
||||
*
|
||||
* This application demonstrates the <b>Dirty Flag</b> pattern. The dirty flag behavioral pattern allows you to avoid
|
||||
* expensive operations that would just need to be done again anyway. This is a simple pattern that really just explains
|
||||
* how to add a bool value to your class that you can set anytime a property changes. This will let your class know that
|
||||
* any results it may have previously calculated will need to be calculated again when they’re requested. Once the
|
||||
* results are re-calculated, then the bool value can be cleared.
|
||||
*
|
||||
* There are some points that need to be considered before diving into using this pattern:- there are some things you’ll
|
||||
* need to consider:- (1) Do you need it? This design pattern works well when the results to be calculated are difficult
|
||||
* or resource intensive to compute. You want to save them. You also don’t want to be calculating them several times in
|
||||
* a row when only the last one counts. (2) When do you set the dirty flag? Make sure that you set the dirty flag within
|
||||
* the class itself whenever an important property changes. This property should affect the result of the calculated
|
||||
* result and by changing the property, that makes the last result invalid. (3) When do you clear the dirty flag? It
|
||||
* might seem obvious that the dirty flag should be cleared whenever the result is calculated with up-to-date
|
||||
* information but there are other times when you might want to clear the flag.
|
||||
* <p>There are some points that need to be considered before diving into using this pattern:-
|
||||
* there are some things you’ll need to consider:- (1) Do you need it? This design pattern works
|
||||
* well when the results to be calculated are difficult or resource intensive to compute. You want
|
||||
* to save them. You also don’t want to be calculating them several times in a row when only the
|
||||
* last one counts. (2) When do you set the dirty flag? Make sure that you set the dirty flag within
|
||||
* the class itself whenever an important property changes. This property should affect the result
|
||||
* of the calculated result and by changing the property, that makes the last result invalid. (3)
|
||||
* When do you clear the dirty flag? It might seem obvious that the dirty flag should be cleared
|
||||
* whenever the result is calculated with up-to-date information but there are other times when you
|
||||
* might want to clear the flag.
|
||||
*
|
||||
* In this example, the {@link DataFetcher} holds the <i>dirty flag</i>. It fetches and re-fetches from <i>world.txt</i>
|
||||
* when needed. {@link World} mainly serves the data to the front-end.
|
||||
* <p>In this example, the {@link DataFetcher} holds the <i>dirty flag</i>. It fetches and
|
||||
* re-fetches from <i>world.txt</i> when needed. {@link World} mainly serves the data to the
|
||||
* front-end.
|
||||
*/
|
||||
public class App {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program execution point
|
||||
* Program execution point.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
executorService.scheduleAtFixedRate(new Runnable() {
|
||||
final World world = new World();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<String> countries = world.fetch();
|
||||
@ -74,10 +78,9 @@ public class App {
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args
|
||||
* command line args
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
App app = new App();
|
||||
|
@ -23,22 +23,19 @@
|
||||
|
||||
package com.iluwatar.dirtyflag;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A mock database manager -- Fetches data from a raw file.
|
||||
*
|
||||
* @author swaisuan
|
||||
*
|
||||
* @author swaisuan
|
||||
*/
|
||||
public class DataFetcher {
|
||||
|
||||
@ -61,7 +58,7 @@ public class DataFetcher {
|
||||
|
||||
/**
|
||||
* Fetches data/content from raw file.
|
||||
*
|
||||
*
|
||||
* @return List of strings
|
||||
*/
|
||||
public List<String> fetch() {
|
||||
|
@ -27,11 +27,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* A middle-layer app that calls/passes along data from the back-end.
|
||||
*
|
||||
* @author swaisuan
|
||||
*
|
||||
* @author swaisuan
|
||||
*/
|
||||
public class World {
|
||||
|
||||
@ -44,9 +42,8 @@ public class World {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Calls {@link DataFetcher} to fetch data from back-end.
|
||||
*
|
||||
*
|
||||
* @return List of strings
|
||||
*/
|
||||
public List<String> fetch() {
|
||||
|
Reference in New Issue
Block a user