001/* 002 * Copyright (C) 2022-2023 The Prometheus jmx_exporter Authors 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 io.prometheus.jmx.common.util; 018 019public class Precondition { 020 021 private Precondition() { 022 // DO NOTHING 023 } 024 025 /** 026 * Method to check an Object is not null 027 * 028 * @param object object 029 */ 030 public static void notNull(Object object) { 031 if (object == null) { 032 throw new IllegalArgumentException(); 033 } 034 } 035 036 /** 037 * Method to check that a String is not null and not empty 038 * 039 * @param string string 040 */ 041 public static void notNullOrEmpty(String string) { 042 if (string == null || string.trim().isEmpty()) { 043 throw new IllegalArgumentException(); 044 } 045 } 046 047 /** 048 * Method to check that an integration is greater than or equal to a value 049 * 050 * @param minimumValue minimumValue 051 * @param value value 052 */ 053 public static void IsGreaterThanOrEqualTo(int minimumValue, int value) { 054 if (value < minimumValue) { 055 throw new IllegalArgumentException(); 056 } 057 } 058}