All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.cowwoc.preconditions.OptionalPreconditionsImpl Maven / Gradle / Ivy

There is a newer version: 1.29
Show newest version
/*
 * Copyright 2014 Gili Tzabari.
 * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
 */
package org.bitbucket.cowwoc.preconditions;

import java.util.Optional;

/**
 * Default implementation of OptionalPreconditions.
 * 

* @author Gili Tzabari */ final class OptionalPreconditionsImpl extends ObjectPreconditionsImpl> implements OptionalPreconditions { /** * Creates new OptionalPreconditionsImpl. *

* @param parameter the value of the parameter * @param name the name of the parameter * @param exceptionOverride the type of exception to throw, null to disable the override * @throws NullPointerException if name or exceptionOverride are null * @throws IllegalArgumentException if name is empty */ OptionalPreconditionsImpl(Optional parameter, String name, Optional> exceptionOverride) throws NullPointerException, IllegalArgumentException { super(parameter, name, exceptionOverride); } @Override public OptionalPreconditions isPresent() throws IllegalArgumentException { if (parameter.isPresent()) return this; return throwException(IllegalArgumentException.class, String.format("%s must be present", name)); } @Override public OptionalPreconditions isEmpty() throws IllegalArgumentException { if (!parameter.isPresent()) return this; return throwException(IllegalArgumentException.class, String.format("%s must be empty", name)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy