Skip to content

Commit

Permalink
Add DataPointNumber
Browse files Browse the repository at this point in the history
Added the DataPointNumber class which provides
a generic DataPoint implementation for all
number types, including long (dword), float,
integer, etc.

This class is intended to supplement existing
functionality and provide a more flexible
interface for working with numerical values.
In the future, it could be expanded to be the
superclass of current numeric DataPoint classes.
  • Loading branch information
alexjhawk committed May 15, 2024
1 parent 68b8f3d commit 02af36f
Showing 1 changed file with 148 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.hms_networks.americas.sc.extensions.datapoint;

/**
* {@link Number} data point class
*
* <p>Class object for a DataPoint with a {@link Number} value
*
* @since 1.15.14
* @author HMS Networks; Americas
*/
public class DataPointNumber extends DataPoint {

/** Data point value */
protected Number value;

/**
* Constructor for a {@link Number} data point with specified quality.
*
* @param tagName data point tag name
* @param tagId data point tag ID
* @param tagUnit data point tag Unit
* @param value data point value
* @param time data point timestamp
* @param quality data point quality
*/
public DataPointNumber(
String tagName, int tagId, String tagUnit, Number value, String time, DataQuality quality) {
this.tagName = tagName;
this.tagId = tagId;
this.tagUnit = tagUnit;
this.value = value;
this.timestamp = time;
this.quality = quality;
}

/**
* Constructor for a {@link Number} data point without specified quality.
*
* @param tagName data point tag name
* @param tagId data point tag ID
* @param tagUnit data point tag Unit
* @param value data point value
* @param time data point timestamp
*/
public DataPointNumber(String tagName, int tagId, String tagUnit, Number value, String time) {
this.tagName = tagName;
this.tagId = tagId;
this.tagUnit = tagUnit;
this.value = value;
this.timestamp = time;
this.quality = DataQuality.GOOD;
}

/**
* Get and return the data point value.
*
* @return data point value
*/
public Number getValue() {
return value;
}

/**
* Set the data point value.
*
* <p>This method is unique to the {@link DataPointNumber} class, and is not available in other
* implementations of {@link DataPoint}.
*
* @param value data point value
*/
public void setValue(Number value) {
this.value = value;
}

/**
* Compares the data point to another data point.
*
* @param p data point to compare
* @return true if the timestamp, type, and value are the same
*/
public boolean equals(DataPoint p) {
boolean returnVal = false;
if (p instanceof DataPointNumber) {
returnVal =
p.getTimeStamp().equals(timestamp)
&& (((DataPointNumber) p).getValue() == null
? value == null
: ((DataPointNumber) p).getValue().equals(value))
&& p.getTagName().equals(tagName);
}
return returnVal;
}

/**
* Compares the data point's value to another data point's value.
*
* @param p data point to compare
* @return true if data points are of the same type and values are equal
*/
public boolean valueEquals(DataPoint p) {
boolean returnVal = false;
if (p instanceof DataPointNumber) {
returnVal =
((DataPointNumber) p).getValue() == null
? value == null
: ((DataPointNumber) p).getValue().equals(value);
}
return returnVal;
}

/**
* Get the data point type.
*
* @return data point type
*/
public DataType getType() {
return DataType.NUMBER;
}

/**
* Get the {@link String} representation of the data point value.
*
* @return data point value as a {@link String}
*/
public String getValueString() {
return value.toString();
}

/**
* Get the {@link Object} representation of the data point value.
*
* @return data point value as an {@link Object}
*/
public Object getValueObject() {
return value;
}

/**
* Clones the data point.
*
* @param tagName The tag name to use for the cloned data point
* @return cloned data point with the specified tag name
* @throws CloneNotSupportedException if the data point cannot be cloned
*/
public DataPoint clone(String tagName) throws CloneNotSupportedException {
return new DataPointNumber(tagName, tagId, tagUnit, value, timestamp, quality);
}
}

0 comments on commit 02af36f

Please sign in to comment.