import com.softwarearchetypes.planvsexecution.resolutionmismatch.*;
import java.time.*;
import java.util.*;
import java.util.function.Function;
import java.util.stream.*;
public class ProductionResolutionExample {
public static void main(String[] args) {
System.out.println("=== Production Analysis: Monthly Plan vs Daily Execution ===\n");
// Monthly plan: 3000 units in January
MonthlyProductionPlan monthlyPlan = new MonthlyProductionPlan(
YearMonth.of(2025, 1),
3000
);
System.out.println("Monthly Plan:");
System.out.println(" Period: " + monthlyPlan.month());
System.out.println(" Target: " + monthlyPlan.targetQuantity() + " units");
// Daily execution: simulated week
List<DailyProductionExecution> week1 = List.of(
new DailyProductionExecution(LocalDate.of(2025, 1, 2), 145, 5, 2),
new DailyProductionExecution(LocalDate.of(2025, 1, 3), 138, 8, 1),
new DailyProductionExecution(LocalDate.of(2025, 1, 6), 142, 6, 3),
new DailyProductionExecution(LocalDate.of(2025, 1, 7), 150, 4, 0),
new DailyProductionExecution(LocalDate.of(2025, 1, 8), 135, 10, 2)
);
DailyProductionExecutionHistory execution =
new DailyProductionExecutionHistory(week1);
System.out.println("\nDaily Execution (Week 1):");
week1.forEach(day -> {
int net = day.produced() - day.defects() + day.rework();
System.out.println(" " + day.date() + ": " +
day.produced() + " produced, " + net + " net");
});
// Test different mapping strategies
System.out.println("\n=== Mapping Strategies ===\n");
// Strategy 1: 30 days
Function<MonthlyProductionPlan, List<DailyProductionExecution>> split30 =
plan -> IntStream.range(1, 31)
.mapToObj(day -> new DailyProductionExecution(
LocalDate.of(plan.month().getYear(), plan.month().getMonth(), day),
plan.targetQuantity() / 30, 0, 0
))
.toList();
System.out.println("Strategy 1: Split over 30 days");
System.out.println(" Daily target: " + (3000 / 30) + " units");
ProductionTolerance tolerance1 = ProductionTolerance.builder()
.allowedDeviation(10)
.build();
boolean result1 = tolerance1.isWithinTolerance(
monthlyPlan, execution, split30
);
System.out.println(" Result: " + (result1 ? "✓ PASS" : "✗ FAIL"));
// Strategy 2: 22 workdays
Function<MonthlyProductionPlan, List<DailyProductionExecution>> split22 =
plan -> IntStream.range(1, 23)
.mapToObj(day -> new DailyProductionExecution(
LocalDate.of(plan.month().getYear(), plan.month().getMonth(), day),
(int) Math.ceil(plan.targetQuantity() / 22.0), 0, 0
))
.toList();
System.out.println("\nStrategy 2: Split over 22 workdays");
System.out.println(" Daily target: " + Math.ceil(3000 / 22.0) + " units");
ProductionTolerance tolerance2 = ProductionTolerance.builder()
.allowedDeviation(15)
.build();
boolean result2 = tolerance2.isWithinTolerance(
monthlyPlan, execution, split22
);
System.out.println(" Result: " + (result2 ? "✓ PASS" : "✗ FAIL"));
// Summary
System.out.println("\n=== Summary ===");
System.out.println("Choosing the right mapping strategy is critical!");
System.out.println("Same data + different mapping = different results");
}
}