Examples of RipplePrintStream


Examples of net.fortytwo.ripple.io.RipplePrintStream

* @author Joshua Shinavier (http://fortytwo.net)
*/
public class ShowContextsCmd extends Command {
    public void execute(final QueryEngine qe, final ModelConnection mc)
            throws RippleException {
        final RipplePrintStream ps = qe.getPrintStream();

        Sink<RippleValue> printSink = new Sink<RippleValue>() {
            private int i = 0;

            public void put(final RippleValue v) throws RippleException {
                ps.print("[" + i++ + "] ");
                ps.println(v);
            }
        };

        ps.println("");
        mc.getContexts().writeTo(printSink);
        ps.println("");
    }
View Full Code Here

Examples of net.fortytwo.ripple.io.RipplePrintStream

                       final PrintStream out,
                       final PrintStream err) throws RippleException {
        this.model = model;
        this.evaluator = evaluator;
        lexicon = new Lexicon(model);
        printStream = new RipplePrintStream(out, lexicon);
        errorPrintStream = err;

        connection = model.createConnection(new LexiconUpdater(lexicon));

        initializeLexicon();
View Full Code Here

Examples of net.fortytwo.ripple.io.RipplePrintStream

* @author Joshua Shinavier (http://fortytwo.net)
*/
public class ShowPrefixesCmd extends Command {
    public void execute(final QueryEngine qe, final ModelConnection mc)
            throws RippleException {
        final RipplePrintStream ps = qe.getPrintStream();

        // Create a map of prefixes to names and find the longest prefix.
        Map<String, String> prefixesToNames = new HashMap<String, String>();
        Collector<Namespace> coll = new Collector<Namespace>();
        mc.getNamespaces().writeTo(coll);
        int max = 0;
        int j = 0;
        for (Object aColl : coll) {
            Namespace ns = (Namespace) aColl;
            prefixesToNames.put(ns.getPrefix(), ns.getName());

            int len = (ns.getPrefix() + j).length();
            if (len > max) {
                max = len;
            }
            j++;
        }
        final int maxlen = max + 4;

        // Alphabetize the prefixes.
        String[] array = new String[prefixesToNames.size()];
        prefixesToNames.keySet().toArray(array);
        Arrays.sort(array);

        ps.println("");

        // Print the namespaces, aligning the name portions with one another.
        int i = 0;
        for (String prefix : array) {
            String s = "[" + i++ + "] " + prefix + ":";
            int len = s.length();
            ps.print(s);

            for (int l = 0; l < maxlen - len + 2; l++) {
                ps.print(' ');
            }

            ps.print(prefixesToNames.get(prefix));
            ps.print('\n');
        }

        ps.println("");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.