List of usage examples for java.util Formatter toString
public String toString()
From source file:com.itemanalysis.psychometrics.cmh.CochranMantelHaenszel.java
public String printHeader() { StringBuilder buffer = new StringBuilder(); Formatter f = new Formatter(buffer); f.format("%-10s", " Item"); f.format("%2s", " "); f.format("%10s", "Chi-square"); f.format("%2s", " "); f.format("%7s", "p-value"); f.format("%2s", " "); f.format("%7s", "Valid N"); f.format("%2s", " "); f.format("%28s", " E.S. (95% C.I.) "); f.format("%2s", " "); f.format("%5s", "Class"); f.format("%2s", " "); f.format("%n"); f.format("%-10s", "----------"); f.format("%2s", " "); f.format("%10s", "----------"); f.format("%2s", " "); f.format("%7s", "-------"); f.format("%2s", " "); f.format("%7s", "-------"); f.format("%2s", " "); f.format("%28s", "----------------------------"); f.format("%2s", " "); f.format("%5s", "-----"); f.format("%2s", " "); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.cfa.AbstractConfirmatoryFactorAnalysisEstimator.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); double[] fl = model.getFactorLoading(); double[] er = model.getErrorVariance(); for (int i = 0; i < nItems; i++) { f.format("% .4f", fl[i]); f.format("%5s", ""); f.format("% .4f", er[i]); f.format("%n"); }//ww w. ja v a 2s . com f.format("%10s", "McDonald's Omega = "); f.format("%8.4f", mcdonaldOmega()); f.format("%n"); f.format("%10s", "GFI = "); f.format("%8.4f", gfi()); f.format("%n"); f.format("%10s", "AGFI = "); f.format("%8.4f", agfi()); f.format("%n"); f.format("%10s", "RMSEA = "); f.format("%8.4f", rmsea()); f.format("%n"); f.format("%10s", "RMSR = "); f.format("%8.4f", Math.sqrt(meanSquaredResidual())); f.format("%n"); f.format("%10s", "BIC = "); f.format("%8.4f", Math.sqrt(bic())); f.format("%n"); f.format("%10s", "X^2 = "); f.format("%8.4f", chisquare()); f.format("%n"); f.format("%10s", "df = "); f.format("%8.4f", degreesOfFreedom()); f.format("%n"); f.format("%10s", "p = "); f.format("%8.4f", pvalue()); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java
public String printLatentDistribution() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%30s", " Latent Distribution "); f.format("%n"); f.format("%30s", "=============================="); f.format("%n"); f.format("%10s", "Point"); f.format("%4s", ""); f.format("%16s", "Density"); f.format("%n"); f.format("%30s", "------------------------------"); f.format("%n"); for (int k = 0; k < latentDistribution.getNumberOfPoints(); k++) { f.format("% 10.8f", latentDistribution.getPointAt(k)); f.format("%4s", ""); f.format("% 10.8e", latentDistribution.getDensityAt(k));//15 wide f.format("%n"); }//w w w. j ava 2 s. c om f.format("%30s", "=============================="); f.format("%n"); f.format("%12s", "Mean = "); f.format("%8.4f", latentDistribution.getMean()); f.format("%n"); f.format("%12s", "Std. Dev. = "); f.format("%8.4f", latentDistribution.getStandardDeviation()); f.format("%n"); return f.toString(); }
From source file:edu.cmu.tetrad.cli.AbstractAlgorithmCli.java
private String createRunInfo(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.getNumRows()); fmt.format("variables read in = %s%n", dataSet.getNumColumns()); 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 ww.jav a2 s . c om*/ if (knowledgeFile != null) { fmt.format("knowledge = %s%n", knowledgeFile.getFileName()); } fmt.format("%n"); } fmt.format("Algorithm Parameters:%n"); printParameterInfos(fmt); fmt.format("%n"); fmt.format("Data Validations:%n"); printValidationInfos(fmt); return fmt.toString(); }
From source file:com.itemanalysis.psychometrics.cfa.AbstractConfirmatoryFactorAnalysisEstimator.java
public String printEstimates(ArrayList<VariableAttributes> items) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); double[] fl = model.getFactorLoading(); double[] er = model.getErrorVariance(); // f.format("%50s", " CONFIRMATORY FACTOR ANALYSIS RESULTS "); f.format("%n"); f.format("%-50s", model.getName()); f.format("%n"); f.format("%50s", "=================================================="); f.format("%n"); f.format("%10s", " "); f.format("%5s", ""); f.format("%10s", "Factor "); f.format("%5s", ""); f.format("%10s", " Error"); f.format("%n"); f.format("%10s", " Item"); f.format("%5s", ""); f.format("%10s", "Loading"); f.format("%5s", ""); f.format("%10s", "Variance"); f.format("%n"); f.format("%50s", "--------------------------------------------------"); f.format("%n"); for (int i = 0; i < items.size(); i++) { f.format("%10s", items.get(i)); f.format("%5s", ""); f.format("% 10.4f", fl[i]); f.format("%5s", ""); f.format("% 10.4f", er[i]); f.format("%n"); }/*from w w w . j av a 2 s .c o m*/ f.format("%50s", "--------------------------------------------------"); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java
public String printItemParameters() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%58s", "MMLE ITEM PARAMETER ESTIMATES"); f.format("%n"); f.format("%87s", "======================================================================================="); f.format("%n"); f.format("%-18s", "Item"); f.format("%5s", "Code"); f.format("%9s", "Apar"); f.format("%7s", "(SE)"); f.format("%9s", "Bpar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%9s", "Cpar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%9s", "Upar"); f.format("%1s", ""); f.format("%6s", "(SE)"); f.format("%n"); f.format("%87s", "---------------------------------------------------------------------------------------"); f.format("%n"); for (int j = 0; j < nItems; j++) { sb.append(irm[j].toString() + "\n"); }/*from w ww .j av a 2 s .c om*/ f.format("%87s", "======================================================================================="); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.scaling.NormalizedScore.java
public String printTable(int precision) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); String f1 = "%10." + precision + "f"; String f2 = "%10s"; // String f3="%10.4f"; //table header f.format("%28s", "SCORE TABLE"); f.format("%n"); f.format("%45s", "============================================="); f.format("%n"); f.format(f2, "Original"); f.format("%5s", ""); f.format(f2, "Percentile"); f.format("%5s", ""); f.format(f2, "Normalized"); f.format("%n"); f.format(f2, "Value"); f.format("%5s", ""); f.format(f2, "Rank"); f.format("%5s", ""); f.format(f2, "Score"); f.format("%n"); f.format("%45s", "---------------------------------------------"); f.format("%n"); int rs = 0;//from w w w . j av a2s . c o m double value = 0.0; double pr = 0.0; Iterator<Integer> iter = normScoreTable.keySet().iterator(); while (iter.hasNext()) { rs = iter.next(); pr = prank.getPercentileRankAt(rs); value = normScoreTable.get(rs); f.format(f1, (double) rs); f.format("%5s", ""); f.format(f1, pr); f.format("%5s", ""); f.format(f1, value); f.format("%5s", ""); f.format("%n"); } f.format("%45s", "============================================="); f.format("%n"); return f.toString(); }
From source file:com.itemanalysis.psychometrics.irt.estimation.MarginalMaximumLikelihoodEstimation.java
public String printItemFitStatistics() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%34s", "ITEM FIT STATISTIC"); f.format("%n"); f.format("%50s", "=================================================="); f.format("%n"); f.format("%-18s", "Item"); f.format("%2s", ""); if (g2ItemFit) { f.format("%8s", "G2"); } else {//from w w w . j a va 2 s .co m f.format("%8s", "S-X2"); } f.format("%2s", ""); f.format("%8s", "df"); f.format("%2s", ""); f.format("%8s", "p-value"); f.format("%n"); f.format("%50s", "--------------------------------------------------"); f.format("%n"); for (int j = 0; j < nItems; j++) { f.format("%-18s", irm[j].getName()); f.format("%2s", ""); f.format("%8.4f", itemFit[j].getValue()); f.format("%2s", ""); f.format("%8.4f", itemFit[j].getDegreesOfFreedom()); f.format("%2s", ""); f.format("%8.4f", itemFit[j].getPValue()); f.format("%n"); } f.format("%50s", "=================================================="); f.format("%n"); return f.toString(); }
From source file:org.xwiki.rest.internal.ModelFactory.java
public Object toRestObject(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion, Boolean withPrettyNames) { Object object = this.objectFactory.createObject(); fillObjectSummary(object, doc, xwikiObject, withPrettyNames); XWikiContext xwikiContext = this.xcontextProvider.get(); BaseClass xwikiClass = xwikiObject.getXClass(xwikiContext); for (java.lang.Object propertyClassObject : xwikiClass.getProperties()) { com.xpn.xwiki.objects.classes.PropertyClass propertyClass = (com.xpn.xwiki.objects.classes.PropertyClass) propertyClassObject; Property property = this.objectFactory.createProperty(); for (java.lang.Object o : propertyClass.getProperties()) { BaseProperty baseProperty = (BaseProperty) o; Attribute attribute = this.objectFactory.createAttribute(); attribute.setName(baseProperty.getName()); /* Check for null values in order to prevent NPEs */ if (baseProperty.getValue() != null) { attribute.setValue(baseProperty.getValue().toString()); } else { attribute.setValue(""); }//from w ww .j a va2 s. com property.getAttributes().add(attribute); } if (propertyClass instanceof ListClass) { ListClass listClass = (ListClass) propertyClass; List allowedValueList = listClass.getList(xwikiContext); if (!allowedValueList.isEmpty()) { Formatter f = new Formatter(); for (int i = 0; i < allowedValueList.size(); i++) { if (i != allowedValueList.size() - 1) { f.format("%s,", allowedValueList.get(i).toString()); } else { f.format("%s", allowedValueList.get(i).toString()); } } Attribute attribute = this.objectFactory.createAttribute(); attribute.setName(Constants.ALLOWED_VALUES_ATTRIBUTE_NAME); attribute.setValue(f.toString()); property.getAttributes().add(attribute); } } property.setName(propertyClass.getName()); property.setType(propertyClass.getClassType()); try { property.setValue(serializePropertyValue(xwikiObject.get(propertyClass.getName()))); } catch (XWikiException e) { // Should never happen } String propertyUri; if (useVersion) { propertyUri = Utils .createURI(baseUri, ObjectPropertyAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), doc.getVersion(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()) .toString(); } else { propertyUri = Utils .createURI(baseUri, ObjectPropertyResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()) .toString(); } Link propertyLink = this.objectFactory.createLink(); propertyLink.setHref(propertyUri); propertyLink.setRel(Relations.SELF); property.getLinks().add(propertyLink); object.getProperties().add(property); } Link objectLink = getObjectLink(this.objectFactory, baseUri, doc, xwikiObject, useVersion, Relations.SELF); object.getLinks().add(objectLink); return object; }
From source file:org.xwiki.rest.resources.BaseSearchResult.java
/** * Search for keyword in the given scopes. Limit the search only to Objects. * /* www. j av a 2 s . com*/ * @param keywords * @param wikiName * @param space * @param hasProgrammingRights * @param number * @return * @throws QueryException * @throws IllegalArgumentException * @throws UriBuilderException * @throws XWikiException */ protected List<SearchResult> searchObjects(String keywords, String wikiName, String space, 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(); if (space != null) { f.format( "select distinct doc.fullName, doc.space, doc.name, obj.className, obj.number from XWikiDocument as doc, BaseObject as obj, StringProperty as sp, LargeStringProperty as lsp where doc.space = :space and obj.name=doc.fullName and sp.id.id = obj.id and lsp.id.id = obj.id and (upper(sp.value) like :keywords or upper(lsp.value) like :keywords) "); } else { f.format( "select distinct doc.fullName, doc.space, doc.name, obj.className, obj.number from XWikiDocument as doc, BaseObject as obj, StringProperty as sp, LargeStringProperty as lsp where obj.name=doc.fullName and sp.id.id = obj.id and lsp.id.id = obj.id and (upper(sp.value) like :keywords or upper(lsp.value) like :keywords) "); } if (hasProgrammingRights) { f.format(" order by doc.fullName asc"); } else { f.format( " and doc.space<>'XWiki' and doc.space<>'Admin' and doc.space<>'Panels' and doc.name<>'WebPreferences' order by doc.fullName asc"); } String query = f.toString(); List<Object> queryResult = null; /* This is needed because if the :space placeholder is not in the query, setting it would cause an exception */ if (space != null) { queryResult = queryManager.createQuery(query, Query.XWQL) .bindValue("keywords", String.format("%%%s%%", keywords.toUpperCase())) .bindValue("space", space).setLimit(number).execute(); } else { queryResult = queryManager.createQuery(query, Query.XWQL) .bindValue("keywords", String.format("%%%s%%", keywords.toUpperCase())).setLimit(number) .execute(); } for (Object object : queryResult) { Object[] fields = (Object[]) object; String spaceName = (String) fields[1]; String pageName = (String) fields[2]; String className = (String) fields[3]; int objectNumber = (Integer) fields[4]; String id = Utils.getObjectId(wikiName, spaceName, pageName, className, objectNumber); String pageId = Utils.getPageId(wikiName, spaceName, pageName); if (Utils.getXWikiApi(componentManager).hasAccessLevel("view", pageId)) { SearchResult searchResult = objectFactory.createSearchResult(); searchResult.setType("object"); searchResult.setId(id); searchResult.setPageFullName(Utils.getPageFullName(wikiName, spaceName, pageName)); searchResult.setWiki(wikiName); searchResult.setSpace(spaceName); searchResult.setPageName(pageName); searchResult.setClassName(className); searchResult.setObjectNumber(objectNumber); String pageUri = UriBuilder.fromUri(uriInfo.getBaseUri()).path(PageResource.class) .build(wikiName, spaceName, pageName).toString(); Link pageLink = new Link(); pageLink.setHref(pageUri); pageLink.setRel(Relations.PAGE); searchResult.getLinks().add(pageLink); String objectUri = UriBuilder.fromUri(uriInfo.getBaseUri()).path(ObjectResource.class) .build(wikiName, spaceName, pageName, className, objectNumber).toString(); Link objectLink = new Link(); objectLink.setHref(objectUri); objectLink.setRel(Relations.OBJECT); searchResult.getLinks().add(objectLink); result.add(searchResult); } } return result; } finally { Utils.getXWikiContext(componentManager).setDatabase(database); } }