Package org.apache.sis.io

Examples of org.apache.sis.io.TableAppender


        String separator = columnSeparator;
        switch (borderWidth) {
            case 1: horizontalLine = '─'; separator += "│ "; break;
            case 2: horizontalLine = '═'; separator += "║ "; break;
        }
        final TableAppender table = new TableAppender(toAppendTo, separator);
        final Vocabulary resources = Vocabulary.getResources(headerLocale);
        /*
         * If there is a header for at least one statistics, write the full headers row.
         */
        if (horizontalLine != 0) {
            table.nextLine(horizontalLine);
        }
        if (showHeaders) {
            table.nextColumn();
            for (final String header : headers) {
                if (header != null) {
                    table.append(header);
                    table.setCellAlignment(TableAppender.ALIGN_CENTER);
                }
                table.nextColumn();
            }
            table.append(lineSeparator);
            if (horizontalLine != 0) {
                table.nextLine(horizontalLine);
            }
        }
        /*
         * Initialize the NumberFormat for formatting integers without scientific notation.
         * This is necessary since the format may have been modified by a previous execution
         * of this method.
         */
        final Format format = getFormat(Double.class);
        if (format instanceof DecimalFormat) {
            ((DecimalFormat) format).applyPattern("#0"); // Also disable scientific notation.
        } else if (format instanceof NumberFormat) {
            setFractionDigits((NumberFormat) format, 0);
        }
        /*
         * Iterates over the rows to format (count, minimum, maximum, mean, RMS, standard deviation),
         * then iterate over columns (statistics on sample values, on the first derivatives, etc.)
         * The NumberFormat configuration may be different for each column, but we can skip many
         * reconfiguration in the common case where there is only one column.
         */
        boolean needsConfigure = false;
        for (int i=0; i<KEYS.length; i++) {
            switch (i) {
                case 1: if (!showNaNCount) continue; else break;
                // Case 0 and 1 use the above configuration for integers.
                // Case 2 unconditionally needs a reconfiguration for floating point values.
                // Case 3 and others need reconfiguration only if there is more than one column.
                case 2: needsConfigure = true; break;
                case 3: needsConfigure = (stats[0].differences() != null); break;
            }
            table.setCellAlignment(TableAppender.ALIGN_LEFT);
            table.append(resources.getString(KEYS[i])).append(':');
            for (final Statistics s : stats) {
                final Number value;
                switch (i) {
                    case 0:  value = s.count();    break;
                    case 1:  value = s.countNaN(); break;
                    case 2:  value = s.minimum()break;
                    case 3:  value = s.maximum()break;
                    case 4:  value = s.mean();     break;
                    case 5:  value = s.rms();      break;
                    case 6:  value = s.standardDeviation(allPopulation); break;
                    default: throw new AssertionError(i);
                }
                if (needsConfigure) {
                    configure(format, s);
                }
                table.append(beforeFill);
                table.nextColumn(fillCharacter);
                table.append(format.format(value));
                table.setCellAlignment(TableAppender.ALIGN_RIGHT);
            }
            table.append(lineSeparator);
        }
        if (horizontalLine != 0) {
            table.nextLine(horizontalLine);
        }
        /*
         * TableAppender needs to be explicitly flushed in order to format the values.
         */
        table.flush();
    }
View Full Code Here


            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Commands));
            out.println(':');
        }
        try {
            final TableAppender table = new TableAppender(out, "  ");
            for (final String command : commandNames) {
                if (showHeader) {
                    table.append("  ");
                }
                table.append(command);
                if (!showHeader) {
                    table.append(':');
                }
                table.nextColumn();
                table.append(commands.getString(command));
                table.nextLine();
            }
            table.flush();
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Options));
            out.println(':');
            for (final Option option : validOptions) {
                final String name = option.name().toLowerCase(Locale.US);
                table.append("  ").append(Option.PREFIX).append(name);
                table.nextColumn();
                table.append(options.getString(name));
                table.nextLine();
            }
            table.flush();
        } catch (IOException e) {
            throw new AssertionError(e); // Should never happen, because we are writing to a PrintWriter.
        }
    }
View Full Code Here

         * @param out           Where to format the tree.
         * @param column        The columns of the tree table to format.
         * @param parentObjects An initially empty {@link IdentityHashMap}.
         */
        Writer(final Appendable out, final TableColumn<?>[] columns, final Map<Object,Object> parentObjects) {
            super(columns.length >= 2 ? new TableAppender(out, "") : out);
            this.columns = columns;
            this.formats = getFormats(columns, false);
            this.values  = new Object[columns.length];
            this.isLast  = new boolean[8];
            this.parentObjects = parentObjects;
View Full Code Here

         */
        final Vocabulary resources = Vocabulary.getResources(displayLocale);
        header.writeIdentifiers(out, true, colors, false, lineSeparator);
        out.append(lineSeparator);
        final char horizontalBorder = isBrief ? '─' : '═';
        final TableAppender table = (isBrief || !columnSeparator.equals(SEPARATOR)) ?
                new TableAppender(out, columnSeparator) : new TableAppender(out);
        table.setMultiLinesCells(true);
        table.nextLine(horizontalBorder);
        for (int i=0; ; i++) {
            boolean end = false;
            final short key;
            switch (i) {
                case 0: {
                    key = Vocabulary.Keys.Name;
                    break;
                }
                case 1: {
                    key = Vocabulary.Keys.Type;
                    break;
                }
                case 2: {
                    if (!showObligation) {
                       continue;
                    }
                    key = Vocabulary.Keys.Obligation;
                    break;
                }
                case 3: {
                    key = Vocabulary.Keys.ValueDomain;
                    break;
                }
                case 4: {
                    key = (values == null) ? Vocabulary.Keys.DefaultValue : Vocabulary.Keys.Value;
                    end = true;
                    break;
                }
                default: throw new AssertionError(i);
            }
            if (hasColors) table.append(X364.BOLD.sequence());
            table.append(resources.getString(key));
            if (hasColors) table.append(X364.NORMAL.sequence());
            if (!writeCodespaces && i == 0) {
                table.append(" (").append(groupCodespace).append(')');
            }
            if (end) break;
            nextColumn(table);
        }
        table.nextLine();
        /*
         * Now process to the formatting of (descriptor,value) pairs. Each descriptor's alias
         * will be formatted on its own line in a table row. If there is more than one value,
         * then each value will be formatted on its own line as well. Note that the values may
         * be null if there is none.
         */
        char horizontalLine = horizontalBorder;
        for (final Map.Entry<GeneralParameterDescriptor,ParameterTableRow> entry : descriptorValues.entrySet()) {
            if (horizontalLine != 0) {
                table.nextLine('─');
            }
            horizontalLine = isBrief ? 0 : '─';
            final ParameterTableRow row = entry.getValue();
            row.codespaceWidth = codespaceWidth;
            row.writeIdentifiers(table, writeCodespaces, null, hasColors, lineSeparator);
            nextColumn(table);
            final GeneralParameterDescriptor generalDescriptor = entry.getKey();
            if (generalDescriptor instanceof ParameterDescriptor<?>) {
                /*
                 * Writes value type.
                 */
                final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) generalDescriptor;
                final Class<?> valueClass = descriptor.getValueClass();
                table.append(getFormat(Class.class).format(valueClass, buffer, dummyFP).toString());
                nextColumn(table);
                buffer.setLength(0);
                /*
                 * Writes the obligation (mandatory or optional).
                 */
                if (showObligation) {
                    final int minimumOccurs = descriptor.getMinimumOccurs();
                    final int maximumOccurs = descriptor.getMaximumOccurs();
                    if (maximumOccurs == 1) {
                        table.append(resources.getString(minimumOccurs == 0 ?
                                Vocabulary.Keys.Optional : Vocabulary.Keys.Mandatory));
                    } else {
                        final Format f = getFormat(Integer.class);
                        table.append(f.format(minimumOccurs, buffer, dummyFP).toString()).append(" … ");
                        buffer.setLength(0);
                        if (maximumOccurs == Integer.MAX_VALUE) {
                            table.append('∞');
                        } else {
                            table.append(f.format(maximumOccurs, buffer, dummyFP).toString());
                            buffer.setLength(0);
                        }
                    }
                    nextColumn(table);
                }
                /*
                 * Writes minimum and maximum values, together with the unit of measurement (if any).
                 */
                final String valueDomain = row.valueDomain;
                if (valueDomain != null) {
                    table.append(CharSequences.spaces(valueDomainAlignment - row.valueDomainAlignment)).append(valueDomain);
                }
                nextColumn(table);
                /*
                 * Writes the values, each on its own line, together with their unit of measurement.
                 */
                table.setCellAlignment(TableAppender.ALIGN_RIGHT);
                final int length = row.values.size();
                for (int i=0; i<length; i++) {
                    Object value = row.values.get(i);
                    if (value != null) {
                        if (i != 0) {
                            table.append(lineSeparator);
                        }
                        final Format format = getFormat(value.getClass());
                        if (format != null) {
                            value = format.format(value, buffer, dummyFP);
                        }
                        table.append(value.toString());
                        buffer.setLength(0);
                        int pad = unitWidth;
                        final String unit = (String) row.units.get(i);
                        if (unit != null) {
                            table.append(unit);
                            pad -= unit.length();
                        }
                        table.append(CharSequences.spaces(pad));
                    }
                }
            }
            table.nextLine();
            table.setCellAlignment(TableAppender.ALIGN_LEFT);
        }
        table.nextLine(horizontalBorder);
        table.flush();
        /*
         * Now formats all groups deferred to the end of this table, with recursive calls to
         * this method (recursive calls use their own TableWriter instance, so they may result
         * in a different cell layout). Most of the time, there is no such additional group.
         */
 
View Full Code Here

         * Writes the table. The header will contain one column for each codespace in the order declared
         * by the user. If the user did not specified any codespace, or if we had to write codespace not
         * on the user list, then those codespaces will be written in the order we found them.
         */
        final boolean hasColors = (colors != null);
        final TableAppender table = new TableAppender(out, columnSeparator);
        table.setMultiLinesCells(true);
        table.appendHorizontalSeparator();
        for (String codespace : columnIndices.keySet()) {
            if (codespace == null) {
                if (!hasIdentifiers) continue; // Skip empty column.
                codespace = resources.getString(Vocabulary.Keys.Identifier);
            }
            if (hasColors) {
                codespace = X364.BOLD.sequence() + codespace + X364.NORMAL.sequence();
            }
            table.append(codespace);
            nextColumn(table);
        }
        table.appendHorizontalSeparator();
        /*
         * Writes row content.
         */
        final int numColumns = columnIndices.size();
        for (final String[] row : rows) {
            for (int i=hasIdentifiers ? 0 : 1; i<numColumns; i++) {
                if (i < row.length) {
                    final String name = row[i];
                    if (name != null) {
                        table.append(name);
                    }
                }
                nextColumn(table);
            }
            table.nextLine();
        }
        table.appendHorizontalSeparator();
        table.flush();
    }
View Full Code Here

        String separator = columnSeparator;
        switch (borderWidth) {
            case 1: horizontalLine = '─'; separator += "│ "; break;
            case 2: horizontalLine = '═'; separator += "║ "; break;
        }
        final TableAppender table = new TableAppender(toAppendTo, separator);
        final Vocabulary resources = Vocabulary.getResources(headerLocale);
        /*
         * If there is a header for at least one statistics, write the full headers row.
         */
        if (horizontalLine != 0) {
            table.nextLine(horizontalLine);
        }
        if (showHeaders) {
            table.nextColumn();
            for (final String header : headers) {
                if (header != null) {
                    table.append(header);
                    table.setCellAlignment(TableAppender.ALIGN_CENTER);
                }
                table.nextColumn();
            }
            table.append(lineSeparator);
            if (horizontalLine != 0) {
                table.nextLine(horizontalLine);
            }
        }
        /*
         * Initialize the NumberFormat for formatting integers without scientific notation.
         * This is necessary since the format may have been modified by a previous execution
         * of this method.
         */
        final Format format = getFormat(Double.class);
        if (format instanceof DecimalFormat) {
            ((DecimalFormat) format).applyPattern("#0"); // Also disable scientific notation.
        } else if (format instanceof NumberFormat) {
            setFractionDigits((NumberFormat) format, 0);
        }
        /*
         * Iterates over the rows to format (count, minimum, maximum, mean, RMS, standard deviation),
         * then iterate over columns (statistics on sample values, on the first derivatives, etc.)
         * The NumberFormat configuration may be different for each column, but we can skip many
         * reconfiguration in the common case where there is only one column.
         */
        boolean needsConfigure = false;
        for (int i=0; i<KEYS.length; i++) {
            switch (i) {
                case 1: if (!showNaNCount) continue; else break;
                // Case 0 and 1 use the above configuration for integers.
                // Case 2 unconditionally needs a reconfiguration for floating point values.
                // Case 3 and others need reconfiguration only if there is more than one column.
                case 2: needsConfigure = true; break;
                case 3: needsConfigure = (stats[0].differences() != null); break;
            }
            table.setCellAlignment(TableAppender.ALIGN_LEFT);
            table.append(resources.getString(KEYS[i])).append(':');
            for (final Statistics s : stats) {
                final Number value;
                switch (i) {
                    case 0:  value = s.count();    break;
                    case 1:  value = s.countNaN(); break;
                    case 2:  value = s.minimum()break;
                    case 3:  value = s.maximum()break;
                    case 4:  value = s.mean();     break;
                    case 5:  value = s.rms();      break;
                    case 6:  value = s.standardDeviation(allPopulation); break;
                    default: throw new AssertionError(i);
                }
                if (needsConfigure) {
                    configure(format, s);
                }
                table.append(beforeFill);
                table.nextColumn(fillCharacter);
                table.append(format.format(value));
                table.setCellAlignment(TableAppender.ALIGN_RIGHT);
            }
            table.append(lineSeparator);
        }
        if (horizontalLine != 0) {
            table.nextLine(horizontalLine);
        }
        /*
         * TableAppender needs to be explicitly flushed in order to format the values.
         */
        table.flush();
    }
View Full Code Here

            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Commands));
            out.println(':');
        }
        try {
            final TableAppender table = new TableAppender(out, "  ");
            for (final String command : commandNames) {
                if (showHeader) {
                    table.append("  ");
                }
                table.append(command);
                if (!showHeader) {
                    table.append(':');
                }
                table.nextColumn();
                table.append(commands.getString(command));
                table.nextLine();
            }
            table.flush();
            out.println();
            out.print(vocabulary.getString(Vocabulary.Keys.Options));
            out.println(':');
            for (final Option option : validOptions) {
                final String name = option.name().toLowerCase(Locale.US);
                table.append("  ").append(Option.PREFIX).append(name);
                table.nextColumn();
                table.append(options.getString(name));
                table.nextLine();
            }
            table.flush();
        } catch (IOException e) {
            throw new AssertionError(e); // Should never happen, because we are writing to a PrintWriter.
        }
    }
View Full Code Here

         * @param out           Where to format the tree.
         * @param column        The columns of the tree table to format.
         * @param parentObjects An initially empty {@link IdentityHashMap}.
         */
        Writer(final Appendable out, final TableColumn<?>[] columns, final Map<Object,Object> parentObjects) {
            super(columns.length >= 2 ? new TableAppender(out, "") : out);
            this.columns = columns;
            this.formats = getFormats(columns, false);
            this.values  = new Object[columns.length];
            this.isLast  = new boolean[8];
            this.parentObjects = parentObjects;
View Full Code Here

TOP

Related Classes of org.apache.sis.io.TableAppender

Copyright © 2018 www.massapicom. 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.