mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 20:59:29 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -30,26 +30,24 @@ import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The Main class serves as the entry point for executing the MapReduce program.
|
||||
* It processes a list of text inputs, applies the MapReduce pattern, and prints the results.
|
||||
* The Main class serves as the entry point for executing the MapReduce program. It processes a list
|
||||
* of text inputs, applies the MapReduce pattern, and prints the results.
|
||||
*/
|
||||
public class Main {
|
||||
private static final Logger logger = Logger.getLogger(Main.class.getName());
|
||||
|
||||
/**
|
||||
* The main method initiates the MapReduce process and displays the word count results.
|
||||
*
|
||||
* @param args Command-line arguments (not used).
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
List<String> inputs = Arrays.asList(
|
||||
"Hello world hello",
|
||||
"MapReduce is fun",
|
||||
"Hello from the other side",
|
||||
"Hello world"
|
||||
);
|
||||
List<String> inputs =
|
||||
Arrays.asList(
|
||||
"Hello world hello", "MapReduce is fun", "Hello from the other side", "Hello world");
|
||||
List<Map.Entry<String, Integer>> result = MapReduce.mapReduce(inputs);
|
||||
for (Map.Entry<String, Integer> entry : result) {
|
||||
logger.info(entry.getKey() + ": " + entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The MapReduce class orchestrates the MapReduce process,
|
||||
* calling the Mapper, Shuffler, and Reducer components.
|
||||
* The MapReduce class orchestrates the MapReduce process, calling the Mapper, Shuffler, and Reducer
|
||||
* components.
|
||||
*/
|
||||
public class MapReduce {
|
||||
private MapReduce() {
|
||||
throw new UnsupportedOperationException("MapReduce is a utility class and cannot be instantiated.");
|
||||
throw new UnsupportedOperationException(
|
||||
"MapReduce is a utility class and cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the MapReduce process on the given list of input strings.
|
||||
*
|
||||
|
||||
@@ -27,15 +27,16 @@ package com.iluwatar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The Mapper class is responsible for processing an input string
|
||||
* and generating a map of word occurrences.
|
||||
* The Mapper class is responsible for processing an input string and generating a map of word
|
||||
* occurrences.
|
||||
*/
|
||||
public class Mapper {
|
||||
private Mapper() {
|
||||
throw new UnsupportedOperationException("Mapper is a utility class and cannot be instantiated.");
|
||||
throw new UnsupportedOperationException(
|
||||
"Mapper is a utility class and cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a given input string into words and counts their occurrences.
|
||||
*
|
||||
|
||||
@@ -30,13 +30,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Reducer class is responsible for aggregating word counts from the shuffled data.
|
||||
*/
|
||||
/** The Reducer class is responsible for aggregating word counts from the shuffled data. */
|
||||
public class Reducer {
|
||||
private Reducer() {
|
||||
throw new UnsupportedOperationException("Reducer is a utility class and cannot be instantiated.");
|
||||
throw new UnsupportedOperationException(
|
||||
"Reducer is a utility class and cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums the occurrences of each word and sorts the results in descending order.
|
||||
*
|
||||
|
||||
@@ -29,14 +29,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Shuffler class is responsible for grouping word occurrences from multiple mappers.
|
||||
*/
|
||||
/** The Shuffler class is responsible for grouping word occurrences from multiple mappers. */
|
||||
public class Shuffler {
|
||||
|
||||
private Shuffler() {
|
||||
throw new UnsupportedOperationException("Shuffler is a utility class and cannot be instantiated.");
|
||||
throw new UnsupportedOperationException(
|
||||
"Shuffler is a utility class and cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges multiple word count maps into a single grouped map.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user