/** * Determine if the newValue has surpassed the threshold value compared with the original value. * <p> * When the originalValue is null, it is automatically assumed to be outside the threshold, because it means the * property hasn't been seen before. * <p> * If any of the parameters cannot be converted to a {@link Float}, then this method returns true when the * original and new value are not equal and false otherwise. * * @param threshold * The threshold value * @param originalValue * The original or last sent value * @param newValue * The new value to check * @return true if the new value is outside the threshold or false otherwise. */ public static bool IsValueOutsideOfThreshold(Real threshold, Encodable originalValue, Encodable newValue) { float floatThreshold = ConvertEncodableToFloat(threshold); float floatOriginal = ConvertEncodableToFloat(originalValue); float floatNewValue = ConvertEncodableToFloat(newValue); // This property hasn't been seen before, so a notification is required if (originalValue == null) { return(true); } // Handle types that can't do threshold comparisons else if (floatThreshold == float.MinValue || floatOriginal == float.MinValue || floatNewValue == float.MinValue) { return(!originalValue.Equals(newValue)); } else { // Due to floating point maths, it's possible that where the difference should be equal to the threshold // and not be outside the threshold actually evaluates to true due to precision errors. However since // this threshold is calculated only for use in deciding whether to trigger a COV notification, small // margins of error on boundary cases are acceptable. return(Math.Abs(floatNewValue - floatOriginal) > floatThreshold); } }
private void setPropertyImpl(PropertyIdentifier pid, Encodable value) { Encodable oldValue = (Encodable)properties[pid]; properties[pid] = value; if (!value.Equals(oldValue)) { // Check for subscriptions. if (ObjectCovSubscription.SendCovNotification(Id.ObjectType, pid, this.getCovIncrement())) { //synchronized(covSubscriptions) { long now = System.DateTime.Now.Ticks; ObjectCovSubscription sub; for (int i = covSubscriptions.Count - 1; i >= 0; i--) { sub = (ObjectCovSubscription)covSubscriptions[i]; if (sub.HasExpired(now)) { covSubscriptions.RemoveAt(i); } else if (sub.IsNotificationRequired(pid, value)) { sendCovNotification(sub, now); } } //} } } }
public bool contains(Encodable value) { foreach (Encodable e in Values) { if (value.Equals(e)) { return(true); } } return(false); }
public void remove(Encodable value) { if (value == null) { return; } for (int i = 0; i < Values.Count; i++) { if (value.Equals(Values[i])) { remove(i + 1); break; } } }