Example usage for java.util Formatter toString

List of usage examples for java.util Formatter toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the result of invoking toString() on the destination for the output.

Usage

From source file:org.xwiki.rest.resources.BaseSearchResult.java

/**
 * Search for keyword in the given scopes. Limit the search only to Pages. Search for keyword
 * //  www.  j a v a  2  s .  c  o m
 * @param searchScopes
 * @param keywords
 * @param wikiName
 * @param space
 * @param hasProgrammingRights
 * @param number
 * @return
 * @throws QueryException
 * @throws IllegalArgumentException
 * @throws UriBuilderException
 * @throws XWikiException
 */
protected List<SearchResult> searchSpaces(String keywords, String wikiName, boolean hasProgrammingRights,
        int number) throws QueryException, IllegalArgumentException, UriBuilderException, XWikiException {
    String database = Utils.getXWikiContext(componentManager).getDatabase();

    /* This try is just needed for executing the finally clause. */
    try {
        List<SearchResult> result = new ArrayList<SearchResult>();

        if (keywords == null) {
            return result;
        }

        Formatter f = new Formatter();

        f.format("select distinct doc.space from XWikiDocument as doc where upper(doc.space) like :keywords ");

        if (hasProgrammingRights) {
            f.format(" order by doc.space asc");
        } else {
            f.format(
                    " and doc.space<>'XWiki' and doc.space<>'Admin' and doc.space<>'Panels' order by doc.space asc");
        }

        String query = f.toString();

        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL)
                .bindValue("keywords", String.format("%%%s%%", keywords.toUpperCase())).setLimit(number)
                .execute();

        for (Object object : queryResult) {

            String spaceName = (String) object;

            SearchResult searchResult = objectFactory.createSearchResult();
            searchResult.setType("space");
            searchResult.setId(String.format("%s:%s", wikiName, spaceName));
            searchResult.setWiki(wikiName);
            searchResult.setSpace(spaceName);

            /* Add a link to the space information */
            Link spaceLink = new Link();
            spaceLink.setRel(Relations.SPACE);
            String spaceUri = UriBuilder.fromUri(uriInfo.getBaseUri()).path(SpaceResource.class)
                    .build(wikiName, spaceName).toString();
            spaceLink.setHref(spaceUri);
            searchResult.getLinks().add(spaceLink);

            /* Add a link to the webhome if it exists */
            String webHomePageId = Utils.getPageId(wikiName, spaceName, "WebHome");
            if (Utils.getXWikiApi(componentManager).exists(webHomePageId)
                    && Utils.getXWikiApi(componentManager).hasAccessLevel("view", webHomePageId)) {
                String pageUri = UriBuilder.fromUri(uriInfo.getBaseUri()).path(PageResource.class)
                        .build(wikiName, spaceName, "WebHome").toString();

                Link pageLink = new Link();
                pageLink.setHref(pageUri);
                pageLink.setRel(Relations.HOME);
                searchResult.getLinks().add(pageLink);
            }

            result.add(searchResult);
        }

        return result;
    } finally {
        Utils.getXWikiContext(componentManager).setDatabase(database);
    }
}

From source file:com.itemanalysis.psychometrics.polycor.PolychoricLogLikelihoodTwoStep.java

public String print(double[] x) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    double se = this.getStandardError(x);

    f.format("%34s", "Polychoric correlation, Two-step est. = ");
    f.format("%6.4f", rho);
    f.format(" (%6.4f)", se);
    f.format("%n");
    f.format("%n");
    f.format("%-20s", "Row Thresholds");
    f.format("%n");

    for (int i = 0; i < (alpha.length - 1); i++) {
        f.format("%6.4f", alpha[i]);
        f.format("%n");
    }//from   w  ww  .j a v a2 s  . com

    f.format("%n");
    f.format("%n");
    f.format("%-20s", "Column Thresholds");
    f.format("%n");

    for (int i = 0; i < (beta.length - 1); i++) {
        f.format("% 6.4f", beta[i]);
        f.format("%n");
    }

    f.format("%n");
    return f.toString();

}

From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java

/**
 * Super simple encryption of just converting string to HEX.
 * @param str the string to be encrypted
 * @return hex-ified string//from w  w  w .j  a  v a  2  s .co  m
 */
private String encrypt(final String str) {
    Formatter formatter = new Formatter();
    for (byte b : str.getBytes()) {
        formatter.format("%02x", b);
    }
    String s = formatter.toString();
    formatter.close();
    return s;
}

From source file:com.adobe.ac.pmd.rules.core.Violation.java

public String toXmlString(final IFlexFile violatedFile, final String ruleSetName) {
    final Formatter formatter = new Formatter();

    if (rule != null) {
        final StringBuffer message = new StringBuffer(getRuleMessage());

        formatter.format("      <violation beginline=\"%d\" " + "endline=\"%d\" begincolumn=\"%d\" "
                + "endcolumn=\"%d\" rule=\"%s\" " + "ruleset=\"%s\" package=\"%s\" "
                + "class=\"%s\" externalInfoUrl=\"%s\" " + "priority=\"%s\">%s</violation>" + getNewLine(),
                beginLine, endLine, beginColumn, endColumn, rule.getRuleName(), ruleSetName,
                violatedFile.getPackageName(), violatedFile.getClassName(),
                RULESET_CREATOR_URL + extractShortName(rule.getName()), rule.getPriority(), message);
    }/*from w  w  w  .ja v a 2  s  .  c  om*/
    return formatter.toString();
}

From source file:edu.cmu.tetrad.cli.search.FgsCli.java

private static String createOutputRunInfo(Set<String> excludedVariables, DataSet dataSet) {
    Formatter fmt = new Formatter();

    fmt.format("Runtime Parameters:%n");
    fmt.format("verbose = %s%n", verbose);
    fmt.format("number of threads = %s%n", numOfThreads);
    fmt.format("%n");

    fmt.format("Dataset:%n");
    fmt.format("file = %s%n", dataFile.getFileName());
    fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter));
    fmt.format("cases read in = %s%n", dataSet.getNumColumns());
    fmt.format("variables read in = %s%n", dataSet.getNumRows());
    fmt.format("%n");

    if (excludedVariableFile != null || knowledgeFile != null) {
        fmt.format("Filters:%n");
        if (excludedVariableFile != null) {
            fmt.format("excluded variables (%d variables) = %s%n", excludedVariables.size(),
                    excludedVariableFile.getFileName());
        }//from  w w  w .  j a v  a2 s. c o  m
        if (knowledgeFile != null) {
            fmt.format("knowledge = %s%n", knowledgeFile.getFileName());
        }
        fmt.format("%n");
    }

    fmt.format("FGS Parameters:%n");
    fmt.format("penalty discount = %f%n", penaltyDiscount);
    fmt.format("depth = %d%n", depth);
    fmt.format("%n");

    fmt.format("Run Options:%n");
    fmt.format("heuristic speedup = %s%n", heuristicSpeedup);
    fmt.format("ignore linear dependence = %s%n", ignoreLinearDependence);
    fmt.format("%n");

    fmt.format("Data Validations:%n");
    fmt.format("skip unique variable name check = %s%n", skipUniqueVarName);
    fmt.format("skip variables with zero variance check = %s%n", skipZeroVariance);
    fmt.format("%n");

    return fmt.toString();
}

From source file:org.efaps.esjp.accounting.util.data.ImportDetails.java

/**
 *
 *///  w w  w . j av a  2  s .  c  o  m
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:edu.cmu.tetrad.cli.search.FgsDiscrete.java

private static String createOutputRunInfo(Set<String> excludedVariables, DataSet dataSet) {
    Formatter fmt = new Formatter();

    fmt.format("Runtime Parameters:%n");
    fmt.format("verbose = %s%n", verbose);
    fmt.format("number of threads = %s%n", numOfThreads);
    fmt.format("%n");

    fmt.format("Dataset:%n");
    fmt.format("file = %s%n", dataFile.getFileName());
    fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter));
    fmt.format("cases read in = %s%n", dataSet.getNumColumns());
    fmt.format("variables read in = %s%n", dataSet.getNumRows());
    fmt.format("%n");

    if (excludedVariableFile != null || knowledgeFile != null) {
        fmt.format("Filters:%n");
        if (excludedVariableFile != null) {
            fmt.format("excluded variables (%d variables) = %s%n", excludedVariables.size(),
                    excludedVariableFile.getFileName());
        }//w  w w  . j a v a 2  s .com
        if (knowledgeFile != null) {
            fmt.format("knowledge = %s%n", knowledgeFile.getFileName());
        }
        fmt.format("%n");
    }

    fmt.format("FGS Discrete Parameters:%n");
    fmt.format("structure prior = %f%n", structurePrior);
    fmt.format("sample prior = %f%n", samplePrior);
    fmt.format("depth = %d%n", depth);
    fmt.format("%n");

    fmt.format("Run Options:%n");
    fmt.format("heuristic speedup = %s%n", heuristicSpeedup);
    fmt.format("%n");

    fmt.format("Data Validations:%n");
    fmt.format("skip unique variable name check = %s%n", skipUniqueVarName);
    fmt.format("skip limit number of category check = %s%n", skipCategoryLimit);
    fmt.format("%n");

    return fmt.toString();
}

From source file:com.itemanalysis.jmetrik.stats.descriptives.DescriptiveAnalysis.java

public void publishHeader() throws IllegalArgumentException {
    StringBuilder header = new StringBuilder();
    Formatter f = new Formatter(header);
    String s1 = String.format("%1$tB %1$te, %1$tY  %tT", Calendar.getInstance());
    int len = 21 + Double.valueOf(Math.floor(Double.valueOf(s1.length()).doubleValue() / 2.0)).intValue();
    String dString = "";
    try {/*  w w w  .ja  va2 s. c  o m*/
        dString = command.getDataString();
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex);
    }
    int len2 = 21 + Double.valueOf(Math.floor(Double.valueOf(dString.length()).doubleValue() / 2.0)).intValue();

    f.format("%31s", "DESCRIPTIVE STATISTICS");
    f.format("%n");
    f.format("%" + len2 + "s", dString);
    f.format("%n");
    f.format("%" + len + "s", s1);
    f.format("%n");
    f.format("%n");
    publish(f.toString());
}

From source file:com.hyperaware.conference.android.fragment.SpeakerDetailFragment.java

private void updateSpeaker() {
    tvName.setText(speakerItem.getName());
    host.setTitle(speakerItem.getName());

    final String company = speakerItem.getCompanyName();
    tvCompany.setVisibility(Strings.isNullOrEmpty(company) ? View.GONE : View.VISIBLE);
    tvCompany.setText(company);/*from   w  w w  .jav a  2s.c  o  m*/

    final String title = speakerItem.getTitle();
    tvTitle.setVisibility(Strings.isNullOrEmpty(title) ? View.GONE : View.VISIBLE);
    tvTitle.setText(title);

    Glide.with(SpeakerDetailFragment.this).load(speakerItem.getImage100()).fitCenter()
            .placeholder(R.drawable.nopic).into(ivPic);

    boolean links_visible = false;
    final String website = speakerItem.getWebsite();
    if (!Strings.isNullOrEmpty(website)) {
        links_visible = true;
        tvWebsite.setVisibility(View.VISIBLE);
        tvWebsite.setText(website);
    }
    final String twitter = speakerItem.getTwitter();
    if (!Strings.isNullOrEmpty(twitter)) {
        links_visible = true;
        tvTwitter.setVisibility(View.VISIBLE);
        tvTwitter.setText(twitter);
    }
    final String facebook = speakerItem.getFacebook();
    if (!Strings.isNullOrEmpty(facebook)) {
        links_visible = true;
        tvFacebook.setVisibility(View.VISIBLE);
        tvFacebook.setText(facebook);
    }
    final String linkedin = speakerItem.getLinkedin();
    if (!Strings.isNullOrEmpty(linkedin)) {
        links_visible = true;
        tvLinkedin.setVisibility(View.VISIBLE);
        tvLinkedin.setText(linkedin);
    }
    vgDetailLinks.setVisibility(links_visible ? View.VISIBLE : View.GONE);

    tvAbout.setText(speakerItem.getAbout());

    if (agendaItems.size() > 0) {
        vgSessions.setVisibility(View.VISIBLE);
        vgSessions.removeAllViews();
        final StringBuilder sb = new StringBuilder();
        final Formatter formatter = new Formatter(sb);
        final LayoutInflater inflater = getActivity().getLayoutInflater();
        for (final AgendaItem item : agendaItems) {
            final View view = inflater.inflate(R.layout.item_speaker_session, vgSessions, false);

            ((TextView) view.findViewById(R.id.tv_topic)).setText(item.getTopic());

            sb.setLength(0);
            DateUtils.formatDateRange(getActivity(), formatter, item.getEpochStartTime() * 1000,
                    item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY,
                    tz.getID());
            ((TextView) view.findViewById(R.id.tv_date)).setText(formatter.toString());

            sb.setLength(0);
            DateUtils.formatDateRange(getActivity(), formatter, item.getEpochStartTime() * 1000,
                    item.getEpochEndTime() * 1000, DateUtils.FORMAT_SHOW_TIME, tz.getID());
            ((TextView) view.findViewById(R.id.tv_time)).setText(formatter.toString());

            final String session_id = item.getId();
            final ImageButton ib_favorite = (ImageButton) view.findViewById(R.id.button_favorite_session);
            favSessionButtonManager.attach(ib_favorite, session_id);

            if (host != null) {
                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Fragment next = SessionDetailFragment.instantiate(item.getId());
                        host.pushFragment(next, "session_detail");
                    }
                });
            }

            vgSessions.addView(view);
        }
    }
}

From source file:com.itemanalysis.jmetrik.stats.frequency.FrequencyAnalysis.java

public void publishHeader() throws IllegalArgumentException {
    StringBuilder header = new StringBuilder();
    Formatter f = new Formatter(header);
    String s1 = String.format("%1$tB %1$te, %1$tY  %tT", Calendar.getInstance());
    int len = 21 + Double.valueOf(Math.floor(Double.valueOf(s1.length()).doubleValue() / 2.0)).intValue();
    String dString = "";
    try {/*from   w w w.  j a v a 2  s  . com*/
        dString = command.getDataString();
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex);
    }
    int len2 = 21 + Double.valueOf(Math.floor(Double.valueOf(dString.length()).doubleValue() / 2.0)).intValue();

    f.format("%31s", "FREQUENCY ANALYSIS");
    f.format("%n");
    f.format("%" + len2 + "s", dString);
    f.format("%n");
    f.format("%" + len + "s", s1);
    f.format("%n");
    f.format("%n");
    publish(f.toString());
}