package ex;
public enum Color {
RED,
GREEN
;
}
package ex;
public class Apple {
private Color color;
public Apple(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
@Override
public String toString() {
return "Apple{" +
"color=" + color +
'}';
}
}
package ex;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Apple> apples = new Farm().filterGreenApples(List.of(new Apple(Color.GREEN), new Apple(Color.RED), new Apple(Color.GREEN)));
apples.forEach(System.out::println);
}
}
package ex;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Apple> greenApples = new Farm().filterApplesByColor(List.of(new Apple(Color.GREEN), new Apple(Color.RED), new Apple(Color.GREEN)), Color.GREEN);
List<Apple> redApples = new Farm().filterApplesByColor(List.of(new Apple(Color.GREEN), new Apple(Color.RED), new Apple(Color.GREEN)), Color.RED);
greenApples.forEach(apple -> System.out.println("green : " + apple));
System.out.println("---");
redApples.forEach(apple -> System.out.println("red : " + apple));
}
}
package ex;
public class Apple {
private Color color;
private int weight;
public Apple(Color color, int weight) {
this.color = color;
this.weight = weight;
}
public Color getColor() {
return color;
}
public int getWeight() {
return weight;
}
@Override
public String toString() {
return "Apple{" +
"color=" + color +
", weight=" + weight +
'}';
}
}
DRY(Don't Repeat Yourself, 같은 것을 반복하지 말 것) 원칙
을 어긴다.💡참고