/** * Add the given tag at the specified index to all permutations of the current parser path and increases the number of * permutations as necessary to satisfy the following relation: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** * Add the given tag at the specified index to all permutations of the current parser path and increases the number of * permutations as necessary to satisfy the following relation: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** * Add the given tag at the specified index to all permutations of the current parser path and increases the number of * permutations as necessary to satisfy the following relation: * * <pre>size = 2^n</pre> * * <p>where n is the path length.</p> * * @param tag to add to path. * @param index of tag relative to parent. */ private void addTag(final DERTag tag, final int index) { if (permutations.isEmpty()) { permutations.add(new DERPath().pushNode(tag.name())); permutations.add(new DERPath().pushNode(tag.name(), index)); } else { final Collection<DERPath> generation = new ArrayDeque<>(permutations.size()); for (DERPath p : permutations) { generation.add(new DERPath(p).pushNode(tag.name())); p.pushNode(tag.name(), index); } permutations.addAll(generation); } }
/** @throws Exception On test failure. */ @Test(groups = {"asn1"}) public void testPushPop() throws Exception { final DERPath path = new DERPath("/SEQ"); path.pushNode("OCTSTR"); Assert.assertEquals(path.toString(), "/SEQ/OCTSTR"); Assert.assertEquals(path.popNode(), "OCTSTR"); path.pushNode("INT", 1); Assert.assertEquals(path.toString(), "/SEQ/INT[1]"); Assert.assertEquals(path.popNode(), "INT[1]"); Assert.assertEquals(path.popNode(), "SEQ"); Assert.assertNull(path.popNode()); Assert.assertNull(path.popNode()); }