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:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java

public static String getQuotedTimeString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {//from ww  w .j a v a 2  s  . co 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:com.itemanalysis.jmetrik.stats.transformation.LinearTransformationAnalysis.java

private String publishHeader() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    String dString = "";
    String title = "LINEAR TRANSFORMATION";

    try {//from  www.ja  v a2s.  c  o m
        dString = command.getDataString();
    } catch (IllegalArgumentException ex) {
        dString = "";
        throw new IllegalArgumentException(ex);
    }

    //create header
    int len1 = 25 + Double.valueOf(Math.floor(Double.valueOf(title.length()).doubleValue() / 2.0)).intValue();
    int len2 = 25 + Double.valueOf(Math.floor(Double.valueOf(dString.length()).doubleValue() / 2.0)).intValue();

    String date = String.format("%1$tB %1$te, %1$tY  %tT", Calendar.getInstance());
    int len3 = 25 + Double.valueOf(Math.floor(Double.valueOf(date.length()).doubleValue() / 2.0)).intValue();

    f.format("%" + len1 + "s", title);
    f.format("%n");
    f.format("%" + len2 + "s", dString);
    f.format("%n");
    f.format("%" + len3 + "s", date);
    f.format("%n");
    f.format("%n");
    f.format("%n");
    f.format("%n");

    return f.toString();
}

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

public static String getTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*w  w  w.  jav a 2s. 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));
        buff.append(" ");
        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.CFAccMSSql.CFAccMSSqlSchema.java

public static String getQuotedTimestampString(Calendar val) {
    if (val == null) {
        return ("null");
    } else {/*from w ww .  j a  va 2  s  . 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.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:com.irccloud.android.data.EventsDataSource.java

public Event addEvent(IRCCloudJSONObject event) {
    synchronized (events) {
        if (!events.containsKey(event.bid()))
            events.put(event.bid(), new TreeMap<Long, Event>());

        Event e = getEvent(event.eid(), event.bid());
        if (e == null) {
            e = new Event();
            events.get(event.bid()).put(event.eid(), e);
        }/*from www. j  a va 2 s.  c om*/
        e.cid = event.cid();
        e.bid = event.bid();
        e.eid = event.eid();
        e.type = event.type();
        e.msg = event.getString("msg");
        e.hostmask = event.getString("hostmask");
        e.from = event.getString("from");
        e.from_mode = event.getString("from_mode");
        e.chan = event.getString("chan");
        if (event.has("newnick"))
            e.nick = event.getString("newnick");
        else if (event.has("nick"))
            e.nick = event.getString("nick");
        else
            e.nick = null;
        e.old_nick = event.getString("oldnick");
        e.server = event.getString("server");
        e.diff = event.getString("diff");
        e.highlight = event.getBoolean("highlight");
        e.self = event.getBoolean("self");
        e.to_chan = event.getBoolean("to_chan");
        e.to_buffer = event.getBoolean("to_buffer");
        e.ops = event.getJsonNode("ops");
        e.color = R.color.row_message_label;
        e.bg_color = R.color.message_bg;
        e.row_type = 0;
        e.html = null;
        e.group_msg = null;
        e.linkify = true;
        e.target_mode = null;
        e.pending = false;
        e.failed = false;
        e.command = null;
        e.day = -1;
        e.entities = event.getJsonNode("entities");

        if (event.has("reqid"))
            e.reqid = event.getInt("reqid");
        else
            e.reqid = -1;

        if (e.from != null)
            e.from = TextUtils.htmlEncode(e.from);

        if (e.msg != null)
            e.msg = TextUtils.htmlEncode(e.msg);

        Formatter f = formatterMap.get(e.type);
        if (f != null)
            f.format(event, e);

        if (event.has("value") && !event.type().startsWith("cap_")) {
            e.msg = "<pre>" + event.getString("value") + " " + e.msg + "</pre>";
        }

        if (e.highlight)
            e.bg_color = R.color.highlight;

        if (e.self)
            e.bg_color = R.color.self;

        if (highest_eid < event.eid())
            highest_eid = event.eid();

        return e;
    }
}

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

/**
 * @param hash//from  w  w w. j  a v a2s. co 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:com.android.ddmuilib.net.NetworkPanel.java

/**
 * Find a {@link TrackedItem} that matches the requested UID and tag, or
 * create one if none exists.//  www  .  j a  v  a  2s.  c  om
 */
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:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.java

/**
 * writes the Continuity Lines Data Block of the RMAKalypso controlFile (*.R10) into the PrintWriter
 *//*from w  w w . j  a va  2  s.c om*/
private void writeR10ContinuityLineDataBlock(final Formatter formatter) throws CoreException, IOException {
    final List<IFELine> continuityLines = m_calculationUnit.getContinuityLines();
    formatter.format("SCL%9d%n", continuityLines.size()); //$NON-NLS-1$
    for (final IFELine line : continuityLines) {
        final IFE1D2DNode[] nodes = line.getNodes();
        for (int i = 0; i < nodes.length; i++) {
            final IFE1D2DNode node = nodes[i];
            final int nodeID = m_nativeIDProvider.getConversionID(node);
            if (nodeID == 0) {
                final GM_Point position = node.getPoint();
                final String msg = Messages
                        .getString("org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.11"); //$NON-NLS-1$
                final IGeoStatus status = m_log.log(IStatus.ERROR, ISimulation1D2DConstants.CODE_PRE, msg,
                        position, null);
                throw new CoreException(status);
            }

            if (i == 0)
                formatter.format("CC1 %4d", m_nativeIDProvider.getConversionID(line)); //$NON-NLS-1$
            else if (i % 9 == 0) {
                formatter.format("%nCC2     "); //$NON-NLS-1$
            }

            formatter.format("%8d", nodeID); //$NON-NLS-1$
        }

        // Why this "if" was here?
        // if( nodes.length % 9 != 0 )
        formatter.format("%n"); //$NON-NLS-1$

        // check if line is an inner boundary line (only for coupled 1d2d units and enabled coupled simulation)
        // this is the case if it is contained in two 2d calculation units of this coupled unit
        final ICalculationUnit parentCalculationUnit = m_controlModel.getCalculationUnit();
        if (parentCalculationUnit.getType() == TYPE.TYPE1D2D
                && ((ICalculationUnit1D2D) parentCalculationUnit).isCoupledSimulation()) {
            final ICalculationUnit1D2D calculationUnit1D2D = (ICalculationUnit1D2D) parentCalculationUnit;
            final IFeatureBindingCollection<ICalculationUnit> changedSubUnits = calculationUnit1D2D
                    .getSubCalculationUnits();
            int in2DCalcUnitCount = 0;
            final IFE1D2DComplexElement<?>[] containers = line.getLinkedElements();
            for (final Feature calcUnit : containers) {
                if (((ICalculationUnit) calcUnit).getType() == TYPE.TYPE2D
                        && changedSubUnits.contains(calcUnit)) {
                    in2DCalcUnitCount++;
                }
            }
            if (in2DCalcUnitCount == 2)
                formatter.format("ICL %4d %4d\n", m_staticInnerLinesIDProvider.getOrAdd(line.getId()), //$NON-NLS-1$
                        m_nativeIDProvider.getConversionID(line));
        }

        FormatterUtils.checkIoException(formatter);
    }
    formatter.format("ECL%n"); //$NON-NLS-1$

    if (m_controlModel.getIDNOPT() != 0 && m_controlModel.getIDNOPT() != -1)
        formatter.format("MP %21.3f%8.3f%8.5f%8.2f%n", //$NON-NLS-1$
                m_controlModel.getFixedMarshBottom() ? 0.0 : m_controlModel.getAC1(), m_controlModel.getAC2(),
                m_controlModel.getAC3(), m_controlModel.getFixedMarshBottom() ? m_controlModel.getAC4() : 0.0);

    formatter.format("ENDGEO%n"); //$NON-NLS-1$

    FormatterUtils.checkIoException(formatter);
}

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);
    }/*ww  w.  jav a2  s  .c om*/
    formatter.close();
    return sb.toString();
}

From source file:fll.scheduler.SchedulerUI.java

private void loadScheduleDescription(final File file) {
    final Properties properties = new Properties();
    try (final Reader reader = new InputStreamReader(new FileInputStream(file), Utilities.DEFAULT_CHARSET)) {
        properties.load(reader);/*from   w  ww .  j  av  a  2 s . c o  m*/
    } catch (final IOException e) {
        final Formatter errorFormatter = new Formatter();
        errorFormatter.format("Error loading file: %s", e.getMessage());
        LOGGER.error(errorFormatter, e);
        JOptionPane.showMessageDialog(SchedulerUI.this, errorFormatter, "Error loading file",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(properties.toString());
    }

    try {
        final SolverParams params = new SolverParams();
        params.load(properties);
        mScheduleDescriptionEditor.setParams(params);
    } catch (final ParseException pe) {
        final Formatter errorFormatter = new Formatter();
        errorFormatter.format("Error parsing file: %s", pe.getMessage());
        LOGGER.error(errorFormatter, pe);
        JOptionPane.showMessageDialog(SchedulerUI.this, errorFormatter, "Error parsing file",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    mScheduleDescriptionFile = file;

    mDescriptionFilename.setText(file.getName());
}