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(Locale l, String format, Object... args) 

Source Link

Document

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

Usage

From source file:eu.stratosphere.pact.runtime.hash.HashFunctionCollisionBenchmark.java

private void printStatistics() {
    for (int level = 0; level < maxLevel; level++) {
        int bucketCountInLevel = 0;

        SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level);
        Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator();

        LOG.debug("Statistics for level: " + level);
        LOG.debug("----------------------------------------------");
        LOG.debug("");
        LOG.debug("Bucket Size |      Count");
        LOG.debug("------------------------");

        int i = 0;
        while (bucketSizeIterator.hasNext()) {
            int bucketSize = bucketSizeIterator.next();
            if (bucketSize != 0) {
                int countForBucketSize = levelMap.get(bucketSize);
                bucketCountInLevel += countForBucketSize;
                Formatter formatter = new Formatter();
                formatter.format(" %10d | %10d", bucketSize, countForBucketSize);

                if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) {
                    LOG.debug(formatter.out());
                } else if (levelMap.size() / 2 == i) {
                    LOG.debug("         .. |         ..");
                    LOG.debug(formatter.out());
                    LOG.debug("         .. |         ..");
                }//  w  ww  .  j a va 2s  .c  om
                i++;
                formatter.close();
            }
        }

        LOG.debug("");
        LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel);
        LOG.debug("Number of empty buckets in level    : " + levelMap.get(0));
        LOG.debug("Number of different bucket sizes    : " + (levelMap.size() - 1));
        LOG.debug("");
        LOG.debug("");
        LOG.debug("");
    }
}

From source file:eu.stratosphere.pact.runtime.hash.MultiLevelHashITCase.java

private void printStatistics() {
    for (int level = 0; level < maxLevel; level++) {
        int bucketCountInLevel = 0;

        SortedMap<Integer, Integer> levelMap = bucketSizesPerLevel.get(level);
        Iterator<Integer> bucketSizeIterator = levelMap.keySet().iterator();

        LOG.debug("Statistics for level: " + level);
        LOG.debug("----------------------------------------------");
        LOG.debug("");
        LOG.debug("Bucket Size |      Count");
        LOG.debug("------------------------");

        int i = 0;
        while (bucketSizeIterator.hasNext()) {
            int bucketSize = bucketSizeIterator.next();
            if (bucketSize != 0) {
                int countForBucketSize = levelMap.get(bucketSize);
                bucketCountInLevel += countForBucketSize;
                Formatter formatter = new Formatter();
                formatter.format(" %10d | %10d", bucketSize, countForBucketSize);

                if (levelMap.size() < 20 || i < 3 || i >= (levelMap.size() - 3)) {
                    LOG.debug(formatter.out());
                } else if (levelMap.size() / 2 == i) {
                    LOG.debug("         .. |         ..");
                    LOG.debug(formatter.out());
                    LOG.debug("         .. |         ..");
                }/*from w  w  w.  ja  v a  2 s  .c o m*/
                i++;
            }
        }

        LOG.debug("");
        LOG.debug("Number of non-empty buckets in level: " + bucketCountInLevel);
        LOG.debug("Number of empty buckets in level    : " + levelMap.get(0));
        LOG.debug("Number of different bucket sizes    : " + (levelMap.size() - 1));
        LOG.debug("");
        LOG.debug("");
        LOG.debug("");
    }
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.IndividualCandidacy.java

public void exportValues(final StringBuilder result) {
    Formatter formatter = new Formatter(result);

    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.candidacy"),
            getCandidacyExecutionInterval().getName());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.state"),
            getState().getLocalizedName());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.whenCreated"),
            getWhenCreated().toString("yyy-MM-dd"));
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.candidacyDate"),
            getCandidacyDate().toString());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.responsible"),
            StringUtils.isEmpty(getResponsible()) ? StringUtils.EMPTY : getResponsible());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.notes"),
            StringUtils.isEmpty(getNotes()) ? StringUtils.EMPTY : getNotes());

    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.IndividualCandidacy.observations"),
            StringUtils.isEmpty(getObservations()) ? StringUtils.EMPTY : getObservations());

    for (final Formation formation : getFormationsSet()) {
        formation.exportValues(result);/*w w w  .  j  a v  a  2  s .c  o m*/
    }

    formatter.close();
}

From source file:net.sourceforge.fenixedu.domain.candidacyProcess.secondCycle.SecondCycleIndividualCandidacy.java

@Override
public void exportValues(StringBuilder result) {
    super.exportValues(result);

    Formatter formatter = new Formatter(result);

    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.process.id"),
            getCandidacyProcess().getProcessCode());
    PrecedentDegreeInformation precedentDegreeInformation = getCandidacyProcess()
            .getPrecedentDegreeInformation();
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.previous.degree"),
            precedentDegreeInformation.getDegreeDesignation());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.conclusionDate"),
            precedentDegreeInformation.getConclusionDate());
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.institution"),
            precedentDegreeInformation.getInstitution().getName());
    formatter.format("%s: %s\n", BundleUtil.getString(Bundle.ACADEMIC, "label.conclusionGrade"),
            precedentDegreeInformation.getConclusionGrade());
    formatter.format("\n");
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.professionalStatus"),
            StringUtils.isEmpty(getProfessionalStatus()) ? StringUtils.EMPTY : getProfessionalStatus());
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.otherEducation"),
            StringUtils.isEmpty(getOtherEducation()) ? StringUtils.EMPTY : getOtherEducation());
    formatter.format("%s: %d\n",
            BundleUtil.getString(Bundle.ACADEMIC,
                    "label.SecondCycleIndividualCandidacy.professionalExperience"),
            getProfessionalExperience() != null ? getProfessionalExperience() : 0);
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.affinity"),
            getAffinity() != null ? getAffinity() : BigDecimal.ZERO);
    formatter.format("%s: %d\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.degreeNature"),
            getDegreeNature() != null ? getDegreeNature() : 0);
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.candidacyGrade"),
            getCandidacyGrade() != null ? getCandidacyGrade() : BigDecimal.ZERO);
    formatter.format("%s: %s\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.interviewGrade"),
            getInterviewGrade());/*w  ww.  j av  a  2 s .c om*/
    formatter.format("%s: %f\n",
            BundleUtil.getString(Bundle.ACADEMIC, "label.SecondCycleIndividualCandidacy.seriesCandidacyGrade"),
            getSeriesCandidacyGrade() != null ? getSeriesCandidacyGrade() : BigDecimal.ZERO);

    formatter.close();
}

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

/**
 * writes the bottom informations into the SWAN-Kalypso controlFile (INPUT)
 *///from  ww  w.  j av a2s. c  om
private void formateBottomData(final Formatter formatter) {
    // format the bottom
    formatter.format("INPGRID BOTTOM UNSTRUCTURED EXC %s\n" + //$NON-NLS-1$
            "READINP BOTTOM -1. '%s.bot' 1 0 FREE\n" + //$NON-NLS-1$
            "$\n", //$NON-NLS-1$
            ISimulation1D2DConstants.SIM_SWAN_EXCLUSION_NUMBER,
            ISimulation1D2DConstants.SIM_SWAN_TRIANGLE_FILE);

}

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

/**
 * writes the operations specification block for current simulation into the Telemac-Kalypso controlFile (INPUT)
 *//*from ww  w. j a v a2  s . co m*/
private void formateSimulationOperationsSpec(final Formatter formatter) {
    formatter.format("BOUNDARY CONDITIONS FILE          : %s%s%n", m_projectFileName,
            Gml2TelemacConv.BOUNDARY_NODES_FILE_EXTENTION);
    formatter.format("GEOMETRY FILE                     : %s%s%s%n", Gml2TelemacConv.GEO_FILE_PREFIX,
            m_projectFileName, Gml2TelemacConv.SERAFIN_FILE_EXTENTION);
    formatter.format("PREVIOUS COMPUTATION FILE         : %s%s%s%n", Gml2TelemacConv.GEO_FILE_PREFIX,
            m_projectFileName, Gml2TelemacConv.SERAFIN_FILE_EXTENTION);
    //    formatter.format( "REFERENCE FILE                    : f2d_%s.slf", m_projectName );
    formatter.format("RESULTS FILE                      : %s%s%s%n", Gml2TelemacConv.RESULT_FILE_PREFIX,
            m_projectFileName, Gml2TelemacConv.SERAFIN_FILE_EXTENTION);
    formatter.format("LIQUID BOUNDARIES FILE            : %s%s%n", m_projectFileName,
            Gml2TelemacConv.BOUNDARY_CONDITIONS_FILE_EXTENTION);

    //    String lOperationSpec = m_controlModel.getAdditionalSimParTelemac();
    //    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.efaps.esjp.accounting.util.data.ImportDetails.java

/**
 *
 *///from w  w  w . ja  va2 s  . com
protected Map<String, Instance> checkDocs(final File _file, final Type _type)
        throws IOException, EFapsException {
    final CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(_file), "UTF-8"));
    final List<String[]> entries = reader.readAll();
    reader.close();
    final Map<String, Instance> ret = new HashMap<>();
    entries.remove(0);
    String docNumber = "";
    int i = 1;
    for (final String[] row : entries) {
        i++;
        final String docNumberTmp = row[0];
        if (!docNumber.equals(docNumberTmp)) {
            docNumber = docNumberTmp;
            ImportDetails.LOG.info("Trying to read Document '{}' - Line: {}", docNumber, i);
            final String[] docSplit = docNumber.split("-");
            if (docSplit.length != 2) {
                ImportDetails.LOG.warn(
                        "Document '{}'  - Line: {} has no '-' to distinguish SerialNumber and No.", docNumber,
                        i);
            } else {
                final String serialNo = docSplit[0];
                final String docNo = docSplit[1];
                try {
                    final int serial = Integer.parseInt(serialNo.trim().replaceAll("\\D", ""));
                    final int no = Integer.parseInt(docNo.trim().replaceAll("\\D", ""));
                    final Formatter criteria = new Formatter();
                    criteria.format("%03d-%06d", serial, no);
                    ImportDetails.LOG.info("Applying Criteria: '{}'", criteria);
                    final QueryBuilder queryBldr = new QueryBuilder(_type);
                    queryBldr.addWhereAttrEqValue(CIERP.DocumentAbstract.Name, criteria.toString());
                    final InstanceQuery query = queryBldr.getQuery();
                    query.executeWithoutAccessCheck();
                    if (query.next()) {
                        ImportDetails.LOG.info("Found Document: '{}'", query.getCurrentValue());
                        ret.put(criteria.toString(), query.getCurrentValue());
                        if (query.next()) {
                            ImportDetails.LOG.error("Found duplicated Document: '{}'", query.getCurrentValue());
                        }
                    } else {
                        ImportDetails.LOG.error("No Document found for : '{}' - Line: {}", docNumber, i);
                    }
                    criteria.close();
                } catch (final NumberFormatException e) {
                    ImportDetails.LOG.error("wrong format '{}'", docNumber);
                }

            }
        }
    }

    return ret;
}

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

/**
 * writes the output specification block for current simulation into the Telemac-Kalypso controlFile (INPUT)
 * //from  w w  w  .  ja v a2 s . c  o  m
 * //HSIG === significant wave height(m), WLEN === Average wave length (m) //RTP === peak period (in s) of the
 * variance density spectrum (relative frequency spectrum), //DIR === mean wave direction, WATLEV === water level (in
 * m), //VEL === current velocity (vector; in m/s), //FORCE === wave-induced force per unit surface area (vector; in
 * N/m2).
 */
private void formateSimulationOutputSpec(final Formatter formatter) {
    String restartComent = (m_controlModel.getRestart() ? "/" : "");
    formatter.format("/%n" + "/%n" + "TITLE                            = 'Demo2D'%n"
            + "VARIABLES FOR GRAPHIC PRINTOUTS  = 'U,V,H,S,B'%n" + "GRAPHIC PRINTOUT PERIOD          = 1%n"
            + "LISTING PRINTOUT PERIOD          = 1%n" + "MASS-BALANCE                     = YES%n"
            + "TIME STEP                        = %d%n" + "NUMBER OF TIME STEPS             = 25%n"
            + "INFORMATION ABOUT SOLVER         = YES%n" + "/%n"
            + "/----------------------------------------------%n" + "/  INITIAL CONDITIONS%n"
            + "/----------------------------------------------%n" + "/%n"
            + "COMPUTATION CONTINUED            = " + (m_controlModel.getRestart() ? "YES%n" : "NO%n")
            + restartComent + "INITIAL CONDITIONS               = 'CONSTANT ELEVATION'%n" + restartComent
            + "INITIAL ELEVATION                = %f%n" + "/%n"
            + "/----------------------------------------------%n" + "/  BOUNDARY CONDITIONS %n"
            + "/----------------------------------------------%n" + "/%n"
            + "/PRESCRIBED FLOWRATES             = 0.;0.035;0.070%n"
            + "/PRESCRIBED ELEVATIONS            = 0.2852;0.;0.%n"
            + "/VELOCITY PROFILES                = 2;2;2%n" + "/%n"
            + "/----------------------------------------------%n" + "/  PHYSICAL PARAMETERS%n"
            + "/----------------------------------------------%n" + "/%n"
            + "LAW OF BOTTOM FRICTION           = 5%n" + "FRICTION COEFFICIENT             = 0.1%n"
            + "TURBULENCE MODEL                 = 1%n" + "VELOCITY DIFFUSIVITY             = 1.E-1%n"
            + "/----------------------------------------------%n" + "/  NUMERICAL PARAMETERS%n"
            + "/----------------------------------------------%n" + "TYPE OF ADVECTION                 = 1;5%n"
            + "SUPG OPTION                       = 2;2%n" + "TREATMENT OF THE LINEAR SYSTEM    = 1%n"
            + "SOLVER                            = 1%n" + "/SOLVER OPTION                     = 3%n"
            + "/IMPLICITATION FOR DEPTH           = 0.6%n" + "/IMPLICITATION FOR VELOCITY        = 0.6%n"
            + "/MASS-LUMPING ON H                 = 1.%n" + "/H CLIPPING                        = NO%n" + "/%n",
            3600, m_controlModel.getELEV()); //367.5

    //          "TITLE = 'TELEMAC 2D : RIVER CULM'  COMPUTATION CONTINUED :YES%n" +
    //          "INITIAL TIME SET TO ZERO : YES%n" +
    //          "TIME STEP = 8.     NUMBER OF TIME STEPS = 6750%n" +
    //          "GRAPHIC PRINTOUT PERIOD : 250%n" +
    //          "VARIABLES TO BE PRINTED : ''    LISTING PRINTOUT PERIOD =  250%n" +
    //          "VARIABLES FOR GRAPHIC PRINTOUTS : 'U,V,S,B,H'%n" +
    //          "LAW OF BOTTOM FRICTION = 3  FRICTION COEFFICIENT = 30.%n" +
    //          "VELOCITY DIFFUSIVITY = 2.        TURBULENCE MODEL : 1%n" +
    //          "SOLVER ACCURACY = 1.E-4      INFORMATION ABOUT SOLVER : OUI%n" +
    //          "/SOLVER : 7  SOLVER OPTION : 2   PRECONDITIONING : 2%n" +
    //          "IMPLICITATION FOR DEPTH = 1.         IMPLICITATION FOR VELOCITY = 1.%n" +
    //          "INITIAL CONDITIONS : 'CONSTANT ELEVATION' INITIAL ELEVATION : 50.%n" +
    //          "PRESCRIBED FLOWRATES : 28.32 ;  0.%n" +
    //          "PRESCRIBED ELEVATIONS : 0.   ; 23.77%n" +
    //          "MASS-BALANCE : YES  VALIDATION : YES%n" +
    //          "TYPE OF ADVECTION : 1;5%n" +
    //          "      SUPG OPTION : 1;0                MASS-LUMPING ON H : 1.%n" +
    //          "TIDAL FLATS : YES   OPTION FOR THE TREATMENT OF TIDAL FLATS : 1%n" +
    //          "CONTINUITY CORRECTION : NO%n" +
    //          "MATRIX STORAGE : 3     MATRIX-VECTOR PRODUCT : 2%n" +
    //          "TREATMENT OF THE LINEAR SYSTEM : 2 SOLVER : 1  PRECONDITIONING : 2  %n" );

    //    // format the output of model
    //    formatter.format( "$*******************MODEL OUTPUT************************\n" + //$NON-NLS-1$
    //        "$\n" + //$NON-NLS-1$
    //        "BLOCK 'COMPGRID' NOHEAD '%s.mat' XP YP HSIG TM01 DIR WATLEV WLEN FORCE VEL WIND %s \n" + //$NON-NLS-1$
    //        "POINTS 'P_%s' FILE '%s.txt'\n" + //$NON-NLS-1$
    //        "TABLE 'P_%s' HEAD '%s_out.tab' %s XP YP HSIG DIR TM01 WATLEV WIND VEL %s \n" + //$NON-NLS-1$   
    //        "TEST 1,0\n" + //$NON-NLS-1$
    //        "COMPUTE %s %s\n" + //$NON-NLS-1$ 
    //        "STOP\n" + //$NON-NLS-1$
    //        "$\n", //$NON-NLS-1$
    //
    //    ISimulation1D2DConstants.SIM_Telemac_TRIANGLE_FILE, m_controlModel.isUnsteadySelected() ? ("OUTPUT " + m_strTimeZeroFromFormated) : "", //$NON-NLS-1$   //$NON-NLS-2$
    //
    //    ISimulation1D2DConstants.SIM_Telemac_TRIANGLE_FILE, ISimulation1D2DConstants.SIM_Telemac_TRIANGLE_FILE, ISimulation1D2DConstants.SIM_Telemac_TRIANGLE_FILE, ISimulation1D2DConstants.SIM_Telemac_TRIANGLE_FILE, m_controlModel.isUnsteadySelected() ? "TIME " : "", //$NON-NLS-1$   //$NON-NLS-2$
    //    m_controlModel.isUnsteadySelected() ? "OUTPUT " + m_strTimeZeroFromFormated : "", //$NON-NLS-1$   //$NON-NLS-2$
    //    m_controlModel.isUnsteadySelected() ? "NONST" : "STATIONARY", //$NON-NLS-1$  //$NON-NLS-2$
    //    m_strTimeZeroFromToFormated );

}

From source file:com.cloud.utils.net.NetUtils.java

public static String getMacAddress(final InetAddress address) {
    final StringBuffer sb = new StringBuffer();
    final Formatter formatter = new Formatter(sb);
    try {/*ww  w . j  a  v a  2  s .co m*/
        final NetworkInterface ni = NetworkInterface.getByInetAddress(address);
        final byte[] mac = ni.getHardwareAddress();

        for (int i = 0; i < mac.length; i++) {
            formatter.format("%02X%s", mac[i], i < mac.length - 1 ? ":" : "");
        }
    } catch (final SocketException e) {
        s_logger.error("SocketException when trying to retrieve MAC address", e);
    } finally {
        formatter.close();
    }
    return sb.toString();
}

From source file:edu.stanford.muse.index.EmailDocument.java

/** used mostly as a debug routine */
public String getHeader() {
    StringBuilder sb = new StringBuilder();
    sb.append("Folder: " + folderName + "\n");

    StringBuilder timeSB = new StringBuilder();
    Formatter formatter = new Formatter(timeSB);
    if (date != null) {
        Calendar c = new GregorianCalendar();
        c.setTime(date);//from w  w  w .  j av  a2 s.  com
        formatter.format("%02d:%02d", c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
        sb.append("Date: " + c.get(Calendar.DATE) + " " + CalendarUtil.getDisplayMonth(c) + " "
                + c.get(Calendar.YEAR) + " " + timeSB + "\n");
    }
    formatter.close();
    sb.append("From: " + getFromString() + "\n");
    sb.append("To: " + getToString() + "\n");
    String cc = getCcString();
    if (!Util.nullOrEmpty(cc))
        sb.append("Cc: " + cc + "\n");
    String bcc = getBccString();
    if (!Util.nullOrEmpty(bcc))
        sb.append("Bcc: " + bcc + "\n");

    if (description == null)
        description = "<None>";
    sb.append("Subject: " + description + "\n");
    if (messageID != null)
        sb.append("Message-ID: " + messageID + "\n");
    sb.append("\n");
    return sb.toString();
}