Example usage for java.util Formatter Formatter

List of usage examples for java.util Formatter Formatter

Introduction

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

Prototype

public Formatter(OutputStream os) 

Source Link

Document

Constructs a new formatter with the specified output stream.

Usage

From source file:com.itemanalysis.psychometrics.reliability.AbstractScoreReliability.java

public String confidenceIntervalToString(double[] confidenceInterval) {
    StringBuilder builder = new StringBuilder();
    Formatter f = new Formatter(builder);
    f.format("(%6.4f, ", confidenceInterval[0]);
    f.format("%6.4f)", confidenceInterval[1]);
    return f.toString();
}

From source file:ca.nines.ise.cmd.Help.java

/**
 * Format a list of commands and send it to System.out.
 *
 * @throws InstantiationException//from   ww w .j  a v  a  2s.c  o  m
 * @throws IllegalAccessException
 */
public void listCommands() throws InstantiationException, IllegalAccessException {
    Formatter formatter = new Formatter(System.out);
    formatter.format("%n%12s   %s%n%n", "command", "description");

    Map<String, String> descriptions = new HashMap<>();
    for (Class<?> cls : ClassIndex.getSubclasses(Command.class)) {
        Command cmd = (Command) cls.newInstance();
        descriptions.put(cls.getSimpleName().toLowerCase(), cmd.description());
    }
    String names[] = descriptions.keySet().toArray(new String[descriptions.size()]);
    Arrays.sort(names);
    for (String name : names) {
        formatter.format("%12s   %s%n", name, descriptions.get(name));
    }
}

From source file:com.itemanalysis.psychometrics.reliability.ReliabilityInterval.java

public String print() {
    StringBuilder builder = new StringBuilder();
    Formatter f = new Formatter(builder);
    String f2 = "";
    if (precision == 2) {
        f2 = "%.2f";
    } else if (precision == 4) {
        f2 = "%.4f";
    }//from   w  w w  .  j  a v a 2s  .  co  m

    f.format("%18s", "95% Confidence Interval: (");
    f.format(f2, this.confidenceInterval()[0]);
    f.format("%2s", ", ");
    f.format(f2, this.confidenceInterval()[1]);
    f.format("%1s", ")");

    return f.toString();
}

From source file:io.mapzone.controller.vm.http.HttpForwarder.java

/**
 * Encodes characters in the query or fragment part of the URI.
 *
 * <p>/*  w  w w .  j  ava2s .co m*/
 * Unfortunately, an incoming URI sometimes has characters disallowed by the
 * spec. HttpClient insists that the outgoing proxied request has a valid URI
 * because it uses Java's {@link URI}. To be more forgiving, we must escape the
 * problematic characters. See the URI class for the spec.
 *
 * @param in example: name=value&foo=bar#fragment
 */
protected static CharSequence encodeUriQuery(CharSequence in) {
    // Note that I can't simply use URI.java to encode because it will escape
    // pre-existing escaped things.
    StringBuilder outBuf = null;
    Formatter formatter = null;
    for (int i = 0; i < in.length(); i++) {
        char c = in.charAt(i);
        boolean escape = true;
        if (c < 128) {
            if (asciiQueryChars.get((int) c)) {
                escape = false;
            }
        } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii
            escape = false;
        }
        if (!escape) {
            if (outBuf != null)
                outBuf.append(c);
        } else {
            // escape
            if (outBuf == null) {
                outBuf = new StringBuilder(in.length() + 5 * 3);
                outBuf.append(in, 0, i);
                formatter = new Formatter(outBuf);
            }
            // leading %, 0 padded, width 2, capital hex
            formatter.format("%%%02X", (int) c);// TODO
        }
    }
    return outBuf != null ? outBuf : in;
}

From source file:com.google.samples.apps.iosched.util.TimeUtils.java

/**
 * Format a {@code date} honoring the app preference for using Conference or device timezone.
 * {@code Context} is used to lookup the shared preference settings.
 *///from  w  ww .j av a  2  s .  c  om
public static String formatShortDate(Context context, Date date) {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);
    return DateUtils.formatDateRange(context, formatter, date.getTime(), date.getTime(),
            DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_NO_YEAR,
            SettingsUtils.getDisplayTimeZone(context).getID()).toString();
}

From source file:com.itemanalysis.psychometrics.statistics.StorelessDescriptiveStatistics.java

public String toString(String title) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%-50s", title);
    f.format("%n");
    f.format("%30s", "==============================");
    f.format("%n");
    f.format("%-10s", "Statistic");
    f.format("%5s", "");
    f.format("%10s", "Value");
    f.format("%5s", "");
    f.format("%n");
    f.format("%30s", "------------------------------");
    f.format("%n");
    f.format("%-10s", "N");
    f.format("%5s", "");
    f.format("%10.4f", (double) m.getN());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Min");
    f.format("%5s", "");
    f.format("%10.4f", min.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Max");
    f.format("%5s", "");
    f.format("%10.4f", max.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Mean");
    f.format("%5s", "");
    f.format("%10.4f", m.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "St. Dev.");
    f.format("%5s", "");
    f.format("%10.4f", sd.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Skewness");
    f.format("%5s", "");
    f.format("%10.4f", skew.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%-10s", "Kurtosis");
    f.format("%5s", "");
    f.format("%10.4f", kurt.getResult());
    f.format("%5s", "");
    f.format("%n");
    f.format("%30s", "==============================");
    f.format("%n");
    return f.toString();
}

From source file:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

public DayAdapter(Context context, Cursor c, int julianDay) {
    super(context, c, false);
    inflater = LayoutInflater.from(context);
    mJulianDay = julianDay;/*  www.j a v a  2  s  . c  o m*/

    mIs24Hour = DateFormat.is24HourFormat(context);

    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter((mStringBuilder));

    mCurrencyFormatter = NumberFormat.getCurrencyInstance();

    //Caching
    mIdToTimeArray = new SparseArray<String>();
    mIdToPayArray = new SparseArray<String>();

    mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income),
            true);
}

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

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);

    f.format("%-10s", rowValue);
    f.format("%5s", "");

    Iterator<Comparable<?>> iter = columns.valuesIterator();
    double freq = 0;

    while (iter.hasNext()) {
        freq = columns.getCount(iter.next());
        f.format("%10.0f", freq);
        f.format("%5s", "");
    }//from  www.j  a  va 2s.  c  om
    return f.toString();
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalMixtureModel.java

public MvNormalMixtureModel(RealMatrix data, int groups) {
    this.data = data;
    this.sampleSize = data.getRowDimension();
    this.dimensions = data.getColumnDimension();
    this.groups = groups;
    piKp1 = new double[groups];

    sb = new StringBuilder();
    emHistory = new Formatter(sb);
    emHistory.format("%10s", "ITERATION");
    emHistory.format("%5s", "");
    emHistory.format("%12s", "LOGLIKE");
    emHistory.format("%5s", "");
    emHistory.format("%12s", "DELTA");
    emHistory.format("%5s", "");
    emHistory.format("%n");
    emHistory.format("%50s", "==================================================");
    emHistory.format("%n");

    initializeComponentDistributions();/*from   w  w  w . jav  a2  s.co  m*/
}

From source file:org.megam.deccanplato.provider.ProviderRegistry.java

public void Data() {
    StringBuilder strbd = new StringBuilder();
    final Formatter formatter = new Formatter(strbd);
    for (Map.Entry<String, Provider> entry : providersMap.entrySet()) {
        formatter.format("%10s = %s%n", entry.getKey(), entry.getValue());
    }/*from   www . jav a  2  s  .  c o  m*/
    for (Map.Entry<String, Set<BusinessActivity>> entry1 : bizActivityMap.entrySet()) {
        formatter.format("%10s = %s%n", entry1.getKey(), entry1.getValue());
    }
    formatter.close();

}