List of usage examples for java.util Formatter format
public Formatter format(String format, Object... args)
From source file:com.itemanalysis.psychometrics.factoranalysis.ExploratoryFactorAnalysis.java
/** * Formatted output of the results. It includes the factor loadings, communalities, and unqiuenesses. * * @param precision number of decimal places to report * @return string of result// w w w . j a va 2 s . c o m */ public String printOutput(int precision) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); int size = 24; String line1 = "========================="; String line2 = "-------------------------"; for (int j = 0; j < nFactors; j++) { size = size + 10; line1 += "=========="; line2 += "----------"; } size = size + 10; line1 += "=========="; line2 += "----------"; size = size + 6; line1 += "======"; line2 += "------"; f.format("%36s", title); f.format("%n"); f.format("%" + size + "s", line1); f.format("%n"); f.format("%20s", "Name"); f.format("%4s", ""); for (int j = 0; j < nFactors; j++) { f.format("%6s", "F" + (j + 1)); f.format("%4s", ""); } f.format("%6s", "H2"); f.format("%4s", ""); f.format("%6s", "U2"); f.format("%n"); f.format("%" + size + "s", line2); f.format("%n"); for (int i = 0; i < nVariables; i++) { f.format("%20s", "V" + (i + 1)); f.format("%5s", ""); for (int j = 0; j < nFactors; j++) { f.format("%6." + precision + "f", factorMethod.getFactorLoadingAt(i, j)); f.format("%4s", ""); } f.format("%6." + precision + "f", factorMethod.getCommunalityAt(i)); f.format("%4s", ""); f.format("%6." + precision + "f", factorMethod.getUniquenessAt(i)); f.format("%n"); } f.format("%" + size + "s", line1); f.format("%n"); f.format("%30s", "Value of the objective function = "); f.format("%-8.4f", fmin); f.format("%n"); f.format("%n"); f.format("%20s", ""); for (int j = 0; j < nFactors; j++) { f.format("%6s", "F" + (j + 1)); f.format("%2s", ""); } f.format("%n"); f.format("%20s", "SS loadings"); for (int j = 0; j < nFactors; j++) { f.format("%6." + precision + "f", factorMethod.getSumsOfSquaresAt(j)); f.format("%2s", ""); } f.format("%n"); f.format("%20s", "Proportion Var"); for (int j = 0; j < nFactors; j++) { f.format("%6." + precision + "f", factorMethod.getProportionOfVarianceAt(j)); f.format("%2s", ""); } f.format("%n"); f.format("%20s", "Proportion Explained"); for (int j = 0; j < nFactors; j++) { f.format("%6." + precision + "f", factorMethod.getProportionOfExplainedVarianceAt(j)); f.format("%2s", ""); } f.format("%n"); return f.toString(); }
From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverterSWAN.java
/** * writes the definition of mesh file for SWAN into the SWAN-Kalypso controlFile (INPUT) *///from w w w. j av a 2s . c o m private void formateMesh(final Formatter formatter) { // format calculation grid // TODO: this settings can be also changed by user formatter.format("CGRID UNSTRUCTURED CIRCLE 36 0.0521 1. 31\n" + //$NON-NLS-1$ "READGRID UNSTRUCTURED triangle '%s'\n" + //$NON-NLS-1$ "$\n", //$NON-NLS-1$ ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE); formatter.format("$internal shift in X:%f, internal shift in Y:%f\n$\n", m_doubleShiftX, m_doubleShiftY); //$NON-NLS-1$ }
From source file:org.kalypso.kalypsomodel1d2d.conv.SWANAdditionalDataConverter.java
private void writeWLSeriesFile(final Date pDate, final FileObject modelWLFileSerie) { Formatter lFormatterWL = null; try {//from w ww. ja v a2 s. com final List<INodeResult> lListActResults = m_resultsSimpleHandler.getResultsForDate(pDate); lFormatterWL = new Formatter(modelWLFileSerie.getContent().getOutputStream(), Charset.defaultCharset().name(), Locale.US); if (lListActResults == null) { return; } for (final INodeResult lResultAct : lListActResults) { if (lResultAct.isWet()) { lFormatterWL.format("%.3f\n", lResultAct.getWaterlevel()); //$NON-NLS-1$ } else { lFormatterWL.format("%s\n", ISimulation1D2DConstants.SIM_SWAN_EXCLUSION_NUMBER); //$NON-NLS-1$ } } FormatterUtils.checkIoException(lFormatterWL); } catch (final Exception e) { e.printStackTrace(); } finally { if (lFormatterWL != null) { // REMARK: do not check io-exception here, else other exception would be hidden by this on lFormatterWL.close(); } } }
From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverterSWAN.java
/** * writes the operations specification block for current simulation into the SWAN-Kalypso controlFile (INPUT) *///from w w w . j a va2 s . co m private void formateSimulationOperationsSpec(final Formatter formatter) { final String lOperationSpec = m_controlModel.getAdditionalSimParSWAN(); if (lOperationSpec != null) { formatter.format("$\n" + //$NON-NLS-1$ "%s\n", //$NON-NLS-1$ lOperationSpec); //$NON-NLS-1$ } // TODO: what calculations do we exactly need, what can be default? // setup the operations // constant else { formatter.format("$\n" + //$NON-NLS-1$ "GEN3 KOMEN\n" + //$NON-NLS-1$ "BREAKING\n" + //$NON-NLS-1$ "FRICTION\n" + //$NON-NLS-1$ "TRIAD\n" + //$NON-NLS-1$ "$\n"); //$NON-NLS-1$ } }
From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverterSWAN.java
/** * writes the wind data into the SWAN-Kalypso controlFile (INPUT) *//*from w w w.j a va2s . co m*/ private void formateWindData(final Formatter formatter) { // format the wind try { if (m_controlModel.isConstantWindSWAN()) { formatter.format("WIND %s\n$\n", //$NON-NLS-1$ m_controlModel.getConstantWindParSWAN()); } else { if (m_gridDescriptor == null) return; final String lStrCRS = m_gridDescriptor.getCoordinateSystem(); final String lStrStartTimeWind = SWANDataConverterHelper .getTimeStringFormatedForSWANInput(m_listWritenDatesWind.get(0)); final String lStrEndTimeWind = SWANDataConverterHelper.getTimeStringFormatedForSWANInput( m_listWritenDatesWind.get(m_listWritenDatesWind.size() - 1)); if (m_listWritenDatesWind.size() == 1) { formatter.format("INPGRID WIND REG %d %d 0 %d %d %.1f %.1f %s %s\n", //$NON-NLS-1$ ((Double) (m_gridDescriptor.getOrigin(lStrCRS).getX() - m_doubleShiftX)).intValue(), ((Double) (m_gridDescriptor.getOrigin(lStrCRS).getY() - m_doubleShiftY)).intValue(), m_gridDescriptor.getNumColumns() - 1, m_gridDescriptor.getNumRows() - 1, Math.abs(m_gridDescriptor.getOffsetX(lStrCRS)), Math.abs(m_gridDescriptor.getOffsetY(lStrCRS)), m_strStationary, lStrStartTimeWind); } else { final String lStrTimeStepLen = "" //$NON-NLS-1$ + (m_listWritenDatesWind.get(1).getTime() - m_listWritenDatesWind.get(0).getTime()) / m_intMilisecInMinute; formatter.format("INPGRID WIND REG %d %d 0 %d %d %.1f %.1f %s %s %s %s %s\n", //$NON-NLS-1$ ((Double) (m_gridDescriptor.getOrigin(lStrCRS).getX() - m_doubleShiftX)).intValue(), ((Double) (m_gridDescriptor.getOrigin(lStrCRS).getY() - m_doubleShiftY)).intValue(), m_gridDescriptor.getNumColumns() - 1, m_gridDescriptor.getNumRows() - 1, Math.abs(m_gridDescriptor.getOffsetX(lStrCRS)), Math.abs(m_gridDescriptor.getOffsetY(lStrCRS)), m_strStationary, lStrStartTimeWind, lStrTimeStepLen, m_strStepLengthUnit, lStrEndTimeWind); } formatter.format("READINP WIND 1. SERIES '%s' 3 0 FREE\n$\n", //$NON-NLS-1$ ISimulation1D2DConstants.SIM_SWAN_WIND_FILE + ISimulation1D2DConstants.SIM_SWAN_DATA_FILE_EXT); } } catch (final Exception e) { e.printStackTrace(); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getDateString(Calendar val) { if (val == null) { return ("null"); } else {/*from w w w .j a va 2s . com*/ StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w . java 2 s . com StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else {//w ww . j a v a2 s.com StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getQuotedTimestampString(Calendar val) { if (val == null) { return ("null"); } else {//from w w w . j av a2 s . co m StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public static String getTZDateString(Calendar val) { if (val == null) { return ("null"); } else {// w w w . ja va2 s . com Calendar cal; if (val.getTimeZone().equals(getServerTimeZone())) { cal = val; } else { cal = new GregorianCalendar(getServerTimeZone()); cal.setTimeInMillis(val.getTimeInMillis()); } StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", cal.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH)); buff.append("T"); fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", cal.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }