![JAR search and dependency download from the Maven repository](/logo.png)
patterntesting.runtime.NullConstants Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patterntesting-rt Show documentation
Show all versions of patterntesting-rt Show documentation
PatternTesting Runtime (patterntesting-rt) is the runtime component for
the PatternTesting framework. It provides the annotations and base classes
for the PatternTesting testing framework (e.g. patterntesting-check,
patterntesting-concurrent or patterntesting-exception) but can be also
used standalone for classpath monitoring or profiling.
It uses AOP and AspectJ to perform this feat.
/**
* $Id: NullConstants.java,v 1.7 2016/12/18 20:19:41 oboehm Exp $
*
* Copyright (c) 2009 by Oliver Boehm
*
* 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 orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 13.06.2009 by oliver ([email protected])
*/
package patterntesting.runtime;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.*;
/**
* This class contains some constants (like a NULL_STRING) as constant. It can
* be statically imported.
*
* If you are using Java 8 you can use Optionals to indicate empty (or NULL)
* values.
*
*
* @author oliver
* @version $Revision: 1.7 $
* @since 13.06.2009
*/
public final class NullConstants {
private static final Logger LOG = LogManager.getLogger(NullConstants.class);
/** to avoid that this class will be instantiated */
private NullConstants() {
}
/**
* If you have a method with a list of arguments where some arguments are
* optional you can
*
* - provide the method with different signatures (good idea, but not
* always feasible)
* - admit null arguments and handle it in the methode (not a good idea
* because it can happen accidentally)
* - use this special NULL_OBJECT object to mark an argument as optional
*
*
* Unfortunately this works only for object as argument. For String as
* argument you can use NULL_STRING.
*
* @see #NULL_STRING
*/
public static final Object NULL_OBJECT = new Object();
/**
* You need a null string and don't want to use null? Use
* NULL_STRING and you can write code like
*
*
* if (name == NULL_STRING) ...
*
*/
public static final String NULL_STRING = "";
/**
* You need a null file and don't want to use null? Use
* NULL_FILE and you can write code like
*
*
* if (name == NULL_STRING) ...
*
*/
public static final File NULL_FILE = new File(NULL_STRING);
/**
* You need a null throwable and don't want to use null? Use
* NULL_THROWABLE and you can write code like
*
*
* if (name == NULL_THROWABLE) ...
*
*/
public static final Throwable NULL_THROWABLE = new Throwable();
/**
* You need a null exception and don't want to use null? Use
* NULL_EXCEPTION and you can write code like
*
*
* if (name == NULL_EXCEPTION) ...
*
*/
public static final Throwable NULL_EXCEPTION = new Exception();
/**
* You need a null date and don't want to use null? Use
* NULL_DATE and you can write code like
*
*
* if (name == NULL_DATE) ...
*
*
* The NULL_DATE is defined here as 1.1.1970 (the epoch).
*/
public static final Date NULL_DATE = new Date(0L);
/**
* You need a null URI and don't want to use null? Uses
* NULL_URI and you can write code like
*
*
* if (name == NULL_URI) ...
*
*
* The NULL_URI is defined as URI for "http://null".
*/
public static final URI NULL_URI = getNullURI();
private static URI getNullURI() {
try {
return new URI("http://null");
} catch (URISyntaxException cannothappen) {
LOG.warn("NULL_URI defined as 'null':", cannothappen);
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy