001 package org.hackystat.telemetry.analyzer.model; 002 003 import org.hackystat.utilities.time.period.TimePeriod; 004 005 /** 006 * Represents one data point a telemetry stream. 007 * 008 * @author (Cedric) Qin Zhang 009 */ 010 public class TelemetryDataPoint { 011 012 private TimePeriod period; 013 014 private Number value; 015 016 /** 017 * Constructs this instance. 018 * 019 * @param timePeriod A time period. It's either day, week, or month. 020 * @param value The value associated with the time period. 021 */ 022 public TelemetryDataPoint(TimePeriod timePeriod, Number value) { 023 this.period = timePeriod; 024 this.value = value; 025 } 026 027 /** 028 * Gets the time period. 029 * 030 * @return The time period. 031 */ 032 public TimePeriod getPeriod() { 033 return this.period; 034 } 035 036 /** 037 * Gets the value. 038 * 039 * @return The value. 040 */ 041 public Number getValue() { 042 return this.value; 043 } 044 045 /** 046 * Indicates whether some other object is "equal to" this one. 047 * 048 * @param obj the reference object with which to compare. 049 * @return <code>true</code> if this object is the same as the obj argument; 050 * <code>false</code> otherwise. 051 */ 052 @Override 053 public boolean equals(Object obj) { 054 if (!(obj instanceof TelemetryDataPoint)) { 055 return false; 056 } 057 058 TelemetryDataPoint another = (TelemetryDataPoint) obj; 059 if (!this.period.equals(another.period)) { 060 return false; 061 } 062 063 if (this.value == null && another.value == null) { 064 return true; 065 } 066 067 if (this.value != null) { 068 return this.value.equals(another.value); 069 } 070 return another.value.equals(this.value); 071 } 072 073 /** 074 * Gets the hash code. 075 * 076 * @return The hash code. 077 */ 078 @Override 079 public int hashCode() { 080 int result = this.period.hashCode(); 081 if (this.value != null) { 082 result = result / 13 + this.value.hashCode() / 2 + 7; 083 } 084 return result; 085 } 086 }