From a9416fd23545ed88c1d551245fd7471abbc9f627 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Wed, 17 Nov 2010 00:00:49 +0000 Subject: [PATCH] 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 --- .../presents/dobj/EntryAddedEvent.java | 22 +++++- .../threerings/presents/dobj/EntryEvent.java | 67 +++++++++++++++++++ .../presents/dobj/EntryRemovedEvent.java | 20 ++++-- .../presents/dobj/EntryUpdatedEvent.java | 16 ++++- 4 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/threerings/presents/dobj/EntryEvent.java diff --git a/src/main/java/com/threerings/presents/dobj/EntryAddedEvent.java b/src/main/java/com/threerings/presents/dobj/EntryAddedEvent.java index 25973dd72..50d386e27 100644 --- a/src/main/java/com/threerings/presents/dobj/EntryAddedEvent.java +++ b/src/main/java/com/threerings/presents/dobj/EntryAddedEvent.java @@ -33,7 +33,7 @@ import com.samskivert.util.StringUtil; * @param the type of entry being handled by this event. This must match the type on the set * that generated this event. */ -public class EntryAddedEvent extends NamedEvent +public class EntryAddedEvent extends EntryEvent { /** * Constructs a new entry added event on the specified target object with the supplied set @@ -66,14 +66,32 @@ public class EntryAddedEvent extends NamedEvent { } + @Override + public Comparable getKey () + { + return _entry.getKey(); + } + /** - * Returns the entry that has been added. + * {@inheritDoc} + * This implementation never returns null. */ + @Override public T getEntry () { return _entry; } + /** + * {@inheritDoc} + * This implementation always returns null. + */ + @Override + public T getOldEntry () + { + return null; + } + @Override public boolean alreadyApplied () { diff --git a/src/main/java/com/threerings/presents/dobj/EntryEvent.java b/src/main/java/com/threerings/presents/dobj/EntryEvent.java new file mode 100644 index 000000000..9cb630ba1 --- /dev/null +++ b/src/main/java/com/threerings/presents/dobj/EntryEvent.java @@ -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 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 null. + */ + public abstract Comparable getKey (); + + /** + * Return the new or updated entry, or null if the entry was removed. + */ + public abstract T getEntry (); + + /** + * Return the old entry, or null if the entry is newly added. + */ + public abstract T getOldEntry (); +} diff --git a/src/main/java/com/threerings/presents/dobj/EntryRemovedEvent.java b/src/main/java/com/threerings/presents/dobj/EntryRemovedEvent.java index e770f3c71..23eac8f9d 100644 --- a/src/main/java/com/threerings/presents/dobj/EntryRemovedEvent.java +++ b/src/main/java/com/threerings/presents/dobj/EntryRemovedEvent.java @@ -33,7 +33,7 @@ import static com.threerings.presents.Log.log; * @param the type of entry being handled by this event. This must match the type on the set * that generated this event. */ -public class EntryRemovedEvent extends NamedEvent +public class EntryRemovedEvent extends EntryEvent { /** * Constructs a new entry removed event on the specified target object with the supplied set @@ -59,17 +59,27 @@ public class EntryRemovedEvent 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 null. */ + @Override + public T getEntry () + { + return null; + } + + /** + * {@inheritDoc} + * This implementation never returns null. + */ + @Override public T getOldEntry () { return _oldEntry; diff --git a/src/main/java/com/threerings/presents/dobj/EntryUpdatedEvent.java b/src/main/java/com/threerings/presents/dobj/EntryUpdatedEvent.java index 035db3f78..5131ed570 100644 --- a/src/main/java/com/threerings/presents/dobj/EntryUpdatedEvent.java +++ b/src/main/java/com/threerings/presents/dobj/EntryUpdatedEvent.java @@ -36,7 +36,7 @@ import static com.threerings.presents.Log.log; * @param the type of entry being handled by this event. This must match the type on the set * that generated this event. */ -public class EntryUpdatedEvent extends NamedEvent +public class EntryUpdatedEvent extends EntryEvent { /** * Constructs a new entry updated event on the specified target object for the specified set @@ -77,17 +77,27 @@ public class EntryUpdatedEvent extends NamedEvent { } + @Override + public Comparable getKey () + { + return _entry.getKey(); + } + /** - * Returns the entry that has been updated. + * {@inheritDoc} + * This implementation never returns null. */ + @Override public T getEntry () { return _entry; } /** - * Returns the entry that was in the set prior to being updated. + * {@inheritDoc} + * This implementation never returns null. */ + @Override public T getOldEntry () { return _oldEntry;