Example usage for java.io PrintStream printf

List of usage examples for java.io PrintStream printf

Introduction

In this page you can find the example usage for java.io PrintStream printf.

Prototype

public PrintStream printf(String format, Object... args) 

Source Link

Document

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

Usage

From source file:edu.illinois.cs.cogcomp.lbjava.classify.TestReal.java

/**
 * Write to PrintStream, with statistical information
 * /*w w  w  . j a v  a  2 s  .c  o  m*/
 * @param out printstream
 * @param processed number of testing examples
 */
public void printPerformace(PrintStream out, int processed) {
    out.println("Statistical Metrics");

    out.printf("Root Mean Squared Error: %f\n", getRootMeanSquaredError(processed));
    out.printf("Mean Squared Error: %f\n", getMeanSquaredError(processed));
    out.printf("Mean Absolute Error: %f\n", getMeanAbsoluteError(processed));
    out.printf("Median Absolute Error: %f\n", getMedianAbsoluteError());
    out.printf("Explained Variance: %f\n", getExplainedVariance());
    out.printf("R2 Score: %f\n", getR2Score());
}

From source file:org.rhwlab.BHCnotused.StdGaussianWishartGaussian.java

private void printVector(PrintStream stream, RealVector v) {
    boolean first = true;
    stream.print("(");
    for (int i = 0; i < v.getDimension(); ++i) {
        if (!first) {
            stream.printf(",%d", (int) v.getEntry(i));
        } else {/*from ww w.  j  ava2s  .c  o  m*/
            stream.printf("%d", (int) v.getEntry(i));
        }
        first = false;
    }
    stream.print(")");
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.ContractsGrantsInvoiceBatchCreateDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.batch.service.ContractsGrantsInvoiceDocumentCreateService#createCGInvoiceDocumentsByAwards(java.lang.String)
 *//*from  w  w w . ja  v  a2 s  .c  o  m*/
@Override
public void createCGInvoiceDocumentsByAwards(Collection<ContractsAndGrantsBillingAward> awards,
        String errOutputFileName) {
    Map<ContractsAndGrantsBillingAward, List<String>> invalidGroup = new HashMap<ContractsAndGrantsBillingAward, List<String>>();

    List<ErrorMessage> errorMessages = getContractsGrantsInvoiceCreateDocumentService()
            .createCGInvoiceDocumentsByAwards(awards,
                    ArConstants.ContractsAndGrantsInvoiceDocumentCreationProcessType.BATCH);

    if (!CollectionUtils.isEmpty(errorMessages)) {
        File errOutPutfile = new File(errOutputFileName);
        PrintStream outputFileStream = null;

        try {
            outputFileStream = new PrintStream(errOutPutfile);
            for (ErrorMessage errorMessage : errorMessages) {
                outputFileStream.printf("%s\n",
                        MessageFormat.format(
                                getConfigurationService().getPropertyValueAsString(errorMessage.getErrorKey()),
                                (Object[]) errorMessage.getMessageParameters()));
            }
        } catch (IOException ex) {
            throw new RuntimeException(
                    "Could not write error entries for batch Contracts & Grants Invoice document creation", ex);
        } finally {
            if (outputFileStream != null) {
                outputFileStream.close();
            }
        }
    }
}

From source file:org.rhwlab.BHC.LogNode.java

@Override
public void print(PrintStream stream) {
    List<RealVector> data = new ArrayList<>();
    this.getDataAsRealVector(data);
    stream.printf("Size=%d\n", data.size());
    /*        /*from ww  w.  j a  v  a2  s . c  om*/
            for (RealVector vec : data){
    stream.print(vectorAsString(vec));
            }
            stream.println();
     */
    stream.printf("lnd=%s\n", Double.toString(lnd));
    stream.printf("lnGammaN=%s\n", Double.toString(this.lngn));
    stream.printf("ln1MinusPi=%s\n", Double.toString(lnonePi));
    stream.printf("lnPi=%s\n", Double.toString(lnPi));
    stream.printf("lnLike=%s\n", Double.toString(lnLike));
    stream.printf("lnDPM=%s\n", Double.toString(lnDPM));
    stream.printf("lnR=%s\n", Double.toString(lnR));
    stream.printf("R=%s\n", Double.toString(Math.exp(lnR)));
}

From source file:co.cask.cdap.cli.CLIMain.java

public CLIMain(final LaunchOptions options, final CLIConfig cliConfig) throws URISyntaxException, IOException {
    this.options = options;
    this.cliConfig = cliConfig;

    cliConfig.getClientConfig().setVerifySSLCert(options.isVerifySSL());
    injector = Guice.createInjector(new AbstractModule() {
        @Override/*from  ww w  .  j av  a 2 s .  co m*/
        protected void configure() {
            bind(LaunchOptions.class).toInstance(options);
            bind(CConfiguration.class).toInstance(CConfiguration.create());
            bind(PrintStream.class).toInstance(cliConfig.getOutput());
            bind(CLIConfig.class).toInstance(cliConfig);
            bind(ClientConfig.class).toInstance(cliConfig.getClientConfig());
        }
    });

    this.commands = ImmutableList.of(injector.getInstance(DefaultCommands.class),
            new CommandSet<>(ImmutableList.<Command>of(new HelpCommand(getCommandsSupplier(), cliConfig),
                    new SearchCommandsCommand(getCommandsSupplier(), cliConfig))));
    filePathResolver = injector.getInstance(FilePathResolver.class);

    Map<String, Completer> completers = injector.getInstance(DefaultCompleters.class).get();
    cli = new CLI<>(Iterables.concat(commands), completers);
    cli.setExceptionHandler(new CLIExceptionHandler<Exception>() {
        @Override
        public boolean handleException(PrintStream output, Exception e, int timesRetried) {
            if (e instanceof SSLHandshakeException) {
                output.printf("To ignore this error, set \"--%s false\" when starting the CLI\n",
                        VERIFY_SSL_OPTION.getLongOpt());
            } else if (e instanceof InvalidCommandException) {
                InvalidCommandException ex = (InvalidCommandException) e;
                output.printf("Invalid command '%s'. Enter 'help' for a list of commands\n", ex.getInput());
            } else if (e instanceof DisconnectedException || e instanceof ConnectException) {
                cli.getReader().setPrompt("cdap (DISCONNECTED)> ");
            } else {
                output.println("Error: " + e.getMessage());
            }

            if (options.isDebug()) {
                e.printStackTrace(output);
            }

            return false;
        }
    });
    cli.addCompleterSupplier(injector.getInstance(EndpointSupplier.class));
    cli.getReader().setExpandEvents(false);
    cliConfig.addHostnameChangeListener(new CLIConfig.ConnectionChangeListener() {
        @Override
        public void onConnectionChanged(CLIConnectionConfig config) {
            updateCLIPrompt(config);
        }
    });
}

From source file:gov.nasa.ensemble.dictionary.nddl.NumericResourceTranslator.java

protected void writeExtraInconParameters(PrintStream out) {
    for (ENumericResourceDef res : resourceDefs_) {
        out.printf("    float \t _%s;\n", NDDLUtil.escape(res.getName()));
    }//from   ww  w . j a v  a2 s . c  om
}

From source file:com.qubell.jenkinsci.plugins.qubell.builders.QubellBuilder.java

/**
 * Outputs a log message into buildLog//from   www  .j ava2s. com
 *
 * @param buildLog current build log
 * @param message  log message, optionally w/ formatting placeholders
 * @param args     arguments for string format of the message
 */
protected void logMessage(PrintStream buildLog, String message, Object... args) {
    buildLog.printf(LOG_MESSAGE_PREFIX.concat(message).concat("\n"), args);
}

From source file:com.hpe.application.automation.tools.run.ServiceInfo.java

private void addServiceIfDeployed(String service, ArrayList<ServiceInfo> results, boolean ignoreMissingServices,
        ICommandExecutor exec, PrintStream logger) throws CommunicatorException, CommandExecutorException {
    try {//from  w ww . j  a v  a  2  s  .c o  m
        IService svc = exec.findService(service, null);
        results.add(new ServiceInfo(svc.getId(), svc.getName()));
    } catch (CommandExecutorException e) {
        if (!ignoreMissingServices) {
            throw e;
        }
        logger.printf("Service '%s' is not deployed, ignoring%n", service);
    }
}

From source file:org.apache.whirr.cli.command.RunScriptCommand.java

@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {

    OptionSet optionSet = parser.parse(args.toArray(new String[0]));
    if (!optionSet.has(scriptOption)) {
        err.println("Please specify a script file to be executed.");
        err.println("Get more help: whirr help " + getName());
        return -1;
    }/*from   w  w  w  . j a  va2  s .c  o  m*/

    if (!(new File(optionSet.valueOf(scriptOption))).exists()) {
        err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption));
        err.println("Get more help: whirr help " + getName());
        return -2;
    }
    try {
        ClusterSpec clusterSpec = getClusterSpec(optionSet);
        String[] ids = null;
        String[] roles = null;
        if (optionSet.has(instancesOption)) {
            ids = optionSet.valueOf(instancesOption).split(",");
        }
        if (optionSet.has(rolesOption)) {
            roles = optionSet.valueOf(rolesOption).split(",");
        }
        printProviderInfo(out, err, clusterSpec, optionSet);
        return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption));

    } catch (IllegalArgumentException e) {
        printErrorAndHelpHint(err, e);
        return -3;
    }
}

From source file:org.rhwlab.variationalbayesian.SuperVoxelGaussianMixture.java

public void reportVar(PrintStream str, String varName, double[] var) {
    str.printf("%s", varName);
    for (int i = 0; i < var.length; ++i) {
        str.printf(",%f", var[i]);
    }/*from  ww w. j av a 2 s  . co  m*/
    str.println();
}