tech.sirwellington.alchemy.arguments.assertions.CollectionAssertions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alchemy-arguments Show documentation
Show all versions of alchemy-arguments Show documentation
Part of the Alchemy Collection.
Easy, Simple, and Robust argument checking logic
for your Services, Libraries, and Scripts.
/*
* Copyright 2015 SirWellington Tech.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tech.sirwellington.alchemy.arguments.assertions;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.sirwellington.alchemy.annotations.access.NonInstantiable;
import tech.sirwellington.alchemy.annotations.arguments.NonEmpty;
import tech.sirwellington.alchemy.annotations.arguments.NonNull;
import tech.sirwellington.alchemy.arguments.AlchemyAssertion;
import tech.sirwellington.alchemy.arguments.Checks;
import tech.sirwellington.alchemy.arguments.FailedAssertionException;
import static java.lang.String.format;
import static tech.sirwellington.alchemy.arguments.Checks.Internal.checkNotNull;
import static tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull;
/**
*
* @author SirWellington
*/
@NonInstantiable
public final class CollectionAssertions
{
private final static Logger LOG = LoggerFactory.getLogger(CollectionAssertions.class);
CollectionAssertions() throws IllegalAccessException
{
throw new IllegalAccessException("cannot instantiate");
}
/**
* Asserts that the collection is not null and not empty.
*
* @param
*
* @return
*/
public static AlchemyAssertion> nonEmptyCollection()
{
return (collection) ->
{
notNull().check(collection);
if (collection.isEmpty())
{
throw new FailedAssertionException("Collection is empty");
}
};
}
/**
* Asserts that the List is not null and not empty
*
* @param
*
* @return
*/
public static AlchemyAssertion> nonEmptyList()
{
return (list) ->
{
notNull().check(list);
if (list.isEmpty())
{
throw new FailedAssertionException("List is empty");
}
};
}
/**
* Asserts that the Set is not null and not empty.
* @param
*
* @return
*/
public static AlchemyAssertion> nonEmptySet()
{
return set ->
{
notNull().check(set);
if(set.isEmpty())
{
throw new FailedAssertionException("Set is empty");
}
};
}
/**
* Asserts that the Map is not null and not empty
*
* @param
* @param
*
* @return
*/
public static AlchemyAssertion
© 2015 - 2025 Weber Informatics LLC | Privacy Policy