jlcout / epctagcoder

Java library for RFID EPC encode / decode

Home Page:https://jlcout.github.io/epctagcoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String parameter for withTagSize

davejbur opened this issue · comments

Hi, this is a really useful library, many thanks! (Have you thought about getting it on Maven?)

Anyway, I'm having a problem where I've got a tag URI, and I want to build another one based on the information in the first one (replacing the first digit in the individual asset reference).

I've therefore got:

String aTagUri = "urn:epc:tag:giai-96:1.1234567.2987654321987";
ParseGIAI parserTagSeen = ParseGIAI.Builder().withEPCTagURI(aTagUri).build();
giaiSeen = parserTagSeen.getGIAI();
ParseGIAI parserTagMaster = ParseGIAI.Builder().withCompanyPrefix(giaiSeen.getCompanyPrefix()).withIndividualAssetReference("9"+giaiSeen.getIndividualAssetReference().substring(1)).withTagSize(GIAITagSize.valueOf(giaiSeen.getTagSize())).withFilterValue(GIAIFilterValue.valueOf(giaiSeen.getFilterValue())).build();

Note the withTagSize step requires an enumerated value, not a string.

However, I then get the error:

Failed to parse tag 'urn:epc:tag:giai-96:1.1234567.2987654321987': 
java.lang.IllegalArgumentException: No enum constant org.epctagcoder.option.GIAI.GIAITagSize.96
	at java.lang.Enum.valueOf(Enum.java:240) ~[?:?]
	at org.epctagcoder.option.GIAI.GIAITagSize.valueOf(GIAITagSize.java:6) ~[epctagcoder-0.0.6-SNAPSHOT.jar:?]
	at <my code location> [classes/:?]

I imagine this is because valueOf isn't implemented for the enumerated type? Can it be? Or is there another/better way of getting from a string to a GIAITagSize?

(An alternative method is to add a get/set to ParseGIAI for individualAssetReference - this makes it possible to build the new tag using withEPCTagURI and the original uri, then setIndividualAssetReference on that. But that seems to be a long-winded way of doing it...)

(edit) Or, I suppose, creating a GIAI#getGiaiTagSize method that returns a GIAITagSize?

Yes, you are right withTagSize step requires an enumerated value.

If you are still unable to resolve this issue, let me know, that next weekend I will see a solution for you.

Thanks - yes, it would be good to get a fix for this.

At present I'm using a workaround which is OK for me - I've modified your ParseGIAI by adding public setIndividualAssetReference & getIndividualAssetReference methods, then:

'''
ParseGIAI parserTagMaster = ParseGIAI.Builder().withEPCTagURI(aTagUri ).build();
parserTagMaster.setIndividualAssetReference("9"+giaiSeen.getIndividualAssetReference().substring(1));
'''

But having a method for getting from a string to an enumerated tagsize would be much easier and more obvious:-)

Thanks!

hi, try this way:

.withTagSize( GIAITagSize.forCode(Integer.parseInt(giaiSeen.getTagSize())) )

logically this can be done to:

.withFilterValue( GIAIFilterValue.forCode(Integer.parseInt(giaiSeen.getFilterValue())) )

Great! - thank you very much for that, I missed the forCode method, I thought there must be some way of doing it but couldn't work it out. Thanks again for you help and the time you took.