Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.epics.vtype;

import java.util.Optional;

public interface DescriptionProvider {
public Optional<String> getDescription();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
*/
package org.epics.vtype;

import java.util.Optional;

/**
* A value that provides display information.
*
* @author carcassi
*/
public interface DisplayProvider {
public interface DisplayProvider extends DescriptionProvider {

/**
* The display associated with this value.
*
* @return the display; not null
*/
Display getDisplay();
default Optional<String> getDescription() {
return Optional.ofNullable(getDisplay().getDescription());
}
}
11 changes: 10 additions & 1 deletion epics-vtype/vtype/src/main/java/org/epics/vtype/IVBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.epics.vtype;

import java.util.Optional;

/**
* Immutable {@code VBoolean} implementation.
*
Expand All @@ -14,14 +16,17 @@ final class IVBoolean extends VBoolean {
private final Boolean value;
private final Alarm alarm;
private final Time time;
private final Optional<String> description;

IVBoolean(Boolean value, Alarm alarm, Time time) {
IVBoolean(Boolean value, Alarm alarm, Time time, Optional<String> description) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an overload so the api is backwards compatible.

@abrahamwolk abrahamwolk Oct 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IVBoolean is not part of the API: neither the constructor nor the class IVBoolean are visible outside of the package (they are not declared public).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe there is a sonarlint against having Optionals for input params, but not sure...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to encode the intent in the type, and representing the absence of a description by Optional.empty().

VType.argumentNotNull("value", value);
VType.argumentNotNull("alarm", alarm);
VType.argumentNotNull("time", time);
VType.argumentNotNull("description", description);
this.value = value;
this.alarm = alarm;
this.time = time;
this.description = description;
}

@Override
Expand All @@ -39,4 +44,8 @@ public Time getTime() {
return time;
}

@Override
public Optional<String> getDescription() {
return description;
}
}
11 changes: 10 additions & 1 deletion epics-vtype/vtype/src/main/java/org/epics/vtype/IVEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.epics.vtype;

import java.util.Optional;

/**
* Immutable {@code VEnum} implementation.
*
Expand All @@ -15,16 +17,19 @@ final class IVEnum extends VEnum {
private final Time time;
private final int index;
private final EnumDisplay enumDisplay;
private final Optional<String> description;

IVEnum(int index, EnumDisplay enumDisplay, Alarm alarm, Time time) {
IVEnum(int index, EnumDisplay enumDisplay, Alarm alarm, Time time, Optional<String> description) {
VType.argumentNotNull("enumDisplay", enumDisplay);
VType.argumentNotNull("alarm", alarm);
VType.argumentNotNull("time", time);
VType.argumentNotNull("index", index);
VType.argumentNotNull("description", description);
this.index = index;
this.enumDisplay = enumDisplay;
this.alarm = alarm;
this.time = time;
this.description = description;
}

@Override
Expand Down Expand Up @@ -56,4 +61,8 @@ public Time getTime() {
return time;
}

@Override
public Optional<String> getDescription() {
return description;
}
}
11 changes: 10 additions & 1 deletion epics-vtype/vtype/src/main/java/org/epics/vtype/IVString.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.epics.vtype;

import java.util.Optional;

/**
* Immutable {@code VString} implementation.
*
Expand All @@ -14,14 +16,17 @@ final class IVString extends VString {
private final String value;
private final Alarm alarm;
private final Time time;
private final Optional<String> description;

IVString(String value, Alarm alarm, Time time) {
IVString(String value, Alarm alarm, Time time, Optional<String> description) {
VType.argumentNotNull("value", value);
VType.argumentNotNull("alarm", alarm);
VType.argumentNotNull("time", time);
VType.argumentNotNull("description", description);
this.value = value;
this.alarm = alarm;
this.time = time;
this.description = description;
}

@Override
Expand All @@ -39,4 +44,8 @@ public Time getTime() {
return time;
}

@Override
public Optional<String> getDescription() {
return description;
}
}
19 changes: 17 additions & 2 deletions epics-vtype/vtype/src/main/java/org/epics/vtype/VBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
package org.epics.vtype;

import java.util.Objects;
import java.util.Optional;

/**
* Scalar boolean with alarm and timestamp.
*
* @author carcassi
*/
public abstract class VBoolean extends Scalar {
public abstract class VBoolean extends Scalar implements DescriptionProvider {

/**
* {@inheritDoc }
Expand All @@ -26,10 +27,24 @@ public abstract class VBoolean extends Scalar {
* @param value the boolean value
* @param alarm the alarm
* @param time the time
* @param description the description (Optional.empty() if not present.)
* @return the new value
*/
public static VBoolean of(final Boolean value, final Alarm alarm, final Time time, final Optional<String> description) {
return new IVBoolean(value, alarm, time, description);
}

/**
* Creates a new VBoolean with empty description field.
*
* @param value the boolean value
* @param alarm the alarm
* @param time the time
* @return the new value
*/
@Deprecated
public static VBoolean of(final Boolean value, final Alarm alarm, final Time time) {
return new IVBoolean(value, alarm, time);
return new IVBoolean(value, alarm, time, null);
}

@Override
Expand Down
20 changes: 18 additions & 2 deletions epics-vtype/vtype/src/main/java/org/epics/vtype/VEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.epics.vtype;

import java.util.Objects;
import java.util.Optional;

/**
* Scalar enum with alarm and timestamp.
Expand All @@ -15,7 +16,7 @@
*
* @author carcassi
*/
public abstract class VEnum extends Scalar {
public abstract class VEnum extends Scalar implements DescriptionProvider {

/**
* {@inheritDoc }
Expand All @@ -39,15 +40,30 @@ public abstract class VEnum extends Scalar {

/**
* Create a new VEnum.
*
* @param index the index in the label array
* @param metaData the metadata
* @param alarm the alarm
* @param time the time
* @param description the description (Optional.empty() if not present.)
* @return the new value
*/
public static VEnum of(int index, EnumDisplay metaData, Alarm alarm, Time time, Optional<String> description) {
return new IVEnum(index, metaData, alarm, time, description);
}

/**
* Create a new VEnum with no description.
*
* @param index the index in the label array
* @param metaData the metadata
* @param alarm the alarm
* @param time the time
* @return the new value
*/
@Deprecated
public static VEnum of(int index, EnumDisplay metaData, Alarm alarm, Time time) {
return new IVEnum(index, metaData, alarm, time);
return new IVEnum(index, metaData, alarm, time, Optional.empty());
}

@Override
Expand Down
19 changes: 17 additions & 2 deletions epics-vtype/vtype/src/main/java/org/epics/vtype/VString.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
package org.epics.vtype;

import java.util.Objects;
import java.util.Optional;

/**
* Scalar string with alarm and timestamp.
*
* @author carcassi
*/
public abstract class VString extends Scalar {
public abstract class VString extends Scalar implements DescriptionProvider {

/**
* {@inheritDoc }
Expand All @@ -22,14 +23,28 @@ public abstract class VString extends Scalar {

/**
* Creates a new VString.
*
* @param value the string value
* @param alarm the alarm
* @param time the time
* @param description the description (Optional.empty() if not present.)
* @return the new value
*/
public static VString of(final String value, final Alarm alarm, final Time time, final Optional<String> description) {
return new IVString(value, alarm, time, description);
}

/**
* Creates a new VString with no description.
*
* @param value the string value
* @param alarm the alarm
* @param time the time
* @return the new value
*/
@Deprecated
public static VString of(final String value, final Alarm alarm, final Time time) {
return new IVString(value, alarm, time);
return new IVString(value, alarm, time, Optional.empty());
}

@Override
Expand Down