WSPlaceholderUtil { public static Map<Integer, PHData> makePlaceholderMap( WSTextSegmentPlaceholder[] holders ) { TreeMap<Integer, PHData> phmap = new TreeMap<>(); Deque<PHData> tagStack = new ArrayDeque<>(); for ( WSTextSegmentPlaceholder h : holders ) { PHData phdata = parsePlaceholderContent(h.getText(), h.getId()); switch (phdata.type) { case OPEN: tagStack.push(phdata); break; case CLOSED: if (!tagStack.isEmpty()) { PHData previousTag = tagStack.peek(); if (previousTag.type == OPEN && previousTag.tag.equals(phdata.tag)) { phdata.correspondingOpenTag = tagStack.pop(); } } break; case STANDALONE: break; } phdata.wsid = h.getId(); phmap.put(h.getId(), phdata); } return phmap; }  static String replacePlaceholders( String s, Map<Integer, PHData> phmap ); static Map<Integer, PHData> makePlaceholderMap( WSTextSegmentPlaceholder[] holders ); static String restorePlaceholders( String s, Map<Integer, PHData> phmap ); static String findEndTagsAtBeginning( String s ); static String removeEndTags( String s );  }
@Test public void testMakePlaceholderMap() { WSTextSegmentPlaceholder[] wsphs = new WSTextSegmentPlaceholder[3]; wsphs[0] = new MockWSTextSegmentPlaceholder( "<img src=\"xyz.jpg\" />", 1 ); wsphs[1] = new MockWSTextSegmentPlaceholder( "<a href=\"xyz.html\" > ", 2 ); wsphs[2] = new MockWSTextSegmentPlaceholder( "</a>", 3 ); Map<Integer, PHData> map = WSPlaceholderUtil.makePlaceholderMap( wsphs ); assertEquals( 3, map.size() ); assertEquals( "<img ws_id='1'/>", map.get( 1 ).mtForm ); assertEquals( "<a ws_id='2'>", map.get( 2 ).mtForm ); assertEquals( "</a>", map.get( 3 ).mtForm ); }