Tag { @Override public String toString() { String tagClassString; switch (tagClass) { case Tag.UNIVERSAL: tagClassString = "UNIVERSAL"; break; case Tag.APPLICATION: tagClassString = "APPLICATION"; break; case Tag.CONTEXT: tagClassString = "CONTEXT"; break; case Tag.PRIVATE: tagClassString = "PRIVATE"; break; default: tagClassString = "UNKWOWN"; break; } return String.format( "TAG: size=%d Class=%s, Type=%s, Number=%X", tagSize, tagClassString, tagType, tagNumber); } Tag(int tagNumber, byte tagClass, TagType tagType, int tagSize);  Tag(byte[] binary, int offset); int getTagNumber(); byte getTagClass(); TagType getTagType(); int getTagSize(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final byte UNIVERSAL; static final byte APPLICATION; static final byte CONTEXT; static final byte PRIVATE; }
@Test public void equals1() { Tag tag1 = new Tag(0x55, Tag.UNIVERSAL, Tag.TagType.PRIMITIVE, 2); Tag tag2 = new Tag(ByteArrayUtil.fromHex("1F550100"), 0); Tag tag3 = new Tag(ByteArrayUtil.fromHex("6F550100"), 0); System.out.println("Tag1: " + tag1.toString()); System.out.println("Tag2: " + tag2.toString()); System.out.println("Tag3: " + tag3.toString()); Assert.assertEquals(tag1, tag2); Assert.assertNotEquals(tag1, tag3); Assert.assertNotEquals(tag2, tag3); Tag tag4 = new Tag(0x05, Tag.UNIVERSAL, Tag.TagType.CONSTRUCTED, 1); Tag tag5 = new Tag(ByteArrayUtil.fromHex("250100"), 0); System.out.println("Tag4: " + tag4.toString()); System.out.println("Tag5: " + tag5.toString()); Assert.assertEquals(tag4, tag5); Tag tag6 = new Tag(0x07, Tag.UNIVERSAL, Tag.TagType.PRIMITIVE, 1); Tag tag7 = new Tag(ByteArrayUtil.fromHex("070100"), 0); System.out.println("Tag6: " + tag6.toString()); System.out.println("Tag7: " + tag7.toString()); Assert.assertEquals(tag6, tag7); Tag tag8 = new Tag(0x12, Tag.UNIVERSAL, Tag.TagType.PRIMITIVE, 2); Tag tag9 = new Tag(ByteArrayUtil.fromHex("1F120100"), 0); System.out.println("Tag8: " + tag8.toString()); System.out.println("Tag9: " + tag9.toString()); Assert.assertEquals(tag8, tag9); }