public static void failIfBadNumberOfArguments(
     CustomQuery customQuery, Type[] argumentsTypes, int... numbers) {
   for (int j : numbers) {
     if (j == argumentsTypes.length) {
       return;
     }
   }
   throw new IncompatibleTypesException(
       "The function "
           + customQuery.getName()
           + " has a wrong number of arguments. Usage:"
           + customQuery.getSqlOrder());
 }
 public static void failIfNotRasterDataSource(
     final CustomQuery customQuery, final Metadata metadata, final int argNumber)
     throws SemanticException, DriverException {
   if (!MetadataUtilities.isRaster(metadata)) {
     throw new SemanticException(
         customQuery.getName() + " requires a raster table as argument number " + argNumber);
   }
 }
 public static void failIfBadNumberOfTables(
     final CustomQuery customQuery, final Metadata[] metadatas, final int numberOfTables)
     throws SemanticException {
   if (numberOfTables != metadatas.length) {
     throw new SemanticException(
         customQuery.getName()
             + " has a wrong number of arguments: "
             + numberOfTables
             + " expected !");
   }
 }
 public static void failIfFieldDoesNotExist(
     final CustomQuery customQuery,
     final String fieldName,
     final int fieldIndex,
     final Metadata metadata)
     throws DriverException, SemanticException {
   if (-1 == fieldIndex) {
     throw new SemanticException(
         customQuery.getName() + ": no fieldname '" + fieldName + "' in your table !");
   }
 }
 public static void failIfNotOfTypes(CustomQuery customQuery, Type type, int... typesCodes) {
   for (int typeCode : typesCodes) {
     if (type.getTypeCode() == typeCode) {
       return;
     }
   }
   throw new IncompatibleTypesException(
       TypeFactory.getTypeName(type.getTypeCode())
           + " is not allowed with custom query "
           + customQuery.getName());
 }
 public static void failIfNotOfType(CustomQuery customQuery, Type type, int typeCode) {
   if (type.getTypeCode() != typeCode) {
     throw new IncompatibleTypesException(
         "Function "
             + customQuery.getName()
             + " only operates with "
             + TypeFactory.getTypeName(typeCode)
             + " types. "
             + TypeFactory.getTypeName(type.getTypeCode())
             + " found");
   }
 }
 public static void failIfNotNumeric(
     final CustomQuery customQuery, final Type type, final int argNumber)
     throws IncompatibleTypesException {
   if (!TypeFactory.isNumerical(type.getTypeCode())) {
     throw new IncompatibleTypesException(
         customQuery.getName()
             + " requires a numerical type as argument number "
             + argNumber
             + ". "
             + TypeFactory.getTypeName(type.getTypeCode())
             + " found");
   }
 }
  public static void failIfFieldIsNotOfType(
      final CustomQuery customQuery,
      final String fieldName,
      final int fieldIndex,
      final int typeCodeOfField,
      final Metadata metadata)
      throws DriverException, SemanticException {
    failIfFieldDoesNotExist(customQuery, fieldName, fieldIndex, metadata);

    final Type[] fieldTypes = MetadataUtilities.getFieldTypes(metadata);
    if (typeCodeOfField != fieldTypes[fieldIndex].getTypeCode()) {
      throw new IncompatibleTypesException(
          customQuery.getName()
              + ": "
              + fieldName
              + " is not of type "
              + TypeFactory.getTypeName(typeCodeOfField));
    }
  }