Created a new abstract parent class for Entry*Event: EntryEvent.
The big win is that getKey() now exists on each of those event types. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6278 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -33,7 +33,7 @@ import com.samskivert.util.StringUtil;
|
||||
* @param <T> the type of entry being handled by this event. This must match the type on the set
|
||||
* that generated this event.
|
||||
*/
|
||||
public class EntryAddedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
public class EntryAddedEvent<T extends DSet.Entry> extends EntryEvent<T>
|
||||
{
|
||||
/**
|
||||
* Constructs a new entry added event on the specified target object with the supplied set
|
||||
@@ -66,14 +66,32 @@ public class EntryAddedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
return _entry.getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry that has been added.
|
||||
* {@inheritDoc}
|
||||
* This implementation never returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getEntry ()
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* This implementation always returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getOldEntry ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alreadyApplied ()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://code.google.com/p/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
import com.threerings.presents.net.Transport;
|
||||
|
||||
/**
|
||||
* A common parent class for DSet entry events.
|
||||
*/
|
||||
public abstract class EntryEvent<T extends DSet.Entry> extends NamedEvent
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntryEvent (int targetOid, String name)
|
||||
{
|
||||
super(targetOid, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public EntryEvent (int targetOid, String name, Transport transport)
|
||||
{
|
||||
super(targetOid, name, transport);
|
||||
}
|
||||
|
||||
/** For unserialization. */
|
||||
public EntryEvent ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key that identifies the entry related to this event.
|
||||
* Never returns <code>null</code>.
|
||||
*/
|
||||
public abstract Comparable<?> getKey ();
|
||||
|
||||
/**
|
||||
* Return the <em>new or updated</em> entry, or <code>null</code> if the entry was removed.
|
||||
*/
|
||||
public abstract T getEntry ();
|
||||
|
||||
/**
|
||||
* Return the <em>old</em> entry, or <code>null</code> if the entry is newly added.
|
||||
*/
|
||||
public abstract T getOldEntry ();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import static com.threerings.presents.Log.log;
|
||||
* @param <T> the type of entry being handled by this event. This must match the type on the set
|
||||
* that generated this event.
|
||||
*/
|
||||
public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
public class EntryRemovedEvent<T extends DSet.Entry> extends EntryEvent<T>
|
||||
{
|
||||
/**
|
||||
* Constructs a new entry removed event on the specified target object with the supplied set
|
||||
@@ -59,17 +59,27 @@ public class EntryRemovedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that identifies the entry that has been removed.
|
||||
*/
|
||||
@Override
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry that was in the set prior to being updated.
|
||||
* {@inheritDoc}
|
||||
* This implementation always returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getEntry ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* This implementation never returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getOldEntry ()
|
||||
{
|
||||
return _oldEntry;
|
||||
|
||||
@@ -36,7 +36,7 @@ import static com.threerings.presents.Log.log;
|
||||
* @param <T> the type of entry being handled by this event. This must match the type on the set
|
||||
* that generated this event.
|
||||
*/
|
||||
public class EntryUpdatedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
public class EntryUpdatedEvent<T extends DSet.Entry> extends EntryEvent<T>
|
||||
{
|
||||
/**
|
||||
* Constructs a new entry updated event on the specified target object for the specified set
|
||||
@@ -77,17 +77,27 @@ public class EntryUpdatedEvent<T extends DSet.Entry> extends NamedEvent
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
return _entry.getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry that has been updated.
|
||||
* {@inheritDoc}
|
||||
* This implementation never returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getEntry ()
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry that was in the set prior to being updated.
|
||||
* {@inheritDoc}
|
||||
* This implementation never returns <code>null</code>.
|
||||
*/
|
||||
@Override
|
||||
public T getOldEntry ()
|
||||
{
|
||||
return _oldEntry;
|
||||
|
||||
Reference in New Issue
Block a user