package com.refactor.observerpattern;

import com.refactor.observerpattern.observer.IMachineObserver;
import com.refactor.observerpattern.observer.ReapingMachineObserver;
import com.refactor.observerpattern.observer.SeedingMachineObserver;
import com.refactor.observerpattern.observer.WateringMachineObserver;

import java.util.Arrays;
import java.util.List;

public class WeatherData {
    private final SeedingMachine seedingMachine;
    private final ReapingMachine reapingMachine;
    private final WateringMachine wateringMachine;
    private List<IMachineObserver> machineObservers;

    public WeatherData(SeedingMachine seedingMachine, ReapingMachine reapingMachine, WateringMachine wateringMachine) {
        this.seedingMachine = seedingMachine;
        this.reapingMachine = reapingMachine;
        this.wateringMachine = wateringMachine;

        this.machineObservers = initMachineObservers();
    }

    public void measurementsChanged(int temp, int humidity, int windPower) {
        machineObservers.forEach(o -> o.update(temp, humidity, windPower));
    }

    private List<IMachineObserver> initMachineObservers() {
        SeedingMachineObserver seedingMachineObserver = new SeedingMachineObserver(seedingMachine);
        ReapingMachineObserver reapingMachineObserver = new ReapingMachineObserver(reapingMachine);
        WateringMachineObserver wateringMachineObserver = new WateringMachineObserver(wateringMachine);

        return Arrays.asList(seedingMachineObserver, reapingMachineObserver, wateringMachineObserver);
    }

}

@@ -384,157 +384,8 @@
 a %7B%0A
-    private final SeedingMachine seedingMachine;%0A    private final ReapingMachine reapingMachine;%0A    private final WateringMachine wateringMachine;%0A
     
@@ -558,431 +558,8 @@
 ) %7B%0A
-        this.seedingMachine = seedingMachine;%0A        this.reapingMachine = reapingMachine;%0A        this.wateringMachine = wateringMachine;%0A%0A        this.machineObservers = initMachineObservers();%0A    %7D%0A%0A    public void measurementsChanged(int temp, int humidity, int windPower) %7B%0A        machineObservers.forEach(o -%3E o.update(temp, humidity, windPower));%0A    %7D%0A%0A    private List%3CIMachineObserver%3E initMachineObservers() %7B
 %0A   
@@ -872,14 +872,31 @@
     
-return
+this.machineObservers =
  Arr
@@ -987,10 +987,170 @@
 %0A    %7D%0A%0A
+    public void measurementsChanged(int temp, int humidity, int windPower) %7B%0A        machineObservers.forEach(o -%3E o.update(temp, humidity, windPower));%0A    %7D%0A%0A
 %7D%0A

remove unused fields