Package org.jpos.tlv
Class CharTagMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,CharTag>
-
- org.jpos.tlv.CharTagMap
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,CharTag>
public class CharTagMap extends java.util.HashMap<java.lang.String,CharTag>
Class represents TLV tag map encoded as sequence of characters.The
CharTagMap
features:- operates (
pack
andunpack
) on character sequences - only one occurrence of the tag in the sequence is possible
- after build the tag size and length size are fixed
- length is encoded as decimal characters
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CharTagMap()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CharTagMap
addTag(java.lang.String tagId, java.lang.String value)
Adds a new tag to map.CharTag
createTLV(java.lang.String tagId, java.lang.String value)
Create new TLV tag.static CharTagMap
getInstance()
Creates new empty instance of text TLV tag map.java.lang.String
getTagValue(java.lang.String tagId)
Gets the value of the tag with given tagId from map.boolean
hasTag(java.lang.String tagId)
Chceck if the tag with given tag identifier is in this tag map.java.lang.String
pack()
Pack TLV Tags.protected void
setLengthSize(int size)
Sets size of length element.protected void
setTagSize(int size)
Sets size of tag element.void
unpack(java.lang.CharSequence data)
Unpack string to TLV tag map.protected void
validateTag(java.lang.String tagId)
protected void
withTagLengthSwap(boolean swap)
Sets size of length element.-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Constructor Detail
-
CharTagMap
public CharTagMap()
-
-
Method Detail
-
getInstance
public static CharTagMap getInstance()
Creates new empty instance of text TLV tag map.This method creates default TLV tag map which works on TLV data with followng parameters:
- TT - 2 ASCII characters of tag identifier
- LLL - 3 ASCII encoded decimal digits represents tag value length
- VAL - 0 or more (up to 999) ASCII encoded characters represents tag value
- Returns:
- new default sized instance of
CharTagMap
-
setTagSize
protected void setTagSize(int size) throws java.lang.IllegalArgumentException
Sets size of tag element.- Parameters:
size
- size of tag elament- Throws:
java.lang.IllegalArgumentException
-
setLengthSize
protected void setLengthSize(int size) throws java.lang.IllegalArgumentException
Sets size of length element.- Parameters:
size
- size of length elament- Throws:
java.lang.IllegalArgumentException
-
withTagLengthSwap
protected void withTagLengthSwap(boolean swap)
Sets size of length element.- Parameters:
swap
- indicates if tag element will be swapped with length element
-
unpack
public void unpack(java.lang.CharSequence data) throws java.lang.IllegalArgumentException
Unpack string to TLV tag map.- Parameters:
data
- sequence of characters encoded as TLV- Throws:
java.lang.IllegalArgumentException
- ifnull
or parsing error occurs
-
pack
public java.lang.String pack()
Pack TLV Tags.- Returns:
- string containing tags in TLV Format
-
addTag
public CharTagMap addTag(java.lang.String tagId, java.lang.String value) throws java.lang.IllegalArgumentException
Adds a new tag to map.- Parameters:
tagId
- tag identifier, notnull
value
- tag value- Returns:
- tag map instance for chaining
- Throws:
java.lang.IllegalArgumentException
- iftagId
isnull
or has invalid length.
-
createTLV
public CharTag createTLV(java.lang.String tagId, java.lang.String value) throws java.lang.IllegalArgumentException
Create new TLV tag.- Parameters:
tagId
- tag identifier, notnull
value
- tag value- Returns:
- TLV instance
- Throws:
java.lang.IllegalArgumentException
- iftagId
isnull
or has invalid length.
-
validateTag
protected void validateTag(java.lang.String tagId) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
getTagValue
public java.lang.String getTagValue(java.lang.String tagId)
Gets the value of the tag with given tagId from map.- Parameters:
tagId
- tag identifier- Returns:
- value tag value
-
hasTag
public boolean hasTag(java.lang.String tagId)
Chceck if the tag with given tag identifier is in this tag map.- Parameters:
tagId
- tag identifier- Returns:
true
if this map contains the tag, otherwise returnfalse
-
-