Example usage for java.util Formatter format

List of usage examples for java.util Formatter format

Introduction

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

Prototype

public Formatter format(String format, Object... args) 

Source Link

Document

Writes a formatted string to this object's destination using the specified format string and arguments.

Usage

From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverterSWAN.java

/**
 * writes the Boundary Conditions based on continuity Lines Data Block and on this connected boundary conditions of
 * waves into the SWAN-Kalypso controlFile (INPUT)
 *///w  ww . j a  v  a  2s  .  c o m
private void formateInitialBoundaries(final Formatter formatter) throws IOException {
    final Set<IFELine> continuityLines = m_mapContiLinesWithConditions.keySet();

    final Integer lIntBoundaryMethod = m_controlModel.getAlgBoundarySWAN();
    String lStrBoundaryMethod = BOUNDARY_JSWAP;
    switch (lIntBoundaryMethod) {
    case 0:
        lStrBoundaryMethod = BOUNDARY_JSWAP;
        break;
    case 1:
        lStrBoundaryMethod = BOUNDARY_PM;
        break;
    case 2:
        lStrBoundaryMethod = BOUNDARY_GAUSS;
        break;
    case 3:
        lStrBoundaryMethod = BOUNDARY_BIN;
    default:
        lStrBoundaryMethod = BOUNDARY_JSWAP;
        break;
    }

    for (final IFELine line : continuityLines) {
        final int lIntContiLineId = m_mapContiLinesWithConditions.get(line);
        // format the boundaries
        formatter.format("BOUN SHAPE %s PEAK DSPR POWER\n" //$NON-NLS-1$
                , lStrBoundaryMethod);
        formatBoundConds(formatter, lIntContiLineId);
    }
}

From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java

/**
 * This method is for displaying person parameter estimates, standard errors, and other information.
 * It will display statistic for every examinee.
 * @return//  w w  w. ja v a 2 s. c  o m
 */
public String printPersonStats() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%12s", "Sum Score");
    f.format("%12s", "Theta");
    f.format("%12s", "Std. Error");
    f.format("%12s", "Extreme");
    f.format("%n");
    f.format("%50s", "--------------------------------------------------");
    f.format("%n");
    for (int i = 0; i < nPeople; i++) {
        f.format("%12.2f", sumScore[i]);
        f.format("%12.2f", theta[i]);
        f.format("%12.2f", thetaStdError[i]);
        if (extremePerson[i] == -1) {
            f.format("%12s", "MINIMUM");
        } else if (extremePerson[i] == 1) {
            f.format("%12s", "MAXIMUM");
        } else {
            f.format("%12s", "");
        }
        f.format("%n");
    }
    f.format("%50s", "--------------------------------------------------");
    f.format("%n");
    return f.toString();
}

From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java

/**
 * Joint maximum likelihood estimation is iterative. An iteration history is saved. The history includes
 * the largest change in logits and the log-likelihood at each iteration. This method provides a string
 * representation of the iteration history.
 *
 * @return a summary of the iteration history.
 *///from  www. jav a 2 s . co m
public String printIterationHistory() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    int index = 0;

    f.format("%10s", "Iteration");
    f.format("%5s", "");
    f.format("%17s", "Delta");
    f.format("%5s", "");
    f.format("%20s", "Log-likelihood");
    f.format("%n");
    f.format("%62s", "--------------------------------------------------------------");
    f.format("%n");
    for (IterationRecord ir : iterationHistory) {
        f.format("%10s", ++index);
        f.format("%5s", "");
        f.format("%42s", ir.toString());
        f.format("%n");
    }
    f.format("%62s", "--------------------------------------------------------------");
    f.format("%n");
    return f.toString();
}

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

/**
 * Publishes global iteration information in the jmetrik log.
 *//*w  ww .ja  va2s. c  o  m*/
public String printIterationSummary() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    int iter = 1;

    f.format("%-35s", "RASCH ANALYSIS ITERATION SUMMARY");
    f.format("%n");
    f.format("%10s", "Iteration");
    f.format("%5s", "");
    f.format("%10s", "Max Change");
    f.format("%n");
    f.format("%-35s", "===================================");
    f.format("%n");

    for (Double d : iterationDelta) {
        f.format("%10d", iter);
        f.format("%5s", "");
        f.format("%10.6f", d);
        f.format("%n");
        iter++;
    }

    if (extremeIterationDelta.size() > 0) {
        iter = 0;

        f.format("%n");
        f.format("%n");
        f.format("%-35s", "EXTREME ITEM/PERSON ITERATION SUMMARY");
        f.format("%n");
        f.format("%10s", "Iteration");
        f.format("%5s", "");
        f.format("%10s", "Max Change");
        f.format("%n");
        f.format("%-35s", "===================================");
        f.format("%n");

        for (Double d : extremeIterationDelta) {
            f.format("%10d", iter);
            f.format("%5s", "");
            f.format("%10.6f", d);
            f.format("%n");
            iter++;
        }
    }

    return f.toString();
}

From source file:com.bluexml.xforms.generator.FormGeneratorsManager.java

/**
 * Provides a unique id for the set of search operators defined in a search field. If an
 * equivalent set already exists, its id is returned. Otherwise, the new set is registered with
 * a new id that's returned.//from  w  ww  . ja v a  2s.c o  m
 * 
 * @param searchField
 * @return the id, a zero padded sequence number starting from 1
 */
public String getSearchOperatorsListId(SearchField searchField) {
    String resultId;

    // get list of operators and default operator
    SearchFieldDataBean sfDataBean = getSearchFieldDataBean(searchField);

    // test whether the list already exists
    resultId = testOperatorList(sfDataBean.listOp);

    // if so, return the id
    if (resultId != null) {
        return resultId;
    }
    // if not, register the list and return its id
    Formatter formatter = new Formatter();
    resultId = formatter.format("%06d", operatorsEnumsMap.keySet().size() + 1).toString();
    operatorsEnumsMap.put(resultId, sfDataBean.listOp);
    return resultId;
}

From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.java

private void formatBC(final Formatter formatter, final String uRVal, final int nitn)
        throws CoreException, IOException {
    if (uRVal == null || uRVal == "") { //$NON-NLS-1$
        final String msg = Messages.getString("org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.6");//$NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, msg));
    }//w w w  .  j  a  va  2 s.com
    final List<Integer> lListFactors = getListParsedRelaxationFactor(uRVal, nitn);
    // final int buffVal = 10 - (int) (uRVal * 10);
    for (int j = 0; j < nitn; j++) {
        if (j % 9 == 0) {
            formatter.format("%nBC%6s", " "); //$NON-NLS-1$ //$NON-NLS-2$
        }
        formatter.format("%5d010", lListFactors.get(j)); //$NON-NLS-1$
    }
    formatter.format("%n"); //$NON-NLS-1$

    FormatterUtils.checkIoException(formatter);
}

From source file:com.itemanalysis.psychometrics.irt.estimation.JointMaximumLikelihoodEstimation.java

/**
 * This method is for displaying item parameter estimates, standard errors, and other information.
 *
 * @return/* w w w.  j  av  a 2 s . c o  m*/
 */
public String printBasicItemStats(String title) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    int maxCat = 0;
    for (int j = 0; j < nItems; j++) {
        maxCat = Math.max(irm[j].getNcat(), maxCat);
    }

    f.format("%40s", title);
    f.format("%n");

    String line1 = "========================================================";
    int lineLength = 44;
    if (maxCat > 2) {
        for (int k = 0; k < maxCat - 1; k++) {
            line1 += "============";
            lineLength += 12;
        }
    }
    f.format("%" + lineLength + "s", line1);
    f.format("%n");

    f.format("%20s", "Name");
    f.format("%12s", "Difficulty");
    f.format("%12s", "Std. Error");
    if (maxCat > 2) {
        for (int k = 0; k < maxCat - 1; k++) {
            f.format("%12s", "step" + (k + 1));
        }
    }

    f.format("%12s", "Extreme");
    f.format("%n");

    String line = "--------------------------------------------------------";
    lineLength = 44;
    if (maxCat > 2) {
        for (int k = 0; k < maxCat - 1; k++) {
            line += "------------";
            lineLength += 12;
        }
    }

    f.format("%" + lineLength + "s", line);
    f.format("%n");
    for (int j = 0; j < nItems; j++) {
        f.format("%20s", irm[j].getName());

        if (droppedStatus[j] == 0) {
            f.format("%12.2f", irm[j].getDifficulty());
            f.format("%12.2f", irm[j].getDifficultyStdError());
            if (irm[j].getNcat() > 2) {
                double[] t = irm[j].getThresholdParameters();
                for (int k = 0; k < t.length; k++) {
                    f.format("%12.2f", t[k]);
                }
            }

            if (itemSummary[j].isExtremeMaximum()) {
                f.format("%12s", "MAXIMUM");
            } else if (itemSummary[j].isExtremeMinimum()) {
                f.format("%12s", "MINIMUM");
            } else {
                f.format("%12s", "");
            }
            f.format("%n");

            if (irm[j].getNcat() > 2) {
                String id = irm[j].getGroupId();
                double[] tse = rsg.get(id).getThresholdStandardError();
                f.format("%44s", "");
                for (int k = 0; k < tse.length; k++) {
                    f.format("%12.2f", tse[k]);
                }
                f.format("%n");
            }
        } else {
            f.format("%12s", "DROPPED");
            f.format("%n");
        }

    }
    f.format("%" + lineLength + "s", line1);
    f.format("%n");
    return f.toString();
}

From source file:org.getobjects.appserver.core.WOApplication.java

/**
 * This method is called when 'info' is enabled in the profile logger.
 *
 * @param _rq   - the WORequest//w  ww. j  a  v a 2s.c o m
 * @param _rqId - the numeric ID of the request (counter)
 * @param _r    - the generated WOResponse
 */
protected void logRequestEnd(WORequest _rq, int _rqId, WOResponse _r) {
    final StringBuilder sb = new StringBuilder(512);
    sb.append("WOApp[");
    sb.append(_rqId);
    sb.append("] ");
    if (_r != null) {
        String s;
        final int status = _r.status();
        sb.append(status);

        if ((s = _r.headerForKey("content-length")) != null) {
            sb.append(" ");
            sb.append(s);
        } else if (!_r.isStreaming()) {
            int len = _r.content().length;
            sb.append(" len=");
            sb.append(len);
        }

        if ((s = _r.headerForKey("content-type")) != null) {
            sb.append(' ');
            sb.append(s);
        }

        final Collection<WOCookie> cookies = _r.cookies();
        if (cookies != null && cookies.size() > 0) {
            sb.append(" C[");
            WOCookie.addCookieInfo(cookies, sb);
            sb.append("]");
        }

        if (status == 302 && (s = _r.headerForKey("location")) != null) {
            sb.append(" 302[");
            sb.append(s);
            sb.append(']');
        }
    } else
        sb.append("no response");

    if (_rq != null) {
        final double duration = _rq.requestDurationSinceStart();
        if (duration > 0.0) {
            // TBD: are there more efficient ways to do this? (apparently there is
            //      no way to cache the parsed format?)
            Formatter formatter = new Formatter(sb, Locale.US);
            formatter.format(" (%.3fs)", duration);
            formatter.close(); // didn't know that ;-)
        }
    }

    profile.info(sb.toString());
}

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

private String hash(InputStream content) {
    byte[] bytes = null;
    try {// w  w w  .j  a v a2  s. c o 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();
    }
}

From source file:com.itemanalysis.psychometrics.cmh.CochranMantelHaenszel.java

@Override
public String toString() {
    StringBuilder buffer = new StringBuilder();
    Formatter f = new Formatter(buffer);
    ChiSquaredDistribution chiSquare = new ChiSquaredDistribution(1.0);

    double cmh = cochranMantelHaenszel();
    Double pvalue = 1.0;//from w w w.j a  v  a  2 s .co m
    pvalue = 1.0 - chiSquare.cumulativeProbability(cmh);

    double commonOddsRatio = 0.0;
    double[] tempConfInt = { 0.0, 0.0 };
    double[] confInt = { 0.0, 0.0 };
    double smd = 0.0;
    double effectSize = 0.0;
    String etsClass = "";

    if (itemVariable.getType().getItemType() == ItemType.BINARY_ITEM) {
        commonOddsRatio = commonOddsRatio();
        tempConfInt = commonOddsRatioConfidenceInterval(commonOddsRatio);
        if (etsDelta) {
            effectSize = etsDelta(commonOddsRatio);
            confInt[0] = etsDelta(tempConfInt[0]);
            confInt[1] = etsDelta(tempConfInt[1]);
        } else {
            effectSize = commonOddsRatio;
            confInt[0] = tempConfInt[0];
            confInt[1] = tempConfInt[1];
        }
        etsClass = etsBinayClassification(cmh, pvalue, commonOddsRatio);
    } else if (itemVariable.getType().getItemType() == ItemType.POLYTOMOUS_ITEM) {
        smd = pF();
        tempConfInt = smdConfidenceInterval(smd);
        confInt[0] = tempConfInt[0];
        confInt[1] = tempConfInt[1];
        effectSize = pF();
        //            etsClass = etsPolytomousClassification(cmh, pvalue, effectSize);
        etsClass = smdDifClass();
    }

    f.format("%-10s", itemVariable.getName().toString());
    f.format("%2s", " ");
    //      f.format("%10s", focalCode + "/" + referenceCode);f.format("%2s", " ");
    f.format("%10.2f", cmh);
    f.format("%2s", " ");
    f.format("%7.2f", pvalue);
    f.format("%2s", " ");
    f.format("%7.0f", validSampleSize);
    f.format("%2s", " ");
    f.format("%8.2f", effectSize);
    f.format(" (%8.2f", confInt[0]);
    f.format(",%8.2f)", confInt[1]);
    f.format("%2s", " ");
    f.format("%5s", etsClass);
    f.format("%2s", " ");
    return f.toString();
}