Example usage for java.util Formatter close

List of usage examples for java.util Formatter close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes this formatter.

Usage

From source file:org.wso2.extension.siddhi.execution.var.backtest.BacktestIncrementalTest.java

private void runViolationTest() {
    Formatter formatter = null;
    try {//from w  w w . j a v  a 2  s  . c  o m
        formatter = new Formatter(new File(METHOD + "-" + DATA_SET + "-" + VAR_CI + ".csv"));
        formatter.format("%s,%s%n", "VaR", "Loss");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    DescriptiveStatistics lossStat = new DescriptiveStatistics(
            lossList.stream().mapToDouble(Double::doubleValue).toArray());
    DescriptiveStatistics varStat = new DescriptiveStatistics(
            varList.stream().mapToDouble(Double::doubleValue).toArray());
    DescriptiveStatistics violationStat = new DescriptiveStatistics();
    int failCount = 0;
    int numberOfData = varList.size();
    for (int i = 0; i < numberOfData - 1; i++) {
        formatter.format("%.3f,%.3f%n", varList.get(i), lossList.get(i + 1));
        if (lossList.get(i + 1) < varList.get(i)) {
            violationStat.addValue(varList.get(i));
            failCount++;
        }
    }
    formatter.close();
    System.out.println("Number of data : " + numberOfData);
    System.out.printf("Loss Mean : %.2f\n", lossStat.getMean());
    System.out.printf("Var Mean : %.2f\n", varStat.getMean());
    System.out.printf("Number of violations : %d\n", failCount);
    System.out.printf("Mean Violation : %.2f\n", violationStat.getMean());
    System.out.printf("Violation Rate : %.2f%%\n", ((double) failCount) / (numberOfData - 1) * 100);
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static String getDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from  w w w  .j a  v a2 s  . c o m*/
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        fmt.close();
        return (buff.toString());
    }
}

From source file:com.android.ddmuilib.net.NetworkPanel.java

/**
 * Find a {@link TrackedItem} that matches the requested UID and tag, or
 * create one if none exists.//w  w w. j a  va2 s. com
 */
public TrackedItem findOrCreateTrackedItem(int uid, int tag) {
    // try searching for existing item
    for (TrackedItem item : mTrackedItems) {
        if (item.uid == uid && item.tag == tag) {
            return item;
        }
    }

    // nothing found; create new item
    final TrackedItem item = new TrackedItem(uid, tag);
    if (item.isTotal()) {
        item.color = TOTAL_COLOR;
        item.label = "Total";
    } else {
        final int size = mTrackedItems.size();
        item.color = nextSeriesColor(size);
        Formatter formatter = new Formatter();
        item.label = "0x" + formatter.format("%08x", tag);
        formatter.close();
    }

    // create color chip to display as legend in table
    item.colorImage = new Image(mDisplay, 20, 20);
    final GC gc = new GC(item.colorImage);
    gc.setBackground(new org.eclipse.swt.graphics.Color(mDisplay, item.color.getRed(), item.color.getGreen(),
            item.color.getBlue()));
    gc.fillRectangle(item.colorImage.getBounds());
    gc.dispose();

    mTrackedItems.add(item);
    return item;
}

From source file:edu.ku.brc.util.WebStoreAttachmentMgr.java

/**
 * @param hash//from   w ww  .  jav a 2  s .c  o  m
 * @return
 */
private String byteArray2Hex(byte[] hash) {
    Formatter formatter = new Formatter();
    for (byte b : hash) {
        formatter.format("%02x", b);
    }
    String s = formatter.toString();
    formatter.close();
    return s;
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//ww  w .j  a  va 2  s.c o m
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*ww w.j a v  a 2 s . com*/
        StringBuffer buff = new StringBuffer();
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//from ww  w . j a  va 2  s. c o m
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.MINUTE));
        buff.append(".");
        fmt.format("%1$02d", db.get(Calendar.SECOND));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWSchema.java

public static String getQuotedDateString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/* w  w  w  . ja  va 2s . c  om*/
        StringBuffer buff = new StringBuffer("'");
        Formatter fmt = new Formatter(buff);
        Calendar db = CFLibDbUtil.getDbServerCalendar(val);
        fmt.format("%1$04d", db.get(Calendar.YEAR));
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.MONTH) + 1);
        buff.append("-");
        fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH));
        buff.append("'");
        fmt.close();
        return (buff.toString());
    }
}

From source file:org.apache.bookkeeper.bookie.BookieShell.java

static String bytes2Hex(byte[] data) {
    StringBuilder sb = new StringBuilder(data.length * 2);
    Formatter formatter = new Formatter(sb);
    for (byte b : data) {
        formatter.format("%02x", b);
    }//from  w ww  .  j  a  va 2s.  c  o m
    formatter.close();
    return sb.toString();
}

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

private void writeWLSeriesFile(final Date pDate, final FileObject modelWLFileSerie) {
    Formatter lFormatterWL = null;
    try {//ww  w  . j  a v  a2 s  .  c o  m
        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();
        }
    }
}