001/*
002 * Copyright 2015 SirWellington Tech.
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 */
016package tech.sirwellington.alchemy.test;
017
018import org.slf4j.Logger;
019import org.slf4j.LoggerFactory;
020import tech.sirwellington.alchemy.annotations.access.NonInstantiable;
021
022/**
023 * Used internally to perform argument checks.
024 *
025 * @author SirWellington
026 */
027@tech.sirwellington.alchemy.annotations.access.Internal
028@NonInstantiable
029public final class Checks
030{
031
032    private final static Logger LOG = LoggerFactory.getLogger(Checks.class);
033
034    Checks() throws IllegalAccessException
035    {
036        throw new IllegalAccessException("cannot instantiate");
037    }
038
039    @tech.sirwellington.alchemy.annotations.access.Internal
040    @NonInstantiable
041    public static class Internal
042    {
043
044        Internal() throws IllegalAccessException
045        {
046            throw new IllegalAccessException("cannot instantiate");
047        }
048
049        public static void checkNotNull(Object ref) throws IllegalArgumentException
050        {
051            checkNotNull(ref, "");
052        }
053
054        public static void checkNotNull(Object ref, String message) throws IllegalArgumentException
055        {
056            if (ref == null)
057            {
058                throw new IllegalArgumentException(message);
059            }
060        }
061
062        public static void checkThat(boolean predicate) throws IllegalArgumentException
063        {
064            checkThat(predicate, "");
065        }
066
067        public static void checkThat(boolean predicate, String message) throws IllegalArgumentException
068        {
069            if (!predicate)
070            {
071                throw new IllegalArgumentException(message);
072            }
073        }
074    }
075
076}