package de.ugoe.cs.eventbench.data; import java.security.InvalidParameterException; import java.util.LinkedList; import java.util.List; import de.ugoe.cs.eventbench.IReplayDecorator; /** *

* Subclass of {@link Event} for events that contain all informations required * for replaying them, i.e., generating scripts that can used for automated * software execution. *

* * @author Steffen Herbold * @version 1.0 * * @param * Allows only types that extend {@link IReplayable} and is used to * define a list of replayables that describe the replay of the * event. */ public class ReplayableEvent extends Event { /** * Id for object serialization. */ private static final long serialVersionUID = 1L; /** *

* List of {@link IReplayable}s of type T that describes the replay of an * event. The {@link IReplayable}s can be interpreted as sub-events * on the platform level that make up the abstract event. *

*/ protected List replayEvents = new LinkedList();; /** *

* Defines whether the replay is valid or invalid. It may be invalid, e.g., * due to errors during the generation of the event or lack of vital * information. *

*/ protected boolean replayValid = true; /** *

* {@link IReplayDecorator} used when replays of this type are written. *

*/ protected IReplayDecorator decorator = null; /** *

* Constructor. Creates a new event with the given type. *

* * @param type * type of the event * @see Event#Event(String) */ public ReplayableEvent(String type) { super(type); } /** *

* Adds a new {@link IReplayable} of type T to the replay sequence. *

* * @param replayable * element that is added to the sequence * @throws InvalidParameterException * thrown is replayable is null */ public void addReplayEvent(T replayable) { if (replayable == null) { throw new InvalidParameterException("replayble must not be null"); } replayEvents.add(replayable); } /** *

* Adds a {@link List}ist of {@link IReplayable} to the replay sequence. *

* * @param generatedReplaySeq * {@link List} that is added to the sequence * @throws InvalidParameterException * thrown if generatedReplaySeq is null */ public void addReplaySequence(List generatedReplaySeq) { if (generatedReplaySeq == null) { throw new InvalidParameterException( "generatedReplaySeq must not be null"); } replayEvents.addAll(generatedReplaySeq); } /** *

* Returns the {@link IReplayDecorator} of the event. *

* * @return {@link IReplayDecorator} of the event; null if no decorator has * been set */ public IReplayDecorator getReplayDecorator() { return decorator; } /** *

* Returns a the list of replay events. *

*

* The return value is a copy of the list used internally! *

* * @return list of replay events. */ public List getReplayMessages() { return new LinkedList(replayEvents); } /** *

* Returns whether the replay is valid or not. *

* * @return true, if replay is valid; false otherwise. */ public boolean hasValidReplay() { return replayValid; } /** *

* Marks the replay as invalid. Once marked as invalid, it remains so and * cannot be changed back to valid. *

*/ public void invalidateReplay() { replayValid = false; } /** *

* Sets the {@link IReplayDecorator} associated with the event. *

* * @param decorator * decorator associated with the event */ public void setDecorator(IReplayDecorator decorator) { this.decorator = decorator; } /* * (non-Javadoc) * * @see de.ugoe.cs.eventbench.data.Event#equals(java.lang.Object) */ @Override public boolean equals(Object other) { if (this == other) { return true; } if (other instanceof ReplayableEvent) { ReplayableEvent otherEvent = (ReplayableEvent) other; if (replayEvents != null) { return super.equals(otherEvent) && replayEvents.equals(otherEvent.replayEvents) && replayValid == otherEvent.replayValid; } else { return super.equals(otherEvent) && otherEvent.replayEvents == null && replayValid == otherEvent.replayValid; } } else { return false; } } @Override public boolean canEqual(Object other) { return (other instanceof ReplayableEvent); } /* * (non-Javadoc) * * @see de.ugoe.cs.eventbench.data.Event#hashCode() */ @Override public int hashCode() { int multiplier = 17; int hash = super.hashCode(); if (replayEvents != null) { hash = multiplier * hash + replayEvents.hashCode(); } hash = multiplier * hash + (replayValid ? 1 : 0); return hash; } }