Example usage for java.util Formatter toString

List of usage examples for java.util Formatter toString

Introduction

In this page you can find the example usage for java.util Formatter toString.

Prototype

public String toString() 

Source Link

Document

Returns the result of invoking toString() on the destination for the output.

Usage

From source file:com.itemanalysis.psychometrics.polycor.PolychoricMaximumLikelihood.java

public String print() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    double[] rowSE = getRowThresholdStandardErrors();
    double[] colSE = getColumnThresholdStandardErrors();

    f.format("%34s", "Polychoric correlation, ML est. = ");
    f.format("%6.4f", rho);
    f.format(" (%6.4f)", variance[0][0]);
    f.format("%n");
    f.format("%41s", "Test of bivariate normality: Chisquare = ");
    f.format("%-8.4f", chiSquare);
    f.format("%6s", " df = ");
    f.format("%-6.0f", df);
    f.format("%5s", " p = ");
    f.format("%-6.4f", probChiSquare);
    f.format("%n");
    f.format("%n");
    f.format("%18s", "Row Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < rowThresholds.length; i++) {
        f.format("%6.4f", rowThresholds[i]);
        f.format("%9s", "");
        f.format("%6.4f", rowSE[i]);
        f.format("%n");
    }/*from   ww w.ja va2 s . com*/

    f.format("%n");
    f.format("%n");
    f.format("%19s", "Column Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < columnThresholds.length; i++) {
        f.format("% 6.4f", columnThresholds[i]);
        f.format("%9s", "");
        f.format("% 6.4f", colSE[i]);
        f.format("%n");
    }

    f.format("%n");
    return f.toString();

}

From source file:com.itemanalysis.psychometrics.rasch.Theta.java

public String toStringWithRawScore(String title, boolean header, boolean footer) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    if (header) {
        f.format("%-50s", title);
        f.format("%n");
        f.format("%50s", "==================================================");
        f.format("%n");
        f.format("%10s", "Sum Score");
        f.format("%2s", " ");
        f.format("%10s", "Theta");
        f.format("%2s", " ");
        f.format("%10s", "Std. Error");
        f.format("%2s", " ");
        f.format("%10s", "Frequency");
        f.format("%2s", " ");
        f.format("%n");
        f.format("%50s", "--------------------------------------------------");
        f.format("%n");
    }/*from  ww  w.j  a va  2 s. c  om*/
    f.format("%10.4f", rawScore);
    f.format("%2s", " ");
    f.format("%10.4f", theta);
    f.format("%2s", " ");
    if (rawScore == 0 || rawScore == maximumPossibleScore) {
        f.format("%10.4s", "--");
        f.format("%2s", " ");
    } else {
        f.format("%10.4f", stdError);
        f.format("%2s", " ");
    }
    f.format("%10.0f", freq);
    f.format("%n");
    if (footer) {
        f.format("%50s", "==================================================");
        f.format("%n");
    }

    return f.toString();
}

From source file:com.itemanalysis.psychometrics.irt.model.Irm4PL.java

/**
 * A string representaiton of the item parameters. Mainly used for printing and debugging.
 *
 * @return a string of item parameters./*from ww w. ja  v a2s.co  m*/
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    String name = "";
    if (getName() != null) {
        name = getName().toString();
    }
    f.format("%-18s", name);
    f.format("%2s", "");

    f.format("%-3s", "L4");
    f.format("%4s", "");

    f.format("% 4.2f", getDiscrimination());
    f.format("%1s", "");
    f.format("(%4.2f)", getDiscriminationStdError());
    f.format("%4s", "");

    f.format("% 4.2f", getDifficulty());
    f.format("%1s", "");
    f.format("(%4.2f)", getDifficultyStdError());
    f.format("%4s", "");

    f.format("% 4.2f", getGuessing());
    f.format("%1s", "");
    f.format("(%4.2f)", getGuessingStdError());
    f.format("%4s", "");

    f.format("% 4.2f", getSlipping());
    f.format("%1s", "");
    f.format("(%4.2f)", getSlippingStdError());
    f.format("%4s", "");

    return f.toString();

    //
    //
    //        StringBuilder sb = new StringBuilder();
    //        Formatter f = new Formatter(sb);
    //
    //        f.format("%10s", getName().toString());f.format("%2s", ": ");
    //        f.format("%1s", "[");
    //        f.format("% .6f", getDiscrimination()); f.format("%2s", ", ");
    //        f.format("% .6f", getDifficulty()); f.format("%2s", ", ");
    //        f.format("% .6f", getGuessing()); f.format("%2s", ", ");
    //        f.format("% .6f", getSlipping());f.format("%1s", "]");
    //        f.format("%n");
    //        f.format("%10s", "");f.format("%2s", "");
    //        f.format("%1s", "(");
    //        f.format("% .6f", getDiscriminationStdError()); f.format("%2s", ", ");
    //        f.format("% .6f", getDifficultyStdError()); f.format("%2s", ", ");
    //        f.format("% .6f", getGuessingStdError()); f.format("%2s", ", ");
    //        f.format("% .6f", getSlippingStdError());f.format("%1s", ")");
    //        return f.toString();
}

From source file:com.itemanalysis.psychometrics.irt.model.IrmGPCM.java

/**
 * Displays the item parameter values and standard errors.
 *
 * @return String representation of item parameter values and standard errors.
 *///from   ww  w.  j a va2  s  .  c om
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    String name = getName().toString();
    if (getName() != null) {
        name = getName().toString().substring(0, Math.min(18, name.length()));
    } else {
        name = "";
    }
    f.format("%-18s", name);
    f.format("%2s", "");

    f.format("%-3s", "PC1");
    f.format("%4s", "");

    f.format("% 4.2f", getDiscrimination());
    f.format("%1s", "");
    f.format("(%4.2f)", getDiscriminationStdError());
    f.format("%4s", "");

    double[] step = getStepParameters();
    double[] stepSe = getStepStdError();
    for (int k = 1; k < ncat; k++) {
        if (k > 1)
            f.format("%43s", "");
        f.format("% 2.2f", step[k]);
        f.format("%1s", "");
        f.format("(%2.2f)", stepSe[k]);
        if (k < ncatM1)
            f.format("%n");
    }

    return f.toString();
    //
    //
    //        StringBuilder sb = new StringBuilder();
    //        Formatter f = new Formatter(sb);
    //
    //        f.format("%10s", getName().toString());f.format("%2s", ": ");
    //        f.format("%1s", "[");
    //        f.format("% .6f", getDiscrimination()); f.format("%2s", ", ");
    //        for(int k=1;k<ncat;k++){
    //            f.format("% .6f", step[k]);//Do not print first step parameter because fixed to zero.
    //            if(k<ncatM1) f.format("%2s", ", ");
    //        }
    //        f.format("%1s", "]");
    //        f.format("%n");
    //        f.format("%10s", "");f.format("%2s", "");
    //        f.format("%1s", "(");
    //        f.format("% .6f", getDiscriminationStdError()); f.format("%2s", ", ");
    //        for(int k=1;k<ncat;k++){
    //            f.format("% .6f", stepStdError[k]);//Do not print first step parameter because fixed to zero.
    //            if(k<ncatM1) f.format("%2s", ", ");
    //        }
    //        f.format("%1s", ")");
    //
    //        return f.toString();

}

From source file:com.itemanalysis.psychometrics.polycor.PolychoricLogLikelihoodML.java

public String print(double[] x) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    int am1 = alpha.length - 1;
    int bm1 = beta.length - 1;

    f.format("%34s", "Polychoric correlation, ML est. = ");
    f.format("%6.4f", rho);
    f.format(" (%6.4f)", Math.sqrt(variance[0][0]));
    f.format("%n");
    f.format("%41s", "Test of bivariate normality: Chisquare = ");
    f.format("%-8.4f", chiSquare);
    f.format("%6s", " df = ");
    f.format("%-6.0f", df);
    f.format("%5s", " p = ");
    f.format("%-6.4f", probChiSquare);
    f.format("%n");
    f.format("%n");
    f.format("%18s", "Row Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < am1; i++) {
        f.format("%6.4f", x[i + 1]);
        f.format("%9s", "");
        f.format("%6.4f", Math.sqrt(variance[i + 1][i + 1]));
        f.format("%n");
    }//  w  w  w  . jav  a2 s . com

    f.format("%n");
    f.format("%n");
    f.format("%19s", "Column Thresholds");
    f.format("%n");
    f.format("%-15s", "Threshold");
    f.format("%-10s", "Std.Err.");
    f.format("%n");

    for (int i = 0; i < bm1; i++) {
        f.format("% 6.4f", x[i + 1 + am1]);
        f.format("%9s", "");
        f.format("% 6.4f", Math.sqrt(variance[i + 1 + am1][i + 1 + am1]));
        f.format("%n");
    }

    f.format("%n");
    return f.toString();

}

From source file:com.itemanalysis.psychometrics.statistics.StorelessDescriptiveStatistics.java

public String toString(String title) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%-50s", title);
    f.format("%n");
    f.format("%30s", "==============================");
    f.format("%n");
    f.format("%-10s", "Statistic");
    f.format("%5s", "");
    f.format("%10s", "Value");
    f.format("%5s", "");
    f.format("%n");
    f.format("%30s", "------------------------------");
    f.format("%n");
    f.format("%-10s", "N");
    f.format("%5s", "");
    f.format("%10.4f", (double) m.getN());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Min");
    f.format("%5s", "");
    f.format("%10.4f", min.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Max");
    f.format("%5s", "");
    f.format("%10.4f", max.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Mean");
    f.format("%5s", "");
    f.format("%10.4f", m.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "St. Dev.");
    f.format("%5s", "");
    f.format("%10.4f", sd.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Skewness");
    f.format("%5s", "");
    f.format("%10.4f", skew.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Kurtosis");
    f.format("%5s", "");
    f.format("%10.4f", kurt.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%30s", "==============================");
    f.format("%n");
    return f.toString();
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalMixtureModel.java

public String printResults() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%20s", "Number of groups = ");
    f.format("%-4d", groups);
    f.format("%n");
    f.format("%20s", "Free parameters = ");
    f.format("%-4d", freeParameters());
    f.format("%n");
    f.format("%20s", "Sample size = ");
    f.format("%-10d", sampleSize);
    f.format("%n");
    f.format("%20s", "Log-likelihood = ");
    f.format("%-12.4f", this.loglikelihood());
    f.format("%n");
    f.format("%20s", "Converged = ");
    f.format("%-5s", converged);
    f.format("%n");
    f.format("%20s", "Status = ");
    f.format("%-35s", statusMessage);
    f.format("%n");
    f.format("%n");
    f.format(fit.printFitStatistics());//from w  w  w  .j  a v  a  2s  .  co  m
    f.format("%n");

    MvNormalComponentDistribution mvnDist = null;
    for (int g = 0; g < groups; g++) {
        f.format("%n");
        mvnDist = (MvNormalComponentDistribution) compDistribution[g];
        f.format("%-12s", "Group " + (g + 1) + " ");
        f.format("%n");
        f.format("%12s", "Mix Prop: ");
        f.format(mvnDist.printMixingProportion());
        f.format("%12s", "Mean: ");
        f.format(mvnDist.printMean());
        f.format("%12s", "Covar: ");
        f.format("%n");
        f.format(mvnDist.printCovariance());
    }
    return f.toString();
}

From source file:org.sipfoundry.sipxconfig.admin.commserver.DnsGeneratorImpl.java

/**
 * Prepares parameters and call XML/RPC method to generate DNS zone file.
 *
 * Extra locationToSkip parameter allows generating zone file without location that is being
 * deleted. We get delete event when location manager still has a list of all locations.
 *
 * @param locationToSkip usually location that is being deleted
 *//*from   w  w w.  j  a v  a 2 s  .c om*/
public void generateWithout(Location locationToSkip) {
    Location primaryLocation = m_locationsManager.getPrimaryLocation();

    if (primaryLocation == null) {
        LOG.error("No primary location defined. OK in test environment");
        return;
    }

    Formatter cmd = new Formatter();
    SipxService proxyService = m_sipxServiceManager.getServiceByBeanId(SipxProxyService.BEAN_ID);
    List<Location> locations = new ArrayList<Location>();
    for (Location location : m_locationsManager.getLocations()) {
        if (!location.equals(locationToSkip)) {
            locations.add(location);
        }
    }

    // First list the servers that have a SIP Router role
    for (Location location : locations) {
        if (location.isServiceInstalled(proxyService)) {
            cmd.format("%s/%s ", location.getFqdn(), location.getAddress());
        }
    }

    // Next list the servers that do not have a SIP Router role
    for (Location location : locations) {
        if (!location.isServiceInstalled(proxyService)) {
            cmd.format("-o %s/%s ", location.getFqdn(), location.getAddress());
        }
    }

    // Next add the server that is running the Instant Messaging Role
    SipxService instantMessagingService = m_sipxServiceManager.getServiceByBeanId("sipxOpenfireService");
    for (Location location : locations) {
        if (location.isServiceInstalled(instantMessagingService)) {
            cmd.format("-x %s/%s ", location.getFqdn(), location.getAddress());
        }
    }

    String portTCP = ((SipxProxyService) proxyService).getSipTCPPort();
    String portUDP = ((SipxProxyService) proxyService).getSipUDPPort();

    cmd.format("--zone --serial %s --provide-dns --port-TCP %s --port-UDP %s", m_serial++, portTCP, portUDP);
    try {
        ZoneAdminApi api = m_zoneAdminApiProvider.getApi(primaryLocation.getProcessMonitorUrl());
        api.generateDns(primaryLocation.getFqdn(), cmd.toString());
    } catch (XmlRpcRemoteException e) {
        // do not re-throw - this is called during saving/deleting locations
        LOG.error("Cannot reconfigure DNS", e);
    }
}

From source file:com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection.java

void formRequest(Formatter formatter, String filtersStr) {
    StringBuilder fmtString = new StringBuilder(1024);

    fmtString.append("/stream?").append(DatabusHttpHeaders.PROTOCOL_VERSION_PARAM).append("=")
            .append(getProtocolVersion()).append((getProtocolVersion() >= 3) ? "&subs" : "&sources")
            .append("=%s&streamFromLatestScn=%s&")
            .append((getProtocolVersion() >= 3) ? "checkPointMult" : "checkPoint")
            .append("=%s&output=binary&size=%d");
    if (filtersStr != null) {
        fmtString.append("&filters=").append(filtersStr);
    }/*from   www.  j  a v a 2s  .c  om*/
    if (_maxEventVersion > 0) {
        fmtString.append("&").append(DatabusHttpHeaders.MAX_EVENT_VERSION).append("=").append(_maxEventVersion);
    }

    formatter
            .format(fmtString.toString(), _sourcesSubsList, Boolean.toString(_enableReadFromLatestSCN),
                    (getProtocolVersion() >= 3) ? _checkpoint.toString()
                            : _checkpoint.getCheckpoint(PhysicalPartition.ANY_PHYSICAL_PARTITION),
                    _freeBufferSpace);

    if (LOG.isDebugEnabled()) {
        LOG.debug("request string for stream (protocolVersion=" + getProtocolVersion() + "):"
                + formatter.toString());
    }
}

From source file:org.mule.modules.box.BoxConnector.java

private String hash(InputStream content) {
    byte[] bytes = null;
    try {//from w  w  w.j a v a2  s .co m
        bytes = IOUtils.toByteArray(content);
    } catch (IOException e) {
        throw new RuntimeException("Error generating sha1 for content", e);
    }

    Formatter formatter = new Formatter();
    try {
        for (byte b : bytes) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    } finally {
        formatter.close();
    }
}