/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.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://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 * The contents of this file comply with the Jini Technology Core
 * Platform Compatibility Kit, v2.0A.
 * 
 * Tester(s): Sun Microsystems, Inc.
 * 
 * Test Platform(s):
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Solaris(TM)SPARC/x86
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Linux (Intel x86)
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Windows (Intel Platform)
 * 
 */
package com.sun.jini.outrigger;

/**
 * Object that that represents a visibility transition of some
 * entry.
 */
class EntryTransition {
    /** The <code>EntryHandle</code> of the entry that changed */
    final private EntryHandle handle;

    /** 
     * The <code>Txn</code> object for the transaction that
     * the entry became available too (if any).
     */
    final private Txn txn;

    /**
     * <code>true</code> if the transition caused the entry to become
     * available (e.g. visible or unlocked), <code>false</code>
     * otherwise.
     */
    final private boolean available;

    /**
     * <code>true</code> if the transition is a write or
     * the commit of a write, <code>false</code> otherwise.
     */
    final private boolean newEntry;

    /** 
     * Create a new <code>EntryTransition</code> object
     * with the specified content.
     * @param handle The <code>EntryHandle</code> of the 
     *               the entry who's visibility is changing.
     * @param txn    If the entry is only visible in a particular
     *               transaction, the <code>Txn</code> for that
     *               transaction, and <code>null</code> otherwise.
     * @param available <code>true</code> if the entry is transitioning
     *               from unavailable to available, <code>false</code> 
     *               otherwise.
     * @param newEntry <code>true</code> if the entry is available and
     *               the transition is because of a write or a write
     *               that is being committed, <code>false</code>
     *               otherwise.
     * @throws NullPointerException if handle is null.
     */
    EntryTransition(EntryHandle handle, Txn txn, boolean available,
		    boolean newEntry)
    {
	if (handle == null)
	    throw new NullPointerException("entry must be non-null");
	
	this.handle = handle;
	this.txn = txn;
	this.available = available;
	this.newEntry = newEntry;
    }

    /**
     * Return the <code>EntryHandle</code> for entry undergoing the
     * visibility transition.
     * @return The handle for the entry undergoing the visibility
     *         transition.  
     */
    EntryHandle getHandle() {
	return handle;
    }

    /**
     * Return the transaction associated with this visibility transition
     * represented as <code>Txn</code> object.  Return
     * <code>null</code> if there is no associated transaction.
     * @return the transaction associated with this visibility transition.
     */
    Txn getTxn() {
	return txn;
    }

    /**
     * Return <code>true</code> if this transition represents an entry
     * becoming visible, otherwise return <code>false</code>.
     * @return <code>true</code> if this transition represents an entry
     * becoming visible, otherwise return <code>false</code>.
     */
    boolean isAvailable() {
	return available;
    }

    /**
     * Return <code>true</code> if this transition represents a
     * new entry becoming visible, otherwise return <code>false</code>.
     * @return Return <code>true</code> if this transition represents a
     * new entry becoming visible, otherwise return <code>false</code>.
     */
    boolean isNewEntry() {
	return newEntry;
    }
}

