Skip to content

Commit

Permalink
enum fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed Sep 11, 2024
1 parent e1fa80d commit 9026349
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/java/org/cip4/jdflib/extensions/MessageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ public enum EFamily

public static EFamily getEnum(final String name)
{
return EnumUtil.getJavaEnumIgnoreCase(EFamily.class, name);
final EFamily ret = EnumUtil.getJavaEnumIgnoreCase(EFamily.class, name);
if (ret == null && name != null)
{
final String sl = name.toLowerCase();
for (final EFamily f : values())
{
if (sl.startsWith(f.name().toLowerCase()))
return f;
}

}
return ret;
}

public String getType(final String base)
Expand All @@ -75,6 +86,7 @@ public String getType(final String base)
}
return null;
}

}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/cip4/jdflib/extensions/ProductHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public enum eProductType

public static eProductType getEnum(final String val)
{
return EnumUtil.getJavaEnumIgnoreCase(eProductType.class, val);
final String val2 = StringUtil.replaceString(val, JDFConstants.BLANK, null);
return EnumUtil.getJavaEnumIgnoreCase(eProductType.class, val2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.cip4.jdflib.JDFTestCaseBase;
Expand Down Expand Up @@ -184,6 +185,8 @@ void testGetFamilyEnumType()
assertEquals(f, EFamily.getEnum(f.name().toLowerCase() + "Foo"));
assertEquals("Foo", EFamily.getEnum(f.name()).getType(f.name().toLowerCase() + "Foo"));
}
assertNull(EFamily.getEnum(null));
assertNull(EFamily.getEnum("blub"));
}

/**
Expand Down

0 comments on commit 9026349

Please sign in to comment.