스트림
import java.util.stream.Stream;
public class MyDto {
private Integer a;
private Integer b;
private Integer c;
private Integer d;
private Integer e;
private Integer f;
public MyDto(Integer a, Integer b, Integer c, Integer d, Integer e, Integer f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
// getter/setter 생략
// ✅ 모든 값이 0인지 확인
public boolean isAllZero() {
return Stream.of(a, b, c, d, e, f)
.allMatch(value -> value != null && value == 0);
}
}
객체내에서
public class MyDto {
private int a;
private int b;
private int c;
public MyDto(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
// ✅ 모든 값이 0인지 체크하는 메서드
public boolean isAllZero() {
return a == 0 && b == 0 && c == 0;
}
}반응형