Thread: [mud4j-commit] SF.net SVN: mud4j: [107] trunk/mud4j-core/src
Status: Pre-Alpha
Brought to you by:
mpurland
From: <mpu...@us...> - 2007-01-14 00:43:33
|
Revision: 107 http://mud4j.svn.sourceforge.net/mud4j/?rev=107&view=rev Author: mpurland Date: 2007-01-13 16:42:58 -0800 (Sat, 13 Jan 2007) Log Message: ----------- Change design of abilities to use constructor injection. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -23,13 +23,32 @@ * * @author Matthew Purland */ -public interface CharacterAbility extends Ability { +public abstract class CharacterAbility implements Ability { + + // Character interface to use for ability. + protected Character character; /** - * Run the ability for the specified player. + * Constructor to provide association between character and + * the ability. * - * @param character Character instance. - * @throws AbilityException + * @param character Character to associate to the ability. */ - public void run(Character character) throws AbilityException; + public CharacterAbility(Character character) { + this.character = character; + } + + /** + * Get the character. + * + * @return the character. + */ + public Character getCharacter() { + return this.character; + } + + /** + * {@inheritDoc} + */ + abstract public void run() throws AbilityException; } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/LocationAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -23,14 +23,31 @@ * * @author Matthew Purland */ -public interface LocationAbility extends Ability { +public abstract class LocationAbility implements Ability { + // Location for the ability. + private Location location; + /** - * Run an ability on a location. + * Constructor to create a LocationAbility to associate + * the ability with a location. * - * @param location Location to run ability on. - * @throws AbilityException + * @param location Location to associate with the specific ability. */ - public void run(Location location) throws AbilityException; + public LocationAbility(Location location) { + this.location = location; + } + + /** + * Get the location for the ability. + * @return Returns the location that is associated with the ability. + */ + public Location getLocation() { + return location; + } + /** + * {@inheritDoc} + */ + abstract public void run() throws AbilityException; } Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/CharacterAbilityTest.java 2007-01-14 00:42:58 UTC (rev 107) @@ -39,7 +39,7 @@ * Assert that we can create an ability. */ public void testCreateCharacterAbility() { - ability = new MockCharacterAbility(); + ability = new MockCharacterAbility(character); } @@ -50,10 +50,10 @@ * @throws AbilityException */ public void testRunCharacterAbility() throws AbilityException { - ability = new MockCharacterAbility(); + ability = new MockCharacterAbility(character); try { - ability.run(character); + ability.run(); fail("MockCharacterAbility did not an expected AbilityException."); } catch (AbilityException ex) { Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 00:31:26 UTC (rev 106) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 00:42:58 UTC (rev 107) @@ -27,12 +27,17 @@ * * @author Matthew Purland */ -public class MockCharacterAbility implements CharacterAbility { +public class MockCharacterAbility extends CharacterAbility { + + public MockCharacterAbility(Character character) { + super(character); + } + /* (non-Javadoc) * @see net.sf.mud4j.ability.CharacterAbility#run(net.sf.mud4j.character.Character) */ - public void run(Character character) throws AbilityException { + public void run() throws AbilityException { try { character.message(MockCharacter.TEST_MESSAGE); } @@ -41,12 +46,5 @@ } } - /* (non-Javadoc) - * @see net.sf.mud4j.ability.Ability#run() - */ - public void run() throws AbilityException { - throw new UnsupportedOperationException(); - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-01-14 18:47:11
|
Revision: 114 http://mud4j.svn.sourceforge.net/mud4j/?rev=114&view=rev Author: mpurland Date: 2007-01-14 10:47:07 -0800 (Sun, 14 Jan 2007) Log Message: ----------- Remove CharacterEffect interface. Fix javadoc on classes. Add new mock test to provide new goal of testing of effect package. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractCharacterEffect.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java Added Paths: ----------- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffectLevel.java Removed Paths: ------------- trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffect.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractCharacterEffect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractCharacterEffect.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractCharacterEffect.java 2007-01-14 18:47:07 UTC (rev 114) @@ -19,39 +19,29 @@ import net.sf.mud4j.character.Character; /** + * Abstract character effect implementation for injecting a character on to + * an effect. + * * @author Matthew Purland * */ -public abstract class AbstractCharacterEffect extends AbstractEffect implements CharacterEffect { +public abstract class AbstractCharacterEffect extends AbstractEffect { private Character character; + /** + * Constructor to inject effect with a character. + * + * @param character + */ public AbstractCharacterEffect(Character character) { - setCharacter(character); + this.character = character; } - + /** - * {@inheritDoc} + * Get character for the effect. + * @return Returns the character for the effect. */ - public void setCharacter(Character character) { - this.character = character; - } -// -// /** -// * {@inheritDoc} -// */ -// @Override -// public void apply() { -// character.getEffectBehavior().addEffect(this); -// } -// -// /** -// * {@inheritDoc} -// */ -// @Override -// public void undo() { -// character.getEffectBehavior().removeEffect(this); -// } - - - + public Character getCharacter() { + return character; + } } Deleted: trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffect.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffect.java 2007-01-14 18:47:07 UTC (rev 114) @@ -1,33 +0,0 @@ -/** - * Copyright 2006 Matthew Purland (m.p...@gm...) - * - * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.mud4j.effect; - -import net.sf.mud4j.character.Character; - -/** - * Effect that adds effects to characters. - * - * @author Matthew Purland - */ -public interface CharacterEffect extends Effect { - - /** - * Set the character on the object. - * @param character Character to set. - */ - public void setCharacter(Character character); -} Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java 2007-01-14 18:47:07 UTC (rev 114) @@ -28,12 +28,14 @@ /** * Apply effect on the target. * @param target Target object to apply effect on. + * @throws EffectException in case of an apply failure. */ public void apply() throws EffectException; /** * Undo the effect from the target. * @param target Target object to remove effect from. + * @throws EffectException in case of an undo failure. */ public void undo() throws EffectException; @@ -46,11 +48,13 @@ /** * Determine if the effect is permanent. Permanent status means * that the effect cannot be removed. + * @return Retruns whether the effect is a permanent effect and cannot expire. */ public boolean isPermanent(); /** - * Get name of the effect + * Get name of the effect. + * @return Returns the name of the effect. */ public String getName(); } Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/ability/MockCharacterAbility.java 2007-01-14 18:47:07 UTC (rev 114) @@ -34,8 +34,10 @@ super(character); } - /* (non-Javadoc) - * @see net.sf.mud4j.ability.CharacterAbility#run(net.sf.mud4j.character.Character) + /** + * Test a character ability by testing through messaging the character. + * + * {@inheritDoc} */ public void run() throws AbilityException { try { Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java 2007-01-14 18:47:07 UTC (rev 114) @@ -15,6 +15,8 @@ */ package net.mud4j.game.effect; +import java.util.Iterator; + import net.mud4j.test.MudTestCase; import net.sf.mud4j.character.Character; import net.sf.mud4j.effect.DefaultEffectBehavior; @@ -42,6 +44,9 @@ effect = new MockCharacterEffect(character); } + /** + * Test the effect name. + */ public void testCharacterEffect() { assertEquals(effect.getName(), "MockCharacterEffect"); } @@ -58,8 +63,13 @@ } + // Assert that the effect behavior contains the effect + assertTrue(character.getEffectBehavior().getEffects().contains(effect)); - assertTrue(character.getEffectBehavior().getEffects().contains(effect)); + effectBehavior.clear(); + + // Assert that the effect behavior now DOES NOT contain the effect + assertFalse(character.getEffectBehavior().getEffects().contains(effect)); } /** @@ -74,6 +84,26 @@ } + // Assert that the effect behavior DOES NOT contain the effect assertFalse(character.getEffectBehavior().getEffects().contains(effect)); } + + /** + * Test the effect of permanent/non-permanent effects. + */ + public void testCharacterEffectPermanent() { + try { + effect.apply(); + effectBehavior.addEffect(effect); + } + catch (EffectException ex) { + + } + + // Iterate through all effects and make sure all are not permanent. + for (Effect effect : effectBehavior.getEffects()) { + assertFalse(effect.isPermanent()); + } + + } } Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java 2007-01-14 18:45:05 UTC (rev 113) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java 2007-01-14 18:47:07 UTC (rev 114) @@ -25,10 +25,17 @@ */ public class MockCharacterEffect extends AbstractCharacterEffect { + /** + * Constructor to provide injection for character on to effect. + * @param character Character to set for the effect. + */ public MockCharacterEffect(Character character) { super(character); } + /** + * {@inheritDoc} + */ public String getName() { return "MockCharacterEffect"; } @@ -55,7 +62,7 @@ * {@inheritDoc} */ public boolean isPermanent() { - // TODO Auto-generated method stub + // Place this effect as non permanent. return false; } Added: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffectLevel.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffectLevel.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffectLevel.java 2007-01-14 18:47:07 UTC (rev 114) @@ -0,0 +1,68 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.mud4j.game.effect; + +import net.sf.mud4j.character.Character; +import net.sf.mud4j.effect.AbstractCharacterEffect; + +/** + * Mock character effect to test to increase level of character. + * + * @author Matthew Purland + */ +public class MockCharacterEffectLevel extends AbstractCharacterEffect { + + /** + * Constructor to provide injection for character on to effect. + * @param character Character to set for the effect. + */ + public MockCharacterEffectLevel(Character character) { + super(character); + } + + /** + * {@inheritDoc} + */ + public String getName() { + return "MockCharacterEffectLevel"; + } + + /** + * {@inheritDoc} + */ + @Override + public void apply() { + + } + + /** + * {@inheritDoc} + */ + @Override + public void undo() { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public boolean isPermanent() { + // Place this effect as non permanent. + return false; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-10-04 21:42:14
|
Revision: 148 http://mud4j.svn.sourceforge.net/mud4j/?rev=148&view=rev Author: mpurland Date: 2007-10-04 14:42:11 -0700 (Thu, 04 Oct 2007) Log Message: ----------- Add behaviors for mud4j core, effectable, and tests Add prompt shell for telnet server. Add line terminal input handler. Start fixing terminal screen buffer. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java trunk/mud4j-core/src/java/net/sf/mud4j/damage/AbstractDamageBehavior.java trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageBehavior.java trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageListener.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractEffect.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractItemEffect.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/ability/TestBehavior.java trunk/mud4j-core/src/java/net/sf/mud4j/behavior/ trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behavior.java trunk/mud4j-core/src/java/net/sf/mud4j/behavior/BehaviorManager.java trunk/mud4j-core/src/java/net/sf/mud4j/damage/PointDamageEvent.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/EffectableBehavior.java trunk/mud4j-core/src/java/net/sf/mud4j/map/ZoneMap.java trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/EffectableBehaviorTest.java trunk/mud4j-core/src/test/unit/net/sf/ trunk/mud4j-core/src/test/unit/net/sf/mud4j/ trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/ Removed Paths: ------------- trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffectDecorator.java trunk/mud4j-core/src/java/net/sf/mud4j/effect/LocationEffectDecorator.java trunk/mud4j-core/src/java/net/sf/mud4j/map/AreaMap.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/CharacterAbility.java 2007-10-04 21:42:11 UTC (rev 148) @@ -45,7 +45,7 @@ */ public Character getCharacter() { return this.character; - } + } /** * {@inheritDoc} Added: trunk/mud4j-core/src/java/net/sf/mud4j/ability/TestBehavior.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/ability/TestBehavior.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/ability/TestBehavior.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,131 @@ +package net.sf.mud4j.ability; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.sf.mud4j.behavior.BehaviorManager; +import net.sf.mud4j.effect.Effect; +import net.sf.mud4j.effect.EffectException; +import net.sf.mud4j.effect.EffectableBehavior; + +public class TestBehavior { + + + // Adds behaviorability to a person + public class PersonBehaviorDecorator extends BehaviorManager implements Person { + private Person person; + + public PersonBehaviorDecorator(Person person) { + this.person = person; + } + + public String getName() { + return person.getName(); + } + } + + public interface PersonBehavior { + Person getPerson(); + } + + public interface Person { + String getName(); + } + + public class PersonA implements Person { + private String name; + + public PersonA(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + public interface PersonFlyEffect extends Effect { + } + + public class PersonFlyWithWingsEffect implements PersonFlyEffect { + private Person person; + + public PersonFlyWithWingsEffect(Person person) { + this.person = person; + } + + private void applyFlying(Person person) { + System.out.println("Person: " + person.getName() + " is now flying with wings."); + } + + public void apply() throws EffectException { + applyFlying(person); + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + + public boolean hasExpired() { + // TODO Auto-generated method stub + return false; + } + + public boolean isPermanent() { + // TODO Auto-generated method stub + return false; + } + + public void undo() throws EffectException { + System.out.println("Person: " + person.getName() + " is not flying with wings."); + } + } + + public class DefaultEffectableBehavior implements EffectableBehavior { + + Map<Class<? extends Effect>, Effect> effectMap = new HashMap<Class<? extends Effect>, Effect>(); + + public void addEffect(Class<? extends Effect> effectClass, Effect effect) { + effectMap.put(effectClass, effect); + } + + public boolean hasEffect(Class<? extends Effect> effectClass) { + return effectMap.containsKey(effectClass); + } + + public void removeEffect(Class<? extends Effect> effectClass) { + effectMap.remove(effectClass); + } + + public <E extends Effect> E getEffect(Class<E> effectClass) { + return (E) effectMap.get(effectClass); + } + } + + public void run() { + Person personA = new PersonA("PersonA"); + PersonBehaviorDecorator personAWithBehaviorable = new PersonBehaviorDecorator(personA); + personAWithBehaviorable.addBehavior(EffectableBehavior.class, new DefaultEffectableBehavior()); + EffectableBehavior effectableBehavior = personAWithBehaviorable.getBehavior(EffectableBehavior.class); + + PersonFlyWithWingsEffect personCanFlyEffect = new PersonFlyWithWingsEffect(personA); + effectableBehavior.addEffect(PersonFlyEffect.class, personCanFlyEffect); + + personCanFlyEffect.apply(); + if (effectableBehavior.hasEffect(PersonFlyEffect.class)) { + System.out.println("Has fly effect."); + //PersonFlyEffect effect = effectableBehavior.getEffect(PersonFlyEffect.class); + effectableBehavior.removeEffect(PersonFlyEffect.class); + } + + System.out.println("A"); + } + + public static void main(String[] args) { + TestBehavior testBehavior = new TestBehavior(); + testBehavior.run(); + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/ability/TestBehavior.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Added: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behavior.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behavior.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behavior.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,5 @@ +package net.sf.mud4j.behavior; + +// Marker interface +public interface Behavior { +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behavior.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Added: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/BehaviorManager.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/behavior/BehaviorManager.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/behavior/BehaviorManager.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,24 @@ +package net.sf.mud4j.behavior; + +import java.util.HashMap; +import java.util.Map; + +public class BehaviorManager implements Behaviorable { + Map<Class<? extends Behavior>, Behavior> behaviorMap = new HashMap<Class<? extends Behavior>, Behavior>(); + + public void addBehavior(Class<? extends Behavior> behaviorClass, Behavior behavior) { + behaviorMap.put(behaviorClass, behavior); + } + + public boolean hasBehavior(Class<? extends Behavior> behaviorClass) { + return behaviorMap.containsKey(behaviorClass); + } + + public void removeBehavior(Class<? extends Behavior> behaviorClass) { + behaviorMap.remove(behaviorClass); + } + + public <E extends Behavior> E getBehavior(Class<E> behaviorClass) { + return (E)behaviorMap.get(behaviorClass); + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/BehaviorManager.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Modified: trunk/mud4j-core/src/java/net/sf/mud4j/damage/AbstractDamageBehavior.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/damage/AbstractDamageBehavior.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/damage/AbstractDamageBehavior.java 2007-10-04 21:42:11 UTC (rev 148) @@ -24,8 +24,8 @@ * * @author Matthew Purland */ -public abstract class AbstractDamageBehavior implements DamageBehavior { - private List<DamageListener> damageListeners; +public abstract class AbstractDamageBehavior<D extends DamageListener> implements DamageBehavior<D> { + private List<D> damageListeners; private boolean isDestroyed; /** @@ -40,7 +40,7 @@ isDestroyed = true; // Iterate through list of damage listeners - for (DamageListener listener : damageListeners) { + for (D listener : damageListeners) { DamageEvent event = new DamageEvent(this); event.setDestroyed(isDestroyed); listener.damageDestroyed(event); @@ -57,14 +57,14 @@ /** * {@inheritDoc} */ - public void removeDamageListener(DamageListener listener) { + public void removeDamageListener(D listener) { damageListeners.remove(listener); } /** * {@inheritDoc} */ - public void addDamageListener(DamageListener listener) { + public void addDamageListener(D listener) { damageListeners.add(listener); } } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageBehavior.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageBehavior.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageBehavior.java 2007-10-04 21:42:11 UTC (rev 148) @@ -23,7 +23,7 @@ * @author Matthew Purland * @see PointDamageBehavior */ -public interface DamageBehavior { +public interface DamageBehavior<D extends DamageListener> { /** * Inflict damage on the object. */ @@ -42,10 +42,10 @@ /** * Add a damage listener to this damage behavior. */ - public void addDamageListener(DamageListener listener); + public void addDamageListener(D listener); /** * Remove a damage listener from this damage behavior. */ - public void removeDamageListener(DamageListener listener); + public void removeDamageListener(D listener); } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageListener.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageListener.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/damage/DamageListener.java 2007-10-04 21:42:11 UTC (rev 148) @@ -21,17 +21,17 @@ /** * The listener interface for receiving damage events. */ -public interface DamageListener extends EventListener { +public interface DamageListener<E extends DamageEvent> extends EventListener { /** * Event called when damage is inflicted. */ - public void damageInflicted(DamageEvent event); + public void damageInflicted(E event); /** * Event called when enough damage is done that destroys the object. */ - public void damageDestroyed(DamageEvent event); + public void damageDestroyed(E event); } Added: trunk/mud4j-core/src/java/net/sf/mud4j/damage/PointDamageEvent.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/damage/PointDamageEvent.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/damage/PointDamageEvent.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,5 @@ +package net.sf.mud4j.damage; + +public class PointDamageEvent { + +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/damage/PointDamageEvent.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractEffect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractEffect.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractEffect.java 2007-10-04 21:42:11 UTC (rev 148) @@ -58,4 +58,9 @@ * {@inheritDoc} */ abstract public void apply() throws EffectException; + + /** + * {@inheritDoc} + */ + abstract public boolean isPermanent(); } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractItemEffect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractItemEffect.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/AbstractItemEffect.java 2007-10-04 21:42:11 UTC (rev 148) @@ -19,7 +19,7 @@ import net.sf.mud4j.world.item.Item; /** - * Abstract item effect imlementation to implement all + * Abstract item effect implementation to implement all * necessary functionality for an extending class to use * and implement business item effect data. Extending * from this class will provide the class with core item @@ -57,14 +57,4 @@ public void undo() throws EffectException { item.getEffectBehavior().removeEffect(this); } - - /** - * {@inheritDoc} - */ - public boolean isPermanent() { - // TODO Auto-generated method stub - return false; - } - - } Deleted: trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffectDecorator.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffectDecorator.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/CharacterEffectDecorator.java 2007-10-04 21:42:11 UTC (rev 148) @@ -1,103 +0,0 @@ -/** - * Copyright 2006 Matthew Purland (m.p...@gm...) - * - * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.sf.mud4j.effect; - -import java.io.IOException; -import java.util.List; - -import net.sf.mud4j.ability.CharacterAbility; -import net.sf.mud4j.character.Character; -import net.sf.mud4j.damage.DamageBehavior; -import net.sf.mud4j.world.item.Item; - -/** - * Provide effects as a decorator to a character. - * - * @author Matthew Purland - */ -public abstract class CharacterEffectDecorator implements Character, Effectable { - - // Character to decorate - private Character character; - - public CharacterEffectDecorator(Character character) { - this.character = character; - } - - /** - * {@inheritDoc} - */ - public List<CharacterAbility> getAbilities() { - return character.getAbilities(); - } - - /** - * {@inheritDoc} - */ - public List<Item> getItems() { - return character.getItems(); - } - - /** - * {@inheritDoc} - */ - public int getLevel() { - return character.getLevel(); - } - - /** - * {@inheritDoc} - */ - public String getName() { - return character.getName(); - } - - /** - * {@inheritDoc} - */ - public boolean hasAbility(CharacterAbility ability) { - return character.hasAbility(ability); - } - - /** - * {@inheritDoc} - */ - public boolean hasItem(Item item) { - return character.hasItem(item); - } - - /** - * {@inheritDoc} - */ - public DamageBehavior getDamageBehavior() { - return character.getDamageBehavior(); - } - - /** - * {@inheritDoc} - */ - public void setDamageBehavior(DamageBehavior damageBehavior) { - character.setDamageBehavior(damageBehavior); - } - - /** - * {@inheritDoc} - */ - public void message(String message) throws IOException { - character.message(message); - } - -} Modified: trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/Effect.java 2007-10-04 21:42:11 UTC (rev 148) @@ -29,21 +29,21 @@ * * @throws EffectException in case of an apply failure. */ - public void apply() throws EffectException; + void apply() throws EffectException; /** * Undo the effect from the target. * * @throws EffectException in case of an undo failure. */ - public void undo() throws EffectException; + void undo() throws EffectException; /** * Determine if the effect has expired duration. * * @return Returns whether the effect has expired yet. */ - public boolean hasExpired(); + boolean hasExpired(); /** * Determine if the effect is permanent. Permanent status means that the @@ -52,12 +52,12 @@ * @return Retruns whether the effect is a permanent effect and cannot * expire. */ - public boolean isPermanent(); + boolean isPermanent(); /** * Get name of the effect. * * @return Returns the name of the effect. */ - public String getName(); + String getName(); } Added: trunk/mud4j-core/src/java/net/sf/mud4j/effect/EffectableBehavior.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/EffectableBehavior.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/EffectableBehavior.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,10 @@ +package net.sf.mud4j.effect; + +import net.sf.mud4j.behavior.Behavior; + +public interface EffectableBehavior extends Behavior { + boolean hasEffect(Class<? extends Effect> effectClass); + void addEffect(Class<? extends Effect> effectClass, Effect effect); + void removeEffect(Class<? extends Effect> effectClass); + <E extends Effect> E getEffect(Class<E> effectClass); +} \ No newline at end of file Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/effect/EffectableBehavior.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Deleted: trunk/mud4j-core/src/java/net/sf/mud4j/effect/LocationEffectDecorator.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/effect/LocationEffectDecorator.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/effect/LocationEffectDecorator.java 2007-10-04 21:42:11 UTC (rev 148) @@ -1,48 +0,0 @@ -/** - * Copyright 2006 Matthew Purland (m.p...@gm...) - * - * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.sf.mud4j.effect; - -import net.sf.mud4j.world.Location; -import net.sf.mud4j.world.Placeable; - -/** - * Provide effect decorator/wrapping around a {@link Location}. Will delegate - * {@link Location} interface to wrapped object. - * - * @author Matthew Purland - */ -public abstract class LocationEffectDecorator implements Effectable, Location { - - // Location that is being decorated - private Location location; - - /** - * Constructor to create an effect decorating a given location. - * - * @param location Location to decorate. - */ - public LocationEffectDecorator(Location location) { - this.location = location; - } - - /** - * {@inheritDoc} - */ - public void move(Placeable placeable) { - location.move(placeable); - } - -} Deleted: trunk/mud4j-core/src/java/net/sf/mud4j/map/AreaMap.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/map/AreaMap.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/map/AreaMap.java 2007-10-04 21:42:11 UTC (rev 148) @@ -1,27 +0,0 @@ -/** - * Copyright 2006 Matthew Purland (m.p...@gm...) - * - * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.mud4j.map; - -/** - * Game map of - * - * @author Matthew Purland - * - */ -public interface AreaMap { - -} Copied: trunk/mud4j-core/src/java/net/sf/mud4j/map/ZoneMap.java (from rev 146, trunk/mud4j-core/src/java/net/sf/mud4j/map/AreaMap.java) =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/map/ZoneMap.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/map/ZoneMap.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,27 @@ +/** + * Copyright 2006 Matthew Purland (m.p...@gm...) + * + * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.sf.mud4j.map; + +/** + * Map of a zone containing rooms. + * + * @author Matthew Purland + * + */ +public interface ZoneMap { + +} Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-10-04 21:42:11 UTC (rev 148) @@ -23,8 +23,25 @@ * @author Matthew Purland */ public class Direction { + + public enum DirectionName { + NORTH("north"), + EAST("east"), + WEST("west"), + SOUTH("south"); + + private String directionName; + + DirectionName(String directionName) { + this.directionName = directionName; + } + + public String getDirectionName() { + return directionName; + } + } - private String directionName; + private DirectionName directionName; /** * Direction is from source to target location. Example. If direction is @@ -40,7 +57,7 @@ * @param sourceLocation Source of the location to the target * @param targetLocation Target of the location from the source */ - public Direction(String directionName, TileLocation sourceLocation, + public Direction(DirectionName directionName, TileLocation sourceLocation, TileLocation targetLocation) { this.directionName = directionName; this.sourceLocation = sourceLocation; @@ -50,7 +67,7 @@ /** * Get name of direction. */ - public String getDirectionName() { + public DirectionName getDirectionName() { return directionName; } Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/CharacterEffectTest.java 2007-10-04 21:42:11 UTC (rev 148) @@ -54,14 +54,9 @@ /** * Test the ability to apply an effect on a character. */ - public void testCharacterEffectApply() { - try { - effect.apply(); - effectBehavior.addEffect(effect); - } - catch (EffectException ex) { - - } + public void testCharacterEffectApply() throws EffectException { + effect.apply(); + effectBehavior.addEffect(effect); // Assert that the effect behavior contains the effect assertTrue(character.getEffectBehavior().getEffects().contains(effect)); @@ -75,15 +70,16 @@ /** * Test the ability to undo an effect on a character. */ - public void testCharacterEffectUndo() { - try { - effect.undo(); - effectBehavior.removeEffect(effect); - } - catch (EffectException ex) { - - } + public void testCharacterEffectUndo() throws EffectException { + effect.apply(); + effectBehavior.addEffect(effect); + + // Assert that the effect behavior contains the effect + assertTrue(character.getEffectBehavior().getEffects().contains(effect)); + effect.undo(); + effectBehavior.removeEffect(effect); + // Assert that the effect behavior DOES NOT contain the effect assertFalse(character.getEffectBehavior().getEffects().contains(effect)); } @@ -91,19 +87,13 @@ /** * Test the effect of permanent/non-permanent effects. */ - public void testCharacterEffectPermanent() { - try { - effect.apply(); - effectBehavior.addEffect(effect); - } - catch (EffectException ex) { - - } + public void testCharacterEffectPermanent() throws EffectException { + effect.apply(); + effectBehavior.addEffect(effect); // Iterate through all effects and make sure all are not permanent. for (Effect effect : effectBehavior.getEffects()) { assertFalse(effect.isPermanent()); - } - + } } } Added: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/EffectableBehaviorTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/EffectableBehaviorTest.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/EffectableBehaviorTest.java 2007-10-04 21:42:11 UTC (rev 148) @@ -0,0 +1,6 @@ +package net.mud4j.game.effect; + + +public class EffectableBehaviorTest { + +} Property changes on: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/EffectableBehaviorTest.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Modified: trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java 2007-10-04 21:41:58 UTC (rev 147) +++ trunk/mud4j-core/src/test/unit/net/mud4j/game/effect/MockCharacterEffect.java 2007-10-04 21:42:11 UTC (rev 148) @@ -24,7 +24,12 @@ * @author Matthew Purland */ public class MockCharacterEffect extends AbstractCharacterEffect { - + + // Effect as non permanent by default. + private boolean isPermanent = false; + private boolean isApplied = false; + + /** * Constructor to provide injection for character on to effect. * @param character Character to set for the effect. @@ -45,8 +50,7 @@ */ @Override public void apply() { - // TODO Auto-generated method stub - + isApplied = true; } /** @@ -54,16 +58,21 @@ */ @Override public void undo() { - // TODO Auto-generated method stub - + isApplied = false; } /** * {@inheritDoc} */ public boolean isPermanent() { - // Place this effect as non permanent. - return false; + return isPermanent; } + + /** + * Set permanent to true. + */ + public void setPermanent() { + isPermanent = true; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-10-04 21:42:41
|
Revision: 150 http://mud4j.svn.sourceforge.net/mud4j/?rev=150&view=rev Author: mpurland Date: 2007-10-04 14:42:39 -0700 (Thu, 04 Oct 2007) Log Message: ----------- ADd behaviorable and behavior test. Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behaviorable.java trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/BehaviorTest.java Added: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behaviorable.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behaviorable.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behaviorable.java 2007-10-04 21:42:39 UTC (rev 150) @@ -0,0 +1,8 @@ +package net.sf.mud4j.behavior; + +public interface Behaviorable { + boolean hasBehavior(Class<? extends Behavior> behaviorClass); + void addBehavior(Class<? extends Behavior> behaviorClass, Behavior behavior); + void removeBehavior(Class<? extends Behavior> behaviorClass); + <E extends Behavior> E getBehavior(Class<E> behaviorClass); +} \ No newline at end of file Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/behavior/Behaviorable.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native Added: trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/BehaviorTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/BehaviorTest.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/BehaviorTest.java 2007-10-04 21:42:39 UTC (rev 150) @@ -0,0 +1,23 @@ +package net.sf.mud4j.behavior; + +public class BehaviorTest { + public interface PersonBehavior { + Person getPerson(); + } + + public interface Person { + String getName(); + } + + public class PersonA implements Person { + private String name; + + public PersonA(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} Property changes on: trunk/mud4j-core/src/test/unit/net/sf/mud4j/behavior/BehaviorTest.java ___________________________________________________________________ Name: svn:keywords + "Author Date Id Revision" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpu...@us...> - 2007-11-01 00:01:02
|
Revision: 158 http://mud4j.svn.sourceforge.net/mud4j/?rev=158&view=rev Author: mpurland Date: 2007-10-31 17:00:59 -0700 (Wed, 31 Oct 2007) Log Message: ----------- Add scheduling service. Add SpringHelper. Rework tile/movement and link system for tiles. Add DaoTest. Modified Paths: -------------- trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/QuartzSchedulingService.java trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/SchedulingService.java trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java trunk/mud4j-core/src/java/net/sf/mud4j/world/Room.java trunk/mud4j-core/src/java/net/sf/mud4j/world/TileLocation.java trunk/mud4j-core/src/resources/spring-config.xml trunk/mud4j-core/src/test/unit/net/sf/mud4j/dao/DaoTest.java trunk/mud4j-core/src/test/unit/net/sf/mud4j/test/Mud4jSpringTestBase.java Added Paths: ----------- trunk/mud4j-core/src/java/net/sf/mud4j/skill/ trunk/mud4j-core/src/java/net/sf/mud4j/startup/ trunk/mud4j-core/src/java/net/sf/mud4j/util/SpringHelper.java trunk/mud4j-core/src/java/net/sf/mud4j/world/MoveableException.java trunk/mud4j-core/src/java/net/sf/mud4j/world/link/ trunk/mud4j-core/src/resources/hsqldb/ trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/ trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/DirectionTest.java trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/RoomTest.java trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/TileLocationTest.java Modified: trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/QuartzSchedulingService.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/QuartzSchedulingService.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/QuartzSchedulingService.java 2007-11-01 00:00:59 UTC (rev 158) @@ -1,6 +1,7 @@ package net.sf.mud4j.scheduling; import org.quartz.Scheduler; +import org.quartz.SchedulerException; public class QuartzSchedulingService implements SchedulingService { private Scheduler scheduler; @@ -9,4 +10,17 @@ Scheduler scheduler) { this.scheduler = scheduler; } + + public String[] getGroupNames() throws SchedulerException { + return scheduler.getJobGroupNames(); + } + + public String[] getJobNames(String groupName) throws SchedulerException { + return scheduler.getJobNames(groupName); + //scheduler.getJobDetail(jobName, jobGroup) + } + + public void addJob(String jobName, String groupName) { + //scheduler.addJob(jobDetail, replace) + } } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/SchedulingService.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/SchedulingService.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/java/net/sf/mud4j/scheduling/SchedulingService.java 2007-11-01 00:00:59 UTC (rev 158) @@ -1,5 +1,7 @@ package net.sf.mud4j.scheduling; public interface SchedulingService { - + public static final String DEFAULT_JOB_GROUP = "mud4j"; + + void addJob(String jobName, String groupName); } \ No newline at end of file Added: trunk/mud4j-core/src/java/net/sf/mud4j/util/SpringHelper.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/util/SpringHelper.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/util/SpringHelper.java 2007-11-01 00:00:59 UTC (rev 158) @@ -0,0 +1,56 @@ +package net.sf.mud4j.util; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +import org.apache.commons.dbcp.BasicDataSource; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringHelper { + + public static ClassPathXmlApplicationContext getClassPathXmlApplicationContext(boolean saveData) { + ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( + new String[] { "spring-config.xml" }); + + appContext.registerShutdownHook(); + + if (saveData) { + // Add an application listener for when it is closed + appContext.addApplicationListener(new ApplicationListener() { + @Override + public void onApplicationEvent(ApplicationEvent event) { + if (event instanceof ContextClosedEvent) { + ContextClosedEvent contextClosedEvent = (ContextClosedEvent) event; + ApplicationContext appContext = contextClosedEvent.getApplicationContext(); + + // Tell HSQLDB to shutdown and save data + BasicDataSource basicDataSource = (BasicDataSource) appContext.getBean("hsqlDataSource"); + Connection connection; + try { + connection = basicDataSource.getConnection(); + + String sql = "SHUTDOWN"; + Statement stmt = connection.createStatement(); + stmt.executeUpdate(sql); + stmt.close(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + }); + + // Refresh and add the application listener + appContext.refresh(); + } + + return appContext; + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/util/SpringHelper.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/Direction.java 2007-11-01 00:00:59 UTC (rev 158) @@ -20,89 +20,96 @@ * Direction to define different directions for dynamic direction management to * add west, east, north, south, etc... * + * Provides the link between a pair of {@link Location}. + * * @author Matthew Purland */ -public class Direction { +public enum Direction { - public enum DirectionName { +// public enum DirectionName { NORTH("north"), EAST("east"), WEST("west"), - SOUTH("south"); - + SOUTH("south"), + NORTHEAST("northeast"), + NORTHWEST("northwest"), + SOUTHWEST("southwest"), + SOUTHEAST("southeast"); +// private String directionName; - DirectionName(String directionName) { + Direction(String directionName) { this.directionName = directionName; } public String getDirectionName() { return directionName; } - } - - private DirectionName directionName; - - /** - * Direction is from source to target location. Example. If direction is - * east then Source (east to) --> Target - */ - private TileLocation sourceLocation; - private TileLocation targetLocation; - - /** - * Creates a direction with a name such as "north" or "south". - * - * @param directionName Name of the direction. - * @param sourceLocation Source of the location to the target - * @param targetLocation Target of the location from the source - */ - public Direction(DirectionName directionName, TileLocation sourceLocation, - TileLocation targetLocation) { - this.directionName = directionName; - this.sourceLocation = sourceLocation; - this.targetLocation = targetLocation; - } - - /** - * Get name of direction. - */ - public DirectionName getDirectionName() { - return directionName; - } - - /** - * Get the source location. - * - * @return the source location. - */ - public TileLocation getSourceLocation() { - return sourceLocation; - } - - /** - * Get the target location. - * - * @return the target location. - */ - public TileLocation getTargetLocation() { - return targetLocation; - } - - /** - * Move the given placeable to the target location of the direction. - * - * @param placeable Placeable to place within the target location. - * @throws IllegalArgumentException when the given placeable is not in the - * source location. - */ - public void move(Placeable placeable) throws IllegalArgumentException { - if (!placeable.getCurrentLocation().equals(getSourceLocation())) { - throw new IllegalArgumentException("Could not place placeable (" - + placeable - + ") because it is not currently in the source location."); - } - - placeable.place(targetLocation); - } +// } +// +// private DirectionName directionName; +// +// /** +// * Direction is from source to target location. Example. If direction is +// * east then Source (east to) --> Target +// */ +// private TileLocation sourceLocation; +// private TileLocation targetLocation; +// +// /** +// * Creates a direction with a name such as "north" or "south". +// * +// * @param sourceLocation Source of the location to the target +// * @param targetLocation Target of the location from the source +// */ +// public Direction(DirectionName directionName, TileLocation sourceLocation, +// TileLocation targetLocation) { +// this.directionName = directionName; +// this.sourceLocation = sourceLocation; +// this.targetLocation = targetLocation; +// } +// +// /** +// * Get name of direction. +// */ +// public DirectionName getDirectionName() { +// return directionName; +// } +// +// /** +// * Get the source location. +// * +// * @return the source location. +// */ +// public TileLocation getSourceLocation() { +// return sourceLocation; +// } +// +// /** +// * Get the target location. +// * +// * @return the target location. +// */ +// public TileLocation getTargetLocation() { +// return targetLocation; +// } +// +// /** +// * Move the given placeable to the target location of the direction. +// * +// * @param placeable Placeable to place within the target location. +// * @throws MoveableException when the given placeable is not in the +// * source location. +// */ +// public void move(Placeable placeable) throws MoveableException { +// Location placeableCurrentLocation = placeable.getCurrentLocation(); +// +// if (placeableCurrentLocation == null || !placeableCurrentLocation.equals(getSourceLocation())) { +// throw new MoveableException("Could not place placeable (" +// + placeable +// + ") because it is not currently in the source location."); +// } +// +// placeable.place(targetLocation); +// } } Added: trunk/mud4j-core/src/java/net/sf/mud4j/world/MoveableException.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/MoveableException.java (rev 0) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/MoveableException.java 2007-11-01 00:00:59 UTC (rev 158) @@ -0,0 +1,7 @@ +package net.sf.mud4j.world; + +public class MoveableException extends Exception { + public MoveableException(String mesg) { + super(mesg); + } +} Property changes on: trunk/mud4j-core/src/java/net/sf/mud4j/world/MoveableException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/Room.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/Room.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/Room.java 2007-11-01 00:00:59 UTC (rev 158) @@ -20,6 +20,7 @@ import java.util.List; import net.sf.mud4j.effect.EffectBehavior; +import net.sf.mud4j.world.link.TileLocationLink; /** * Defines rooms interface as a location that events happen within. @@ -81,27 +82,6 @@ /** * {@inheritDoc} */ - public void addDirection(Direction direction) { - directionList.add(direction); - } - - /** - * {@inheritDoc} - */ - public void removeDirection(Direction direction) { - directionList.remove(direction); - } - - /** - * {@inheritDoc} - */ - public List<Direction> getDirections() { - return directionList; - } - - /** - * {@inheritDoc} - */ public void move(Placeable placeable) { placeable.place(this); } Modified: trunk/mud4j-core/src/java/net/sf/mud4j/world/TileLocation.java =================================================================== --- trunk/mud4j-core/src/java/net/sf/mud4j/world/TileLocation.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/java/net/sf/mud4j/world/TileLocation.java 2007-11-01 00:00:59 UTC (rev 158) @@ -17,6 +17,8 @@ import java.util.List; +import net.sf.mud4j.world.link.TileLocationLink; + /** * Location that represents a single tile that contains * directions that link to other locations. @@ -24,21 +26,21 @@ * @author Matthew Purland */ public interface TileLocation extends Location { - /** - * Add a direction to the location. - * @param direction Direction to add to the location. - */ - public void addDirection(Direction direction); - - /** - * Remove a direction from the location. - * @param direction to remove from the location. - */ - public void removeDirection(Direction direction); - - /** - * Get list of directions for the location. - * @return Returns the list implementation for the location. - */ - public List<Direction> getDirections(); +// /** +// * Add a link to the location. +// * @param link Link to add to the location. +// */ +// public void addLocationLink(TileLocationLink link); +// +// /** +// * Remove a link from the location. +// * @param link Link to remove from the location. +// */ +// public void removeLocationLink(TileLocationLink link); +// +// /** +// * Get list of links involving this location. +// * @return Returns the list implementation for the location. +// */ +// public List<TileLocationLink> getLinks(); } Modified: trunk/mud4j-core/src/resources/spring-config.xml =================================================================== --- trunk/mud4j-core/src/resources/spring-config.xml 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/resources/spring-config.xml 2007-11-01 00:00:59 UTC (rev 158) @@ -15,7 +15,7 @@ <value>org.hsqldb.jdbcDriver</value> </property> <property name="url"> - <value>jdbc:hsqldb:file:src/resources/hsqldb/data</value> + <value>jdbc:hsqldb:file:src/resources/hsqldb/mud4j;hsqldb.default_table_type=cached</value> </property> <property name="username"> <value>sa</value> @@ -25,12 +25,27 @@ </property> </bean> + <!-- + <bean id="hsqlDatabase" class="org.springmodules.db.hsqldb.ServerBean" lazy-init="false"> + <property name="dataSource"><ref local="hsqlDataSource"/></property> + <property name="serverProperties"> + <props> + <prop key="server.port">9101</prop> + <prop key="server.database.0">src/resources/hsqldb</prop> + <prop key="server.dbname.0">mud4j</prop> + </props> + </property> + </bean> + --> + + <!-- --> + <!-- Database Property --> <bean id="hsqlHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> - <prop key="hibernate.hbm2ddl.auto">create-drop</prop> + <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop> @@ -116,7 +131,8 @@ <map> <entry key="timeout" value="5"/> </map> - </property> + </property> + <property name="group" value="mud4j" /> </bean> <!-- Trigger for ticks --> Modified: trunk/mud4j-core/src/test/unit/net/sf/mud4j/dao/DaoTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/dao/DaoTest.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/dao/DaoTest.java 2007-11-01 00:00:59 UTC (rev 158) @@ -1,28 +1,62 @@ package net.sf.mud4j.dao; +import org.springframework.dao.DataAccessException; + import net.sf.mud4j.account.Account; import net.sf.mud4j.test.Mud4jSpringTestBase; public class DaoTest extends Mud4jSpringTestBase { - - public void testAccountDao() { - AccountDao accountDao = (AccountDao) getApplicationContext().getBean("accountDao"); + + public void testAccountDao() { + AccountDao accountDao = (AccountDao) getApplicationContext().getBean( + "accountDao"); assertNotNull("AccountDao should not be null", accountDao); } - + public void testAccountDaoFind() { - AccountDao accountDao = (AccountDao) getApplicationContext().getBean("accountDao"); - + AccountDao accountDao = (AccountDao) getApplicationContext().getBean( + "accountDao"); + Account account = new Account(); account.setUsername("someusername"); account.setPassword("somepassword"); - + Long accountId = accountDao.save(account); - + Account foundAccount = accountDao.findById(accountId); - assertEquals("Account was not found correctly.", accountId, foundAccount.getAccountId()); - + assertEquals("Account was not found correctly.", accountId, + foundAccount.getAccountId()); + Account foundAccountTwo = accountDao.findByUsername("someusername"); - assertEquals("Account was not found correctly.", accountId, foundAccountTwo.getAccountId()); + assertEquals("Account was not found correctly.", accountId, + foundAccountTwo.getAccountId()); } + + /** + * Test when two rows are inserted that findByUsername returns with + * exception. + * + * @todo Username should be unique + */ + public void testAccountDaoFindDataAccessException() { + AccountDao accountDao = (AccountDao) getApplicationContext().getBean( + "accountDao"); + + Account account = new Account(); + account.setUsername("someusername"); + account.setPassword("somepassword"); + + Long accountId = accountDao.save(account); + Long accountId2 = accountDao.save(account); + + boolean exceptionOccurred = false; + try { + Account foundAccount = accountDao.findByUsername("someusername"); + } + catch (DataAccessException ex) { + exceptionOccurred = true; + } + + assertTrue(exceptionOccurred); + } } Modified: trunk/mud4j-core/src/test/unit/net/sf/mud4j/test/Mud4jSpringTestBase.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/test/Mud4jSpringTestBase.java 2007-10-14 21:55:55 UTC (rev 157) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/test/Mud4jSpringTestBase.java 2007-11-01 00:00:59 UTC (rev 158) @@ -1,7 +1,13 @@ package net.sf.mud4j.test; + +import java.lang.reflect.Field; +import java.util.Properties; + import junit.framework.TestCase; +import net.sf.mud4j.util.SpringHelper; +import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -9,10 +15,38 @@ private ClassPathXmlApplicationContext appContext; public void setUp() { - appContext = new ClassPathXmlApplicationContext( - new String[] { "spring-config.xml" }); + // Save data and schema + boolean saveData = false; + + appContext = SpringHelper.getClassPathXmlApplicationContext(saveData); + + try { + hackHibernateProperties(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + public void hackHibernateProperties() throws Exception { + //PropertiesFactoryBean hsqlHibernateProperties = (PropertiesFactoryBean) appContext.getBean("hsqlHibernateProperties"); + Properties hsqlHibernateProperties = (Properties) appContext.getBean("hsqlHibernateProperties"); +// // Hack to get properties to remove hbm2ddl from props +// Field f = PropertiesFactoryBean.class.getDeclaredField("localProperties"); +// f.setAccessible(true); +// Properties properties = (Properties) f.get(hsqlHibernateProperties); + //hsqlHibernateProperties.remove("hibernate.hbm2ddl.auto"); + hsqlHibernateProperties.setProperty("hibernate.hbm2ddl.auto", "create-update"); + appContext.refresh(); +// hsqlHibernateProperties.setProperties(properties); +// f.setAccessible(false); + } + + public void tearDown() { + // Tearing down the unit test so close the app context + appContext.close(); + } + public ApplicationContext getApplicationContext() { return appContext; } Added: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/DirectionTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/DirectionTest.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/DirectionTest.java 2007-11-01 00:00:59 UTC (rev 158) @@ -0,0 +1,44 @@ +package net.sf.mud4j.world; + +import junit.framework.TestCase; + +public class DirectionTest extends TestCase { + +// /** +// * Tests when an exception occurs when the placeable is not in the source +// * location. +// */ +// public void testDirectionMoveFailure() { +// Room room1 = new Room(); +// Room room2 = new Room(); +// +// Placeable placeable = new Placeable() { +// private Location currentLocation; +// +// @Override +// public Location getCurrentLocation() { +// return currentLocation; +// } +// +// @Override +// public void place(Location to) { +// this.currentLocation = to; +// } +// +// }; +// +// assertNull("Placeable should be null.", placeable.getCurrentLocation()); +// +// // Direction going north from room1 to room2 +// Direction direction = new Direction(DirectionName.NORTH, room1, room2); +// +// boolean directionMoveFailure = false; +// try { +// direction.move(placeable); +// } catch (MoveableException ex) { +// directionMoveFailure = true; +// } +// +// assertTrue("Failure must occur when placeable is not in source location.", directionMoveFailure); +// } +} Property changes on: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/DirectionTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/RoomTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/RoomTest.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/RoomTest.java 2007-11-01 00:00:59 UTC (rev 158) @@ -0,0 +1,32 @@ +package net.sf.mud4j.world; + +import net.sf.mud4j.world.link.LocationLink; +import net.sf.mud4j.world.link.TileLocationLink; + +public class RoomTest { + public void testRoomDirection() { + // Form a square of rooms + // 1-2 + // | | + // 4-3 + Room room1 = new Room(); + Room room2 = new Room(); + Room room3 = new Room(); + Room room4 = new Room(); + + // Link locations room1 and room2 going "east" from room1 + LocationLink link1and2 = new TileLocationLink(room1, room2, Direction.EAST); + + // Link locations room2 and room3 going "south" from room2 + LocationLink link2and3 = new TileLocationLink(room2, room3, Direction.SOUTH); + + // Link locations room1 and room2 going "east" from room1 + LocationLink link3and4 = new TileLocationLink(room3, room4, Direction.WEST); + + // Link locations room2 and room3 going "south" from room2 + LocationLink link4and1 = new TileLocationLink(room4, room1, Direction.NORTH); + + // @todo Register links with rooms or manager + // @todo Test moving Placeable through rooms using link + } +} Property changes on: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/RoomTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Added: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/TileLocationTest.java =================================================================== --- trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/TileLocationTest.java (rev 0) +++ trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/TileLocationTest.java 2007-11-01 00:00:59 UTC (rev 158) @@ -0,0 +1,9 @@ +package net.sf.mud4j.world; + +import junit.framework.TestCase; + +public class TileLocationTest extends TestCase { + public void testMove() { + + } +} Property changes on: trunk/mud4j-core/src/test/unit/net/sf/mud4j/world/TileLocationTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |