How to apply the contrast and brightness programmatically?

I am trying to implement the logic to change the brightness and contrast value based on the input that we pass. Please see the below code sinippet

 public void adjustBrightnessContrast(File file, int brightnessRange, int contrastRange, boolean isAutoAdjust) {
        if (file.exists()) {
            ImagePlus imp = IJ.openImage(file.getAbsolutePath());
//            imp.setDisplayRange(0,20);
//  , "Enhance Contrast", "saturated=20 normalize");
//            run("Apply LUT");
                // Code to apply auto brightness/contrast
            else {
                // Code to apply the brightness and contrast value programatically (NO UI interface)
            new FileSaver(imp).saveAsJpeg(SAVED_LOCATION + file.getName());


I tried many ways but i could not succeed. Please note that I do not want to open any UI to allow the user to manually select as i am trying to implement utility method.

Please help me.