[305] | 1 | package de.ugoe.cs.eventbench.jfc.data;
|
---|
[299] | 2 |
|
---|
[300] | 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.Map;
|
---|
| 5 |
|
---|
[299] | 6 | import de.ugoe.cs.eventbench.data.IReplayable;
|
---|
| 7 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
[359] | 8 | import de.ugoe.cs.eventbench.jfc.JFCLogParser;
|
---|
[299] | 9 |
|
---|
| 10 | /**
|
---|
| 11 | * <p>
|
---|
| 12 | * This class defines JFC events.
|
---|
| 13 | * </p>
|
---|
| 14 | *
|
---|
| 15 | * @author Steffen Herbold
|
---|
| 16 | * @version 1.0
|
---|
| 17 | */
|
---|
| 18 | public class JFCEvent extends ReplayableEvent<IReplayable> {
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * <p>
|
---|
| 22 | * Id for object serialization.
|
---|
| 23 | * </p>
|
---|
| 24 | */
|
---|
| 25 | private static final long serialVersionUID = 1L;
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * <p>
|
---|
[300] | 29 | * Internal map of parameters associated with the event.
|
---|
| 30 | * </p>
|
---|
| 31 | */
|
---|
| 32 | private Map<String, String> parameters;
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * <p>
|
---|
| 36 | * Information about the event source.
|
---|
| 37 | * </p>
|
---|
| 38 | */
|
---|
| 39 | private Map<String, String> sourceParameters;
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * <p>
|
---|
| 43 | * Information about the parent of the event source.
|
---|
| 44 | * </p>
|
---|
| 45 | */
|
---|
| 46 | private Map<String, String> parentParameters;
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * <p>
|
---|
[299] | 50 | * Constructor. Creates a new JFCEvent.
|
---|
| 51 | * </p>
|
---|
| 52 | *
|
---|
| 53 | * @param type
|
---|
| 54 | * type of the event
|
---|
| 55 | */
|
---|
| 56 | public JFCEvent(String type) {
|
---|
| 57 | super(type);
|
---|
[300] | 58 | parameters = new HashMap<String, String>();
|
---|
[304] | 59 | sourceParameters = new HashMap<String, String>();
|
---|
| 60 | parentParameters = new HashMap<String, String>();
|
---|
[299] | 61 | }
|
---|
| 62 |
|
---|
[300] | 63 | /**
|
---|
| 64 | * <p>
|
---|
| 65 | * Adds a new parameter to the event.
|
---|
| 66 | * </p>
|
---|
| 67 | *
|
---|
| 68 | * @param name
|
---|
| 69 | * name of the parameter
|
---|
| 70 | * @param value
|
---|
| 71 | * value of the parameter
|
---|
| 72 | */
|
---|
| 73 | public void addParameter(String name, String value) {
|
---|
| 74 | parameters.put(name, value);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * <p>
|
---|
| 79 | * Retrieves the value of a parameter.
|
---|
| 80 | * </p>
|
---|
| 81 | *
|
---|
| 82 | * @param name
|
---|
| 83 | * name of the parameter
|
---|
| 84 | * @return value of the parameter
|
---|
| 85 | */
|
---|
| 86 | public String getParameter(String name) {
|
---|
| 87 | return parameters.get(name);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * <p>
|
---|
| 92 | * Adds new information about the source of the event.
|
---|
| 93 | * </p>
|
---|
| 94 | *
|
---|
| 95 | * @param name
|
---|
| 96 | * name of the information
|
---|
| 97 | * @param value
|
---|
| 98 | * value of the information
|
---|
| 99 | */
|
---|
| 100 | public void addSourceInformation(String name, String value) {
|
---|
| 101 | sourceParameters.put(name, value);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * <p>
|
---|
| 106 | * Retrieves information about the source of the event.
|
---|
| 107 | * </p>
|
---|
| 108 | *
|
---|
| 109 | * @param name
|
---|
| 110 | * name of the information
|
---|
| 111 | * @return value of the information
|
---|
| 112 | */
|
---|
| 113 | public String getSourceInformation(String name) {
|
---|
| 114 | return sourceParameters.get(name);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /**
|
---|
| 118 | * <p>
|
---|
| 119 | * Adds new information about the parent of the source of the event.
|
---|
| 120 | * </p>
|
---|
| 121 | *
|
---|
| 122 | * @param name
|
---|
| 123 | * name of the information
|
---|
| 124 | * @param value
|
---|
| 125 | * value of the information
|
---|
| 126 | */
|
---|
| 127 | public void addParentInformation(String name, String value) {
|
---|
| 128 | parentParameters.put(name, value);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /**
|
---|
| 132 | * <p>
|
---|
[359] | 133 | * Used by the {@link JFCLogParser} to extend the target string of the
|
---|
| 134 | * current event with a further ancestor. The resulting target string will
|
---|
| 135 | * have the structure {@code etc.grandparent.parent.eventtarget}.
|
---|
| 136 | * </p>
|
---|
| 137 | *
|
---|
| 138 | * @param extension
|
---|
| 139 | * extension for the target.
|
---|
| 140 | */
|
---|
| 141 | public void extendTarget(String extension) {
|
---|
| 142 | if (target == null || "".equals(target)) {
|
---|
| 143 | target = extension;
|
---|
| 144 | } else {
|
---|
| 145 | target += "." + extension;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /**
|
---|
| 150 | * <p>
|
---|
[300] | 151 | * Retrieves information about the parent of the source of the event.
|
---|
| 152 | * </p>
|
---|
| 153 | *
|
---|
| 154 | * @param name
|
---|
| 155 | * name of the information
|
---|
| 156 | * @return value of the information
|
---|
| 157 | */
|
---|
| 158 | public String getParentInformation(String name) {
|
---|
| 159 | return parentParameters.get(name);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /*
|
---|
| 163 | * (non-Javadoc)
|
---|
| 164 | *
|
---|
| 165 | * @see de.ugoe.cs.eventbench.data.ReplayableEvent#equals(java.lang.Object)
|
---|
| 166 | */
|
---|
| 167 | @Override
|
---|
| 168 | public boolean equals(Object other) {
|
---|
| 169 | if (other == this) {
|
---|
| 170 | return true;
|
---|
| 171 | }
|
---|
| 172 | if (other instanceof JFCEvent) {
|
---|
| 173 | return super.equals(other)
|
---|
| 174 | && parameters.equals(((JFCEvent) other).parameters);
|
---|
| 175 | }
|
---|
| 176 | return false;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /*
|
---|
| 180 | * (non-Javadoc)
|
---|
| 181 | *
|
---|
| 182 | * @see de.ugoe.cs.eventbench.data.ReplayableEvent#hashCode()
|
---|
| 183 | */
|
---|
| 184 | @Override
|
---|
| 185 | public int hashCode() {
|
---|
| 186 | int hashCode = super.hashCode();
|
---|
| 187 | hashCode *= parameters.hashCode();
|
---|
| 188 | return hashCode;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[299] | 191 | }
|
---|