List of usage examples for java.util Formatter toString
public String toString()
From source file:org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState.java
/** * Publishes a value on MQTT. A command topic needs to be set in the configuration. * * @param command The command to send//from w w w. java 2 s . c o m * @return A future that completes with true if the publishing worked and false and/or exceptionally otherwise. */ public CompletableFuture<@Nullable Void> publishValue(Command command) { cachedValue.update(command); String mqttCommandValue = cachedValue.getMQTTpublishValue(); final MqttBrokerConnection connection = this.connection; if (!readOnly && connection != null) { // Formatter: Applied before the channel state value is published to the MQTT broker. if (config.formatBeforePublish.length() > 0) { try (Formatter formatter = new Formatter()) { Formatter format = formatter.format(config.formatBeforePublish, mqttCommandValue); mqttCommandValue = format.toString(); } catch (IllegalFormatException e) { logger.debug("Format pattern incorrect for {}", channelUID, e); } } // Send retained messages if this is a stateful channel return connection.publish(config.commandTopic, mqttCommandValue.getBytes(), 1, config.retained) .thenRun(() -> { }); } else { CompletableFuture<@Nullable Void> f = new CompletableFuture<>(); f.completeExceptionally(new IllegalStateException("No connection or readOnly channel!")); return f; } }
From source file:com.itemanalysis.psychometrics.factoranalysis.MINRESmethod.java
public String printStartValues() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); double[] start = getStartValues(); for (int i = 0; i < start.length; i++) { f.format("%8.4f", start[i]); f.format("%n"); }//w w w . java 2 s .c om return f.toString(); }
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 ww w .jav a 2s . c om*/ return f.toString(); }
From source file:org.openhab.binding.mqtt.generic.internal.generic.ChannelState.java
/** * Publishes a value on MQTT. A command topic needs to be set in the configuration. * * @param command The command to send//from w w w . j av a2 s .com * @return A future that completes with true if the publishing worked and false and/or exceptionally otherwise. */ public CompletableFuture<@Nullable Void> publishValue(Command command) { cachedValue.update(command); String mqttCommandValue = cachedValue.getMQTTpublishValue(); final MqttBrokerConnection connection = this.connection; if (!readOnly && connection != null) { // Formatter: Applied before the channel state value is published to the MQTT broker. if (config.formatBeforePublish.length() > 0) { try (Formatter formatter = new Formatter()) { Formatter format = formatter.format(config.formatBeforePublish, mqttCommandValue); mqttCommandValue = format.toString(); } catch (IllegalFormatException e) { logger.debug("Format pattern incorrect for {}", channelUID, e); } } // Outgoing transformations for (ChannelStateTransformation t : transformationsOut) { mqttCommandValue = t.processValue(mqttCommandValue); } // Send retained messages if this is a stateful channel return connection.publish(config.commandTopic, mqttCommandValue.getBytes(), 1, config.retained) .thenRun(() -> { }); } else { CompletableFuture<@Nullable Void> f = new CompletableFuture<>(); f.completeExceptionally(new IllegalStateException("No connection or readOnly channel!")); return f; } }
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"; }//www . j a va 2s.c o 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:org.xwiki.rest.internal.DomainObjectFactory.java
public static Object createObject(ObjectFactory objectFactory, URI baseUri, XWikiContext xwikiContext, Document doc, BaseObject xwikiObject, boolean useVersion, XWiki xwikiApi, Boolean withPrettyNames) throws XWikiException { Object object = objectFactory.createObject(); fillObjectSummary(object, objectFactory, baseUri, doc, xwikiObject, xwikiApi, withPrettyNames); 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 = objectFactory.createProperty(); for (java.lang.Object o : propertyClass.getProperties()) { BaseProperty baseProperty = (BaseProperty) o; Attribute attribute = 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 v a 2 s . c o m*/ 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 = 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()); if (xwikiObject.get(propertyClass.getName()) != null) { property.setValue(xwikiObject.get(propertyClass.getName()).toFormString()); } else { property.setValue(""); } String propertyUri; if (useVersion) { propertyUri = UriBuilder.fromUri(baseUri).path(ObjectPropertyAtPageVersionResource.class) .build(doc.getWiki(), doc.getSpace(), doc.getName(), doc.getVersion(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()) .toString(); } else { propertyUri = UriBuilder.fromUri(baseUri).path(ObjectPropertyResource.class) .build(doc.getWiki(), doc.getSpace(), doc.getName(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()) .toString(); } Link propertyLink = objectFactory.createLink(); propertyLink.setHref(propertyUri); propertyLink.setRel(Relations.SELF); property.getLinks().add(propertyLink); object.getProperties().add(property); } Link objectLink = getObjectLink(objectFactory, baseUri, doc, xwikiObject, useVersion, Relations.SELF); object.getLinks().add(objectLink); return object; }
From source file:org.openhab.binding.mqtt.generic.ChannelState.java
/** * Publishes a value on MQTT. A command topic needs to be set in the configuration. * * @param command The command to send/* w w w .j av a 2 s .c o m*/ * @return A future that completes with true if the publishing worked and false if it is a readonly topic * and exceptionally otherwise. */ public CompletableFuture<Boolean> publishValue(Command command) { cachedValue.update(command); String mqttCommandValue = cachedValue.getMQTTpublishValue(); final MqttBrokerConnection connection = this.connection; if (connection == null) { CompletableFuture<Boolean> f = new CompletableFuture<>(); f.completeExceptionally(new IllegalStateException( "The connection object has not been set. start() should have been called!")); return f; } if (readOnly) { logger.debug( "You have tried to publish {} to the mqtt topic '{}' that was marked read-only. You can't 'set' anything on a sensor state topic for example.", mqttCommandValue, config.commandTopic); return CompletableFuture.completedFuture(false); } // Formatter: Applied before the channel state value is published to the MQTT broker. if (config.formatBeforePublish.length() > 0) { try (Formatter formatter = new Formatter()) { Formatter format = formatter.format(config.formatBeforePublish, mqttCommandValue); mqttCommandValue = format.toString(); } catch (IllegalFormatException e) { logger.debug("Format pattern incorrect for {}", channelUID, e); } } // Outgoing transformations for (ChannelStateTransformation t : transformationsOut) { mqttCommandValue = t.processValue(mqttCommandValue); } // Send retained messages if this is a stateful channel return connection.publish(config.commandTopic, mqttCommandValue.getBytes(), 1, config.retained); }
From source file:org.apache.abdera.ext.gdata.GoogleLoginAuthScheme.java
protected String getAuth(String id, String pwd, String service) { try {// www . j ava 2 s .com AbderaClient abderaClient = new AbderaClient(); Formatter f = new Formatter(); f.format("Email=%s&Passwd=%s&service=%s&source=%s", URLEncoder.encode(id, "utf-8"), URLEncoder.encode(pwd, "utf-8"), (service != null) ? URLEncoder.encode(service, "utf-8") : "", URLEncoder.encode(Version.APP_NAME, "utf-8")); StringRequestEntity stringreq = new StringRequestEntity(f.toString(), "application/x-www-form-urlencoded", "utf-8"); String uri = "https://www.google.com/accounts/ClientLogin"; RequestOptions options = abderaClient.getDefaultRequestOptions(); options.setContentType("application/x-www-form-urlencoded"); ClientResponse response = abderaClient.post(uri, stringreq, options); InputStream in = response.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int n = -1; while ((n = in.read()) != -1) { out.write(n); } out.flush(); response.release(); String auth = new String(out.toByteArray()); return auth.split("\n")[2].replaceAll("Auth=", "auth="); } catch (Exception e) { } return null; }
From source file:com.itemanalysis.psychometrics.measurement.ClassicalItemStatistics.java
/** * A string that contains all of the item statistics. * * @return string of estimated statistics *///from w w w .j a v a2s .c om @Override public String toString() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("% 10.4f", getDifficulty()); f.format("%2s", " ");//category proportion endorsing f.format("% 10.4f", getStdDev()); f.format("%2s", " ");//category standard deviation f.format("% 10.4f", getDiscrimination()); f.format("%2s", " "); //item discrimination return f.toString(); }
From source file:com.imellon.android.vatchecker.VatCheckerActivity.java
/** * Request info./*w w w. j a va2s. c o m*/ * * @param keyphrase the keyphrase */ public void requestInfo(String keyphrase) { HttpPost httppost = new HttpPost("https://www1.gsis.gr/wsgsis/RgWsBasStoixN/RgWsBasStoixNSoapHttpPort"); try { InputStream inputStream = getResources().openRawResource(R.raw.gsisrequesttemplate); String envelope = convertInputStreamToString(inputStream); Formatter formatter = new Formatter(); formatter.format(envelope, keyphrase); envelope = formatter.toString(); StringEntity se = new StringEntity(envelope, HTTP.UTF_8); se.setContentType("text/xml"); httppost.setEntity(se); HttpEntity entity = null; HttpResponse response = sClient.execute(httppost); InputStream in = null; if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); in = entity.getContent(); } String retStr = convertInputStreamToString(in); AndroidXMLParser p = new AndroidXMLParser(retStr); message = p.parse(); updateViews(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }