com.helger.commons.error.level.IHasErrorLevels Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ph-commons Show documentation
Show all versions of ph-commons Show documentation
Java 1.8+ Library with tons of utility classes required in all projects
The newest version!
/*
* Copyright (C) 2014-2024 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* 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 com.helger.commons.error.level;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import com.helger.commons.collection.impl.ICommonsIterable;
/**
* Interface representing an object having multiple objects with an error level
*
* @author Philip Helger
* @param
* Implementation type
*/
public interface IHasErrorLevels extends ICommonsIterable
{
/**
* Check if this group contains only success messages. If no item is present,
* false
is returned, since no success message is contained. If
* you want to check, if the list is empty or contains only success messages,
* use {@link #containsNoFailure()} instead.
*
* @return true
if at least one item is present, and if all items
* have the error level success, false
otherwise.
* @see #containsNoFailure()
*/
default boolean containsOnlySuccess ()
{
return containsOnly (IHasErrorLevel::isSuccess);
}
/**
* Check if this group contains at least one success message.
*
* @return true
if at least one success item is present,
* false
otherwise.
*/
default boolean containsAtLeastOneSuccess ()
{
return containsAny (IHasErrorLevel::isSuccess);
}
/**
* Check if this group contains no success message. This is also true, if the
* list is empty!
*
* @return true
if no success item is present, false
* otherwise.
*/
default boolean containsNoSuccess ()
{
return containsNone (IHasErrorLevel::isSuccess);
}
/**
* @return The number of contained success messages. Always ≥ 0.
*/
@Nonnegative
default int getSuccessCount ()
{
return getCount (IHasErrorLevel::isSuccess);
}
/**
* Check if this group contains only failure messages. If no item is present,
* false
is returned. All error levels except
* {@link EErrorLevel#SUCCESS} are considered to be a failure!
*
* @return true
if at least one item is present, and if all items
* have an error level indicating failure, false
* otherwise.
*/
default boolean containsOnlyFailure ()
{
return containsOnly (IHasErrorLevel::isFailure);
}
/**
* Check if this group contains at least one failure message. All error levels
* except {@link EErrorLevel#SUCCESS} are considered to be a failure!
*
* @return true
if at least one failure item is present,
* false
otherwise.
*/
default boolean containsAtLeastOneFailure ()
{
return containsAny (IHasErrorLevel::isFailure);
}
/**
* Check if this group contains no failure message. All error levels except
* {@link EErrorLevel#SUCCESS} are considered to be a failure!
*
* @return true
if no failure item is present, false
* otherwise.
*/
default boolean containsNoFailure ()
{
return containsNone (IHasErrorLevel::isFailure);
}
/**
* @return The number of contained failure messages. Always ≥ 0.
*/
@Nonnegative
default int getFailureCount ()
{
return getCount (IHasErrorLevel::isFailure);
}
/**
* Check if this group contains only error or fatal error messages. If no item
* is present, false
is returned. All error levels ≥
* {@link EErrorLevel#ERROR} are considered to be an error!
*
* @return true
if at least one item is present, and if all items
* have an error level indicating error or fatal error,
* false
otherwise.
*/
default boolean containsOnlyError ()
{
return containsOnly (IHasErrorLevel::isError);
}
/**
* Check if this group contains at least one error or fatal error message. All
* error levels ≥ {@link EErrorLevel#ERROR} are considered to be an error!
*
* @return true
if at least one error or fatal error item is
* present, false
otherwise.
*/
default boolean containsAtLeastOneError ()
{
return containsAny (IHasErrorLevel::isError);
}
/**
* Check if this group contains no error or fatal error message. All error
* levels ≥ {@link EErrorLevel#ERROR} are considered to be an error!
*
* @return true
if no error or fatal error item is present,
* false
otherwise.
*/
default boolean containsNoError ()
{
return containsNone (IHasErrorLevel::isError);
}
/**
* @return The number of contained error messages. Always ≥ 0. All error
* levels ≥ {@link EErrorLevel#ERROR} are considered to be an
* error!
*/
@Nonnegative
default int getErrorCount ()
{
return getCount (IHasErrorLevel::isError);
}
/**
* @return true
if at least 1 item of level warning or at least 1
* item of level error is contained.
*/
default boolean containsAtLeastOneWarningOrError ()
{
return containsAny (x -> x.getErrorLevel ().isGE (EErrorLevel.WARN));
}
/**
* Get the most severe error level within this object. The severity is defined
* by {@link EErrorLevel}'s severity model.
*
* @return {@link EErrorLevel#SUCCESS} if no error is contained, the most
* severe contained error level otherwise.
*/
@Nonnull
default IErrorLevel getMostSevereErrorLevel ()
{
IErrorLevel ret = EErrorLevel.LOWEST;
for (final IMPLTYPE aItem : this)
{
final IErrorLevel aCur = aItem.getErrorLevel ();
if (aCur.isGT (ret))
{
ret = aCur;
if (ret.isHighest ())
break;
}
}
return ret;
}
}