001/* 002 * Copyright (C) 2009-2011 Mathias Doenitz 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.parboiled.support; 018 019import org.parboiled.errors.GrammarException; 020 021/** 022 * Utility methods for grammar integrity checks. 023 */ 024public final class Checks { 025 026 private Checks() {} 027 028 /** 029 * Throws a GrammarException if the given condition is not met. 030 * 031 * @param condition the condition 032 * @param errorMessageFormat the error message format 033 * @param errorMessageArgs the error message arguments 034 */ 035 public static void ensure(boolean condition, String errorMessageFormat, Object... errorMessageArgs) { 036 if (!condition) { 037 throw new GrammarException(errorMessageFormat, errorMessageArgs); 038 } 039 } 040 041 /** 042 * Throws a GrammarException if the given condition is not met. 043 * 044 * @param condition the condition 045 * @param errorMessage the error message 046 */ 047 public static void ensure(boolean condition, String errorMessage) { 048 if (!condition) { 049 throw new GrammarException(errorMessage); 050 } 051 } 052 053}