package org.rakam.util;

import io.netty.handler.codec.http.HttpResponseStatus;

import javax.annotation.Nullable;


public final class ValidationUtil {

    private ValidationUtil() throws InstantiationException {
        throw new InstantiationException("The class is not created for instantiation");
    }

    public static void checkProject(String project) {
        checkArgument(project != null, "project is null");
        if(!project.matches("^[0-9A-Za-z_]+$")) {
            throw new IllegalArgumentException("Project id is not valid.");
        }
    }
    public static void checkCollection(String collection) {
        checkArgument(collection != null, "collection is null");
        if(!collection.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
            throw new IllegalArgumentException("Collection is not valid.");
        }
    }

    public static String checkTableColumn(String column, String type) {
        checkArgument(type != null, type+" is null");
        if(!column.matches("^[a-zA-Z_][a-zA-Z0-9_]*$")) {
            throw new IllegalArgumentException(type+" is not valid.");
        }
        return column;
    }

    public static void checkArgument(boolean expression, @Nullable String errorMessage) {
        if (!expression) {
            if(errorMessage == null) {
                throw new RakamException(HttpResponseStatus.BAD_REQUEST);
            } else {
                throw new RakamException(errorMessage, HttpResponseStatus.BAD_REQUEST);
            }
        }
    }
}

@@ -25,16 +25,58 @@
 %0Aimport 
+javax.annotation.Nullable;%0A%0Aimport static 
 io.netty
@@ -117,43 +117,20 @@
 atus
-;%0A%0Aimport javax.annotation.Nullable
+.BAD_REQUEST
 ;%0A%0A%0A
@@ -782,39 +782,29 @@
   throw new 
-IllegalArgument
+Rakam
 Exception(%22C
@@ -819,32 +819,45 @@
 n is not valid.%22
+, BAD_REQUEST
 );%0A        %7D%0A   
@@ -1062,39 +1062,29 @@
   throw new 
-IllegalArgument
+Rakam
 Exception(ty
@@ -1094,32 +1094,45 @@
 %22 is not valid.%22
+, BAD_REQUEST
 );%0A        %7D%0A   
@@ -1355,35 +1355,16 @@
 ception(
-HttpResponseStatus.
 BAD_REQU
@@ -1445,35 +1445,16 @@
 essage, 
-HttpResponseStatus.
 BAD_REQU

use RakamException instead of IllegalArgumentException