All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docx4j.model.datastorage.xpathtracker.Histgram Maven / Gradle / Ivy

Go to download

docx4j is a library which helps you to work with the Office Open XML file format as used in docx documents, pptx presentations, and xlsx spreadsheets.

There is a newer version: 11.4.11
Show newest version
package org.docx4j.model.datastorage.xpathtracker;

import javax.xml.namespace.QName;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.HashMap;

/**
 * Keeps track of the number of siblings element found so far.
 *
 * @author Kohsuke Kawaguchi
 */
public class Histgram {
	
	private static Logger log = LoggerFactory.getLogger(Histgram.class);	
	
    private final Map occurrence = new HashMap();

    protected String current;
    protected int currentValue;

    public void update(String uri, String localName, String qName) {
    	
    	if (localName.contains(":") /* QName constructor allows that */) {
    		log.error("Unexpected localName " + localName);
    		throw new java.lang.IllegalArgumentException("Unexpected localName " + localName);
    	}    	
    	
        QName qn = new QName(uri,localName);
        Integer v = occurrence.get(qn);
        if(v==null) {
        	v=1;
        } else {
        	v++;
        }

        occurrence.put(qn,v);
        current = qName;
        currentValue = v;
    }

    public void appendPath(StringBuilder buf) {
        if(current==null)
            return; // this is the head
        buf.append('/');
        buf.append(current);
        buf.append('[');
        buf.append(currentValue);
        buf.append(']');
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy