807ea788cbd623bd6e662b1255b9d0a11f204331
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / analysis / UserAction.java
1 package edu.uci.iotproject.analysis;
2
3 import java.time.Instant;
4
5 /**
6  * Models a user's action, such as toggling the smart plug on/off at a given time.
7  *
8  * @author Janus Varmarken
9  */
10 public class UserAction {
11
12     /**
13      * The specific type of action the user performed.
14      */
15     private final Type mType;
16
17     /**
18      * The time the action took place.
19      */
20     private final Instant mTimestamp;
21
22     public UserAction(Type typeOfAction, Instant timeOfAction) {
23         mType = typeOfAction;
24         mTimestamp = timeOfAction;
25     }
26
27     /**
28      * Get the specific type of action performed by the user.
29      * @return the specific type of action performed by the user.
30      */
31     public Type getType() {
32         return mType;
33     }
34
35     /**
36      * Get the time at which the user performed this action.
37      * @return the time at which the user performed this action.
38      */
39     public Instant getTimestamp() {
40         return mTimestamp;
41     }
42
43     /**
44      * Enum for indicating what type of action the user performed.
45      */
46     public enum Type {
47         TOGGLE_ON, TOGGLE_OFF
48     }
49
50
51     @Override
52     public boolean equals(Object obj) {
53         if (this == obj) {
54             return true;
55         }
56         if (obj instanceof UserAction) {
57             UserAction that = (UserAction) obj;
58             return this.mType == that.mType && this.mTimestamp.equals(that.mTimestamp);
59         } else {
60             return false;
61         }
62     }
63
64     @Override
65     public int hashCode() {
66         final int prime = 31;
67         int hashCode = 17;
68         hashCode = prime * hashCode + mType.hashCode();
69         hashCode = prime * hashCode + mTimestamp.hashCode();
70         return hashCode;
71     }
72
73     @Override
74     public String toString() {
75        return String.format("[ %s @ %s ]", mType.name(), mTimestamp.toString());
76     }
77 }