Skip to content

Commit

Permalink
Add testing, fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jul 21, 2024
1 parent 76ea15a commit 623ec94
Show file tree
Hide file tree
Showing 18 changed files with 985 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void update(boolean[] value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public void update(boolean value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_hasLastValue;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ public DataLogWriter(OutputStream os) {
}

/** Explicitly flushes the log data to disk. */
@Override
public void flush() {
DataLogJNI.flush(m_impl);
if (m_os == null) {
return;
}
try {
int pos = 0;
for (;;) {
for (; ; ) {
int qty = DataLogJNI.copyWriteBuffer(m_impl, m_buf, pos);
if (qty == 0) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void update(double[] value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public void update(double value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_hasLastValue;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void update(float[] value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public void update(float value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_hasLastValue;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void update(long[] value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public void update(long value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_hasLastValue;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ public void update(T value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public boolean hasLastValue() {
synchronized (m_buf) {
if (m_immutable) {
return m_lastValue != null;
} else if (m_cloneable && m_lastValue != null) {
return true;
}
return m_lastValueBuf != null;
}
}

/**
* Gets the last value.
*
Expand All @@ -166,11 +182,7 @@ public T getLastValue() {
synchronized (m_buf) {
if (m_immutable) {
return m_lastValue;
}
if (m_cloneable) {
if (m_lastValue == null) {
return null;
}
} else if (m_cloneable && m_lastValue != null) {
try {
return m_buf.getProto().clone(m_lastValue);
} catch (CloneNotSupportedException e) {
Expand Down
10 changes: 10 additions & 0 deletions wpiutil/src/main/java/edu/wpi/first/util/datalog/RawLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ public void update(ByteBuffer value, int start, int len) {
update(value, start, len, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand All @@ -283,6 +292,7 @@ private boolean equalsLast(byte[] value, int start, int len) {
return Arrays.equals(m_lastValue.array(), 0, len, value, start, start + len);
}

@SuppressWarnings("PMD.SimplifyBooleanReturns")
private boolean equalsLast(ByteBuffer value) {
if (m_lastValue == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void update(String[] value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public void update(String value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public synchronized boolean hasLastValue() {
return m_lastValue != null;
}

/**
* Gets the last value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ public void update(Collection<T> value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public boolean hasLastValue() {
synchronized (m_buf) {
if (m_immutable) {
return m_lastValue != null;
} else if (m_cloneable && m_lastValue != null) {
return true;
}
return m_lastValueBuf != null;
}
}

/**
* Gets the last value.
*
Expand All @@ -218,18 +234,16 @@ public void update(Collection<T> value) {
@SuppressWarnings("PMD.ReturnEmptyCollectionRatherThanNull")
public T[] getLastValue() {
synchronized (m_buf) {
if (m_immutable || m_cloneable) {
if (m_immutable) {
if (m_lastValue == null) {
return null;
}
if (m_immutable) {
return Arrays.copyOf(m_lastValue, m_lastValueLen);
} else {
try {
return cloneArray(m_lastValue);
} catch (CloneNotSupportedException e) {
// fall through
}
return Arrays.copyOf(m_lastValue, m_lastValueLen);
} else if (m_cloneable && m_lastValue != null) {
try {
return cloneArray(m_lastValue, m_lastValueLen);
} catch (CloneNotSupportedException e) {
// fall through
}
}
if (m_lastValueBuf == null) {
Expand Down Expand Up @@ -276,11 +290,11 @@ private boolean equalsLast(Collection<T> arr) {
return true;
}

private T[] cloneArray(T[] in) throws CloneNotSupportedException {
private T[] cloneArray(T[] in, int len) throws CloneNotSupportedException {
Struct<T> s = m_buf.getStruct();
@SuppressWarnings("unchecked")
T[] arr = (T[]) Array.newInstance(s.getTypeClass(), in.length);
for (int i = 0; i < in.length; i++) {
T[] arr = (T[]) Array.newInstance(s.getTypeClass(), len);
for (int i = 0; i < len; i++) {
arr[i] = s.clone(in[i]);
}
return arr;
Expand All @@ -302,7 +316,7 @@ private void copyToLast(T[] value) throws CloneNotSupportedException {
if (m_immutable) {
m_lastValue = Arrays.copyOf(value, value.length);
} else {
m_lastValue = cloneArray(value);
m_lastValue = cloneArray(value, value.length);
}
} else {
if (m_immutable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ public void update(T value) {
update(value, 0);
}

/**
* Gets whether there is a last value.
*
* @return True if last value exists, false otherwise.
*/
public boolean hasLastValue() {
synchronized (m_buf) {
if (m_immutable) {
return m_lastValue != null;
} else if (m_cloneable && m_lastValue != null) {
return true;
}
return m_lastValueBuf != null;
}
}

/**
* Gets the last value.
*
Expand All @@ -151,11 +167,7 @@ public T getLastValue() {
synchronized (m_buf) {
if (m_immutable) {
return m_lastValue;
}
if (m_cloneable) {
if (m_lastValue == null) {
return null;
}
} else if (m_cloneable && m_lastValue != null) {
try {
return m_buf.getStruct().clone(m_lastValue);
} catch (CloneNotSupportedException e) {
Expand Down
Loading

0 comments on commit 623ec94

Please sign in to comment.