FileDocCategorySizeDatePackage
FinalMembers.javaAPI DocExample3738Sun Dec 14 22:47:38 GMT 2003oreilly.hcj.finalstory

FinalMembers.java

/*
 *     file: FinalMembers.java
 *  package: oreilly.hcj.finalstory
 *
 * This software is granted under the terms of the Common Public License,
 * CPL, which may be found at the following URL:
 * http://www-124.ibm.com/developerworks/oss/CPLv1.0.htm
 *
 * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
 * All Rights are Reserved by the various authors.
 *
########## DO NOT EDIT ABOVE THIS LINE ########## */

package oreilly.hcj.finalstory;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**  
 * Demonstration of final class members.
 *
 * @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
 * @version $Revision: 1.3 $
 */
public class FinalMembers {
	/** Holds the creation date-time of the instance. */
	private Date creationDate =
		Calendar.getInstance(TimeZone.getTimeZone("GMT"))
		        .getTime();

	/** Holds the modification date-time of the instance. */
	public Date modificationDate = creationDate;

	/**
	 * Holds the creation date-time of the instance.  A protected version of createDate.
	 */
	private final Date creationDate2 =
		Calendar.getInstance(TimeZone.getTimeZone("GMT"))
		        .getTime();

	/** Holds the creation date-time of the instance. */
	private final Date creationDate3;

	/** 
	 * Constructor
	 *
	 * @param creationDate The creation date.
	 * @param modificationDate The last modification date.
	 *
	 * @throws IllegalArgumentException if modificationDate is less than creationDate.
	 */
	public FinalMembers(final Date creationDate, final Date modificationDate) {
		if (modificationDate.compareTo(creationDate) < 0) {
			throw new IllegalArgumentException("modificationDate");
		}
		this.creationDate3 = creationDate;
		// do a bunch of date calculations. 
		// this.creationDate3 = modificationDate;  // <= compiler error
	}

	/** 
	 * Second constructor.  Use current date for creation date.
	 *
	 * @param modificationDate The last modification date.
	 */
	public FinalMembers(final Date modificationDate) {
		this.modificationDate = modificationDate;
		// <= compiler error: