<commit_before>/**
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  <NAME>
 * <p/>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p/>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package jlibs.xml.sax.sniff;

import javax.xml.namespace.NamespaceContext;
import java.io.PrintStream;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
public class XPathResults implements Debuggable{
    private NamespaceContext nsContext;
    private Map<String, Object> map;

    public XPathResults(NamespaceContext nsContext, List<XPath> xpaths){
        this.nsContext = nsContext;
        map = new LinkedHashMap<String, Object>(xpaths.size());
        for(XPath xpath: xpaths)
            map.put(xpath.toString(), xpath.result);
    }

    public NamespaceContext getNamespaceContext(){
        return nsContext;
    }

    public Object getResult(XPath xpath){
        return map.get(xpath.toString());
    }

    public void print(PrintStream out){
        for(Map.Entry<String, Object> entry: map.entrySet()){
            out.printf("XPath: %s%n", entry.getKey());
            if(entry.getValue() instanceof Collection){
                int i = 0;
                for(Object item: (Collection)entry.getValue())
                    out.printf("      %d: %s%n", ++i, item);
            }else
                out.printf("      %s\n", entry.getValue());
            out.println();
        }
    }
}<commit_msg>printing<commit_after>/**
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  <NAME>
 * <p/>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p/>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package jlibs.xml.sax.sniff;

import javax.xml.namespace.NamespaceContext;
import java.io.PrintStream;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author <NAME>
 */
public class XPathResults implements Debuggable{
    private NamespaceContext nsContext;
    private Map<String, Object> map;

    public XPathResults(NamespaceContext nsContext, List<XPath> xpaths){
        this.nsContext = nsContext;
        map = new LinkedHashMap<String, Object>(xpaths.size());
        for(XPath xpath: xpaths)
            map.put(xpath.toString(), xpath.result);
    }

    public NamespaceContext getNamespaceContext(){
        return nsContext;
    }

    public Object getResult(XPath xpath){
        return map.get(xpath.toString());
    }

    /*-------------------------------------------------[ Printing ]---------------------------------------------------*/
    
    private void print(PrintStream out, String xpath, Object result){
        out.printf("XPath: %s%n", xpath);
        if(result instanceof Collection){
            int i = 0;
            for(Object item: (Collection)result)
                out.printf("      %d: %s%n", ++i, item);
        }else
            out.printf("      %s\n", result);
    }

    public void printResult(PrintStream out, XPath xpath){
        print(out, xpath.toString(), map.get(xpath.toString()));
    }

    public void print(PrintStream out){
        for(Map.Entry<String, Object> entry: map.entrySet()){
            print(out, entry.getKey(), entry.getValue());
            out.println();
        }
    }
}
{'fraction_non_alphanumeric': 0.13016330451488953, 'fraction_numerical': 0.0033621517771373678, 'mean_word_length': 2.5967184801381693, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311848', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1130, 'n_words': 377}