001    /**
002     * $Id: NullConstants.java,v 1.2 2012/07/16 19:57:11 oboehm Exp $
003     *
004     * Copyright (c) 2009 by Oliver Boehm
005     *
006     * Licensed under the Apache License, Version 2.0 (the "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     *
018     * (c)reated 13.06.2009 by oliver (ob@aosd.de)
019     */
020    package patterntesting.runtime;
021    
022    import java.io.File;
023    import java.util.Date;
024    
025    /**
026     * This class contains some constants (like a NULL_STRING) as constant.
027     * It can be statically imported.
028     *
029     * @author <a href="boehm@javatux.de">oliver</a>
030     * @since 13.06.2009
031     * @version $Revision: 1.2 $
032     */
033    public final class NullConstants {
034    
035        /** to avoid that this class will be instantiated */
036        private NullConstants() {}
037    
038        /**
039         * If you have a method with a list of arguments where some arguments are
040         * optional you can
041         * <ul>
042         *  <li>
043         *      provide the method with different signatures
044         *      (good idea, but not always feasible)
045         *  </li>
046         *  <li>
047         *      admit null arguments and handle it in the methode
048         *      (not a good idea because it can happen accidentally)
049         *  </li>
050         *  <li>
051         *      use this special NULL_OBJECT object to mark an argument as optional
052         *  </li>
053         * </ul>
054         * Unfortunately this works only for object as argument. For String as
055         * argument you can use NULL_STRING.
056         *
057         * @see #NULL_STRING
058         */
059        public static final Object NULL_OBJECT = new Object();
060    
061        /**
062         * You need a null string and don't want to use <i>null</i>? Use
063         * <i>NULL_STRING</i> and you can write code like
064         * <pre>
065         * if (name == NULL_STRING) ...
066         * </pre>
067         */
068        public static final String NULL_STRING = "";
069    
070        /**
071         * You need a null file and don't want to use <i>null</i>? Use
072         * <i>NULL_FILE</i> and you can write code like
073         * <pre>
074         * if (name == NULL_STRING) ...
075         * </pre>
076         */
077        public static final File NULL_FILE = new File(NULL_STRING);
078    
079        /**
080         * You need a null throwable and don't want to use <i>null</i>? Use
081         * <i>NULL_THROWABLE</i> and you can write code like
082         * <pre>
083         * if (name == NULL_THROWABLE) ...
084         * </pre>
085         */
086        public static final Throwable NULL_THROWABLE = new Throwable();
087    
088        /**
089         * You need a null exception and don't want to use <i>null</i>? Use
090         * <i>NULL_EXCEPTION</i> and you can write code like
091         * <pre>
092         * if (name == NULL_EXCEPTION) ...
093         * </pre>
094         */
095        public static final Throwable NULL_EXCEPTION = new Exception();
096    
097        /**
098         * You need a null date and don't want to use <i>null</i>? Use
099         * <i>NULL_DATE</i> and you can write code like
100         * <pre>
101         * if (name == NULL_DATE) ...
102         * </pre>
103         * The NULL_DATE is defined here as 1.1.1970 (the epoch).
104         */
105        public static final Date NULL_DATE = new Date(0L);
106    
107    }