[1] | 1 | package de.ugoe.cs.eventbench.data;
|
---|
| 2 |
|
---|
| 3 | import java.util.LinkedList;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
[57] | 6 | import de.ugoe.cs.eventbench.IReplayDecorator;
|
---|
| 7 |
|
---|
[79] | 8 | /**
|
---|
| 9 | * <p>
|
---|
| 10 | * Subclass of {@link Event} for events that contain all informations required
|
---|
| 11 | * for replaying them, i.e., generating scripts that can used for automated
|
---|
| 12 | * software execution.
|
---|
| 13 | * </p>
|
---|
| 14 | *
|
---|
| 15 | * @author Steffen Herbold
|
---|
| 16 | * @version 1.0
|
---|
| 17 | *
|
---|
| 18 | * @param <T>
|
---|
| 19 | * Allows only types that extend {@link IReplayable} and is used to
|
---|
| 20 | * define a list of replayables that describe the replay of the
|
---|
| 21 | * event.
|
---|
| 22 | */
|
---|
[1] | 23 | public class ReplayableEvent<T extends IReplayable> extends Event<T> {
|
---|
| 24 |
|
---|
[79] | 25 | /**
|
---|
[86] | 26 | * Id for object serialization.
|
---|
| 27 | */
|
---|
| 28 | private static final long serialVersionUID = 1L;
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
[79] | 31 | * <p>
|
---|
| 32 | * List of {@link IReplayable}s of type T that describes the replay of an
|
---|
| 33 | * event. The {@link IReplayable}s can be interpreted as <it>sub-events</it>
|
---|
| 34 | * on the platform level that make up the abstract event.
|
---|
| 35 | * </p>
|
---|
| 36 | */
|
---|
[335] | 37 | protected List<T> replayEvents = new LinkedList<T>();;
|
---|
[1] | 38 |
|
---|
[79] | 39 | /**
|
---|
| 40 | * <p>
|
---|
| 41 | * Defines whether the replay is valid or invalid. It may be invalid, e.g.,
|
---|
| 42 | * due to errors during the generation of the event or lack of vital
|
---|
| 43 | * information.
|
---|
| 44 | * </p>
|
---|
| 45 | */
|
---|
[335] | 46 | protected boolean replayValid = true;
|
---|
[79] | 47 |
|
---|
| 48 | /**
|
---|
| 49 | * <p>
|
---|
| 50 | * {@link IReplayDecorator} used when replays of this type are written.
|
---|
| 51 | * </p>
|
---|
| 52 | */
|
---|
[335] | 53 | protected IReplayDecorator decorator = null;
|
---|
[79] | 54 |
|
---|
| 55 | /**
|
---|
| 56 | * <p>
|
---|
| 57 | * Constructor. Creates a new event with the given type.
|
---|
| 58 | * <p>
|
---|
| 59 | *
|
---|
| 60 | * @param type
|
---|
| 61 | * type of the event
|
---|
| 62 | * @see Event#Event(String)
|
---|
| 63 | */
|
---|
[1] | 64 | public ReplayableEvent(String type) {
|
---|
| 65 | super(type);
|
---|
| 66 | }
|
---|
[79] | 67 |
|
---|
| 68 | /**
|
---|
| 69 | * <p>
|
---|
| 70 | * Adds a new {@link IReplayable} of type T to the replay sequence.
|
---|
| 71 | * </p>
|
---|
| 72 | *
|
---|
| 73 | * @param replayable
|
---|
| 74 | * element that is added to the sequence
|
---|
| 75 | */
|
---|
| 76 | public void addReplayEvent(T replayable) {
|
---|
| 77 | replayEvents.add(replayable);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | /**
|
---|
| 81 | * <p>
|
---|
| 82 | * Adds a {@link List}ist of {@link IReplayable} to the replay sequence.
|
---|
| 83 | * </p>
|
---|
| 84 | *
|
---|
| 85 | * @param generatedReplaySeq
|
---|
| 86 | * {@link List} that is added to the sequence
|
---|
| 87 | */
|
---|
[1] | 88 | public void addReplaySequence(List<T> generatedReplaySeq) {
|
---|
| 89 | replayEvents.addAll(generatedReplaySeq);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[79] | 92 | /**
|
---|
| 93 | * <p>
|
---|
| 94 | * Returns the {@link IReplayDecorator} of the event.
|
---|
| 95 | * </p>
|
---|
| 96 | *
|
---|
| 97 | * @return {@link IReplayDecorator} of the event; null if no decorator has
|
---|
| 98 | * been set
|
---|
| 99 | */
|
---|
| 100 | public IReplayDecorator getReplayDecorator() {
|
---|
| 101 | return decorator;
|
---|
[1] | 102 | }
|
---|
[79] | 103 |
|
---|
[1] | 104 | /**
|
---|
| 105 | * <p>
|
---|
| 106 | * Returns a the list of replay events.
|
---|
[79] | 107 | * </p>
|
---|
[1] | 108 | * <p>
|
---|
| 109 | * The return value is a copy of the list used internally!
|
---|
| 110 | * </p>
|
---|
[79] | 111 | *
|
---|
| 112 | * @return list of replay events.
|
---|
[1] | 113 | */
|
---|
| 114 | public List<T> getReplayMessages() {
|
---|
| 115 | return new LinkedList<T>(replayEvents);
|
---|
| 116 | }
|
---|
[79] | 117 |
|
---|
| 118 | /**
|
---|
| 119 | * <p>
|
---|
| 120 | * Returns whether the replay is valid or not.
|
---|
| 121 | * </p>
|
---|
| 122 | *
|
---|
| 123 | * @return true, if replay is valid; false otherwise.
|
---|
| 124 | */
|
---|
[1] | 125 | public boolean hasValidReplay() {
|
---|
| 126 | return replayValid;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[79] | 129 | /**
|
---|
| 130 | * <p>
|
---|
| 131 | * Marks the replay as invalid. Once marked as invalid, it remains so and
|
---|
| 132 | * cannot be changed back to valid.
|
---|
| 133 | * </p>
|
---|
| 134 | */
|
---|
[1] | 135 | public void invalidateReplay() {
|
---|
| 136 | replayValid = false;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[79] | 139 | /**
|
---|
| 140 | * <p>
|
---|
| 141 | * Sets the {@link IReplayDecorator} associated with the event.
|
---|
| 142 | * </p>
|
---|
| 143 | *
|
---|
| 144 | * @param decorator
|
---|
| 145 | * decorator associated with the event
|
---|
| 146 | */
|
---|
[57] | 147 | public void setDecorator(IReplayDecorator decorator) {
|
---|
| 148 | this.decorator = decorator;
|
---|
| 149 | }
|
---|
[1] | 150 |
|
---|
[108] | 151 | /* (non-Javadoc)
|
---|
| 152 | * @see de.ugoe.cs.eventbench.data.Event#equals(java.lang.Object)
|
---|
| 153 | */
|
---|
| 154 | @Override
|
---|
| 155 | public boolean equals(Object other) {
|
---|
| 156 | if (this == other) {
|
---|
| 157 | return true;
|
---|
| 158 | }
|
---|
| 159 | if (other instanceof ReplayableEvent<?>) {
|
---|
| 160 | ReplayableEvent<?> otherEvent = (ReplayableEvent<?>) other;
|
---|
| 161 | return super.equals(otherEvent)
|
---|
| 162 | && replayEvents.equals(otherEvent.replayEvents)
|
---|
| 163 | && replayValid == otherEvent.replayValid;
|
---|
| 164 |
|
---|
| 165 | } else {
|
---|
| 166 | return false;
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | /* (non-Javadoc)
|
---|
| 171 | * @see de.ugoe.cs.eventbench.data.Event#hashCode()
|
---|
| 172 | */
|
---|
| 173 | @Override
|
---|
| 174 | public int hashCode() {
|
---|
| 175 | int multiplier = 17;
|
---|
| 176 | int hash = super.hashCode();
|
---|
| 177 | hash = multiplier * hash + replayEvents.hashCode();
|
---|
| 178 | hash = multiplier * hash + (replayValid ? 1 : 0);
|
---|
| 179 |
|
---|
| 180 | return hash;
|
---|
| 181 | }
|
---|
[1] | 182 | }
|
---|