public static void validateAllOrNone ( Props props , String ... keys ) { Objects . requireNonNull ( keys ) ; boolean allExist = true ; boolean someExist = false ; for ( String key : keys ) { Object val = props . get ( key ) ; allExist &= val != null ; someExist |= val != null ; } if ( someExist && ! allExist ) { throw new IllegalArgumentException ( "Either all of properties exist or none of them should exist for " + Arrays . toString ( keys ) ) ; } }
Validates if all of the keys exist of none of them exist