How can I write a condition in java to check for an enum value that start with IOS
?
for the following condition it just sets it equal to IOS
but I want my condition to have my getSoftwareName()
to startWith IOS
if (request.getEquipmentInfo().getSoftwareName() == RouterSwName.IOS) {
}
Here is my enum class:
public enum RouterSwName
{
JUNOS,
IOS,
IOS_XR,
IOS_XE,
OTHER; }
How about
request.getEquipmentInfo.getSoftwareName().toString().startsWith("IOS")
Assuming that getSoftwareName()
returns an enum, its toString()
should return raw enum name as String
. Then you simply check if it starts with "IOS".
you could:
if (request.getEquipmentInfo().getSoftwareName() == RouterSwName.IOS ||
request.getEquipmentInfo().getSoftwareName() == RouterSwName.IOS_XR ||
request.getEquipmentInfo().getSoftwareName() == RouterSwName.IOS_XE)
{
}
You could attach a property to each constant, but I would just keep a separate set of them:
private static final Set<RouteSwName> IOS_ROUTERS =
Collections.unmodifiableSet(
EnumSet.of(
RouteSwName.IOS,
RouteSwName.IOS_XR,
RouteSwName.IOS_XE));
Then you can just do:
if (IOS_ROUTERS.contains(request.getEquipmentInfo().getSoftwareName())) {
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.