本文整理汇总了Java中java.util.Formatter.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.toString方法的具体用法?Java Formatter.toString怎么用?Java Formatter.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Formatter
的用法示例。
在下文中一共展示了Formatter.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNotFoundMessage
import java.util.Formatter; //导入方法依赖的package包/类
private String buildNotFoundMessage(PluginRequest pluginRequest, Result result) {
if (result.notFoundList.isEmpty()) {
// this shouldn't happen, resolvers should call notFound()
return String.format("Plugin %s was not found", pluginRequest.getDisplayName());
} else {
Formatter sb = new Formatter();
sb.format("Plugin %s was not found in any of the following sources:%n", pluginRequest.getDisplayName());
for (NotFound notFound : result.notFoundList) {
sb.format("%n- %s", notFound.source);
if (notFound.detail != null) {
sb.format(" (%s)", notFound.detail);
}
}
return sb.toString();
}
}
示例2: failVersionCheck
import java.util.Formatter; //导入方法依赖的package包/类
private static void failVersionCheck(boolean exit, String reason, Object... args) {
Formatter errorMessage = new Formatter().format(reason, args);
String javaHome = System.getProperty("java.home");
String vmName = System.getProperty("java.vm.name");
errorMessage.format("Set the JVMCI_VERSION_CHECK environment variable to \"ignore\" to suppress ");
errorMessage.format("this error or to \"warn\" to emit a warning and continue execution.%n");
errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
errorMessage.format("Currently used VM configuration is: %s%n", vmName);
if (System.getProperty("java.specification.version").compareTo("1.9") < 0) {
errorMessage.format("Download the latest JVMCI JDK 8 from http://www.oracle.com/technetwork/oracle-labs/program-languages/downloads/index.html");
} else {
errorMessage.format("Download the latest JDK 9 build from https://jdk9.java.net/download/");
}
String value = System.getenv("JVMCI_VERSION_CHECK");
if ("warn".equals(value)) {
System.err.println(errorMessage.toString());
} else if ("ignore".equals(value)) {
return;
} else if (exit) {
System.err.println(errorMessage.toString());
System.exit(-1);
} else {
throw new InternalError(errorMessage.toString());
}
}
示例3: listArray
import java.util.Formatter; //导入方法依赖的package包/类
/**
* Generates a string holding the named definition
* of a 2D float array for Mathematica in the form
* name = {{A[0][0],...,A[0][m-1]},
* {A[1][0],...,A[1][m-1]}, ...,
* {A[n-1][0], A[n-1][1], ...,A[n-1][m-1]}};
* @param name the identifier to be used in Mathematica.
* @param A the array to be encoded (of length m).
* @return a String holding the Mathematica definition.
*/
public static String listArray(String name, float[][] A) {
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
String fs = PrintPrecision.getFormatStringFloat();
formatter.format(name + " = {");
for (int i = 0; i < A.length; i++) {
if (i == 0)
formatter.format("{");
else
formatter.format(", \n{");
for (int j = 0; j < A[i].length; j++) {
if (j == 0)
formatter.format(fs, A[j][i]);
else
formatter.format(", " + fs, A[j][i]);
}
formatter.format("}");
}
formatter.format("};\n");
String result = formatter.toString();
formatter.close();
return result;
}
示例4: toString
import java.util.Formatter; //导入方法依赖的package包/类
@Override
public String toString() {
// Output into coordinate format. Indices start from 1 instead of 0
Formatter out = new Formatter();
out.format("%10d %19d\n", size, Matrices.cardinality(this));
int i = 0;
for (VectorEntry e : this) {
if (e.get() != 0)
out.format("%10d % .12e\n", e.index() + 1, e.get());
if (++i == 100) {
out.format("...\n");
break;
}
}
return out.toString();
}
示例5: buildSensorControlCommand
import java.util.Formatter; //导入方法依赖的package包/类
/**
* build TDV string of the sensor control command
* @param info sensor info
* @param value command value
* @return TDV command string
*/
public static String buildSensorControlCommand(SensorInfo info, int value) {
Formatter formatter = new Formatter();
formatter.format("%02x", info.getType().getValueTDVTypes()[0]);
switch (info.getType()) {
case BUZZER:
formatter.format("%02x", ValueType.SHORT.getCode());
formatter.format("%04x", value);
break;
case LED:
formatter.format("%02x", ValueType.SHORT.getCode());
formatter.format("%04x", value);
break;
case DEVICE:
formatter.format("%02x", ValueType.INT.getCode());
formatter.format("%08x", value);
break;
default:
formatter.format("%02x", ValueType.BOOL.getCode());
formatter.format("%02x", value);
break;
}
String result = formatter.toString();
formatter.close();
return result;
}
示例6: checkDescriptorExists
import java.util.Formatter; //导入方法依赖的package包/类
/**
* Checks that a descriptor exists for this key after triggering loading of descriptors.
*/
protected boolean checkDescriptorExists() {
OptionKey.Lazy.init();
if (descriptor == null) {
Formatter buf = new Formatter();
buf.format("Could not find a descriptor for an option key. The most likely cause is " +
"a dependency on the %s annotation without a dependency on the " +
"org.graalvm.compiler.options.processor.OptionProcessor annotation processor.", Option.class.getName());
StackTraceElement[] stackTrace = new Exception().getStackTrace();
if (stackTrace.length > 2 &&
stackTrace[1].getClassName().equals(OptionKey.class.getName()) &&
stackTrace[1].getMethodName().equals("getValue")) {
String caller = stackTrace[2].getClassName();
buf.format(" In suite.py, add GRAAL_OPTIONS_PROCESSOR to the \"annotationProcessors\" attribute of the project " +
"containing %s.", caller);
}
throw new AssertionError(buf.toString());
}
return true;
}
示例7: toHexString
import java.util.Formatter; //导入方法依赖的package包/类
private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();
for (byte b : bytes) {
formatter.format("%02x", b);
}
return formatter.toString();
}
示例8: scheduleToString
import java.util.Formatter; //导入方法依赖的package包/类
private String scheduleToString(Schedule s) {
if(!s.open) {
return getContext().getString(R.string.lobby_schedule_closed);
}
Formatter f = new Formatter();
DateUtils.formatDateRange(getContext(), f, s.openTime, s.openTime, DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
f.format(getContext().getString(R.string.lobby_schedule_range_separator));
DateUtils.formatDateRange(getContext(), f, s.openTime + s.duration, s.openTime + s.duration, DateUtils.FORMAT_SHOW_TIME, Time.TIMEZONE_UTC);
return f.toString();
}
示例9: select
import java.util.Formatter; //导入方法依赖的package包/类
public <T extends ComponentResolutionState> T select(Collection<? extends T> candidates) {
Formatter formatter = new Formatter();
formatter.format("A conflict was found between the following modules:");
for (ComponentResolutionState candidate : candidates) {
formatter.format("%n - %s", candidate.getId());
}
throw new RuntimeException(formatter.toString());
}
示例10: getFourLineHexString
import java.util.Formatter; //导入方法依赖的package包/类
public static String getFourLineHexString(byte[] sha256Hash){
Formatter formatter = new Formatter();
for (int i = 0; i < 32; i++) {
formatter.format("%02X", sha256Hash[i]);
if (i == 7 || i == 15 || i == 23) {
formatter.format("\n");
} else if (i != 31) {
formatter.format(" ");
}
}
return formatter.toString();
}
示例11: getRuntime
import java.util.Formatter; //导入方法依赖的package包/类
/**
* Gets the singleton {@link JVMCIRuntime} instance available to the application.
*
* @throws UnsupportedOperationException if JVMCI is not supported
*/
public static JVMCIRuntime getRuntime() {
if (runtime == null) {
String javaHome = System.getProperty("java.home");
String vmName = System.getProperty("java.vm.name");
Formatter errorMessage = new Formatter();
errorMessage.format("The VM does not support the JVMCI API.%n");
errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
errorMessage.format("Currently used VM configuration is: %s", vmName);
throw new UnsupportedOperationException(errorMessage.toString());
}
return runtime;
}
示例12: byteToHex
import java.util.Formatter; //导入方法依赖的package包/类
private static String byteToHex(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash) {
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
示例13: toHexString
import java.util.Formatter; //导入方法依赖的package包/类
private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();
for (byte b : bytes) {
formatter.format("%02x", b);
}
String hexString = formatter.toString();
formatter.close();
return hexString;
}
示例14: checkNoConcurrentAccess
import java.util.Formatter; //导入方法依赖的package包/类
boolean checkNoConcurrentAccess() {
Thread currentThread = Thread.currentThread();
if (currentThread != thread) {
Formatter buf = new Formatter();
buf.format("Thread local %s object was created on thread %s but is being accessed by thread %s. The most likely cause is " +
"that the object is being retrieved from a non-thread-local cache.",
DebugContext.class.getName(), thread, currentThread);
int debugContextConstructors = 0;
boolean addedHeader = false;
for (StackTraceElement e : origin) {
if (e.getMethodName().equals("<init>") && e.getClassName().equals(DebugContext.class.getName())) {
debugContextConstructors++;
} else if (debugContextConstructors != 0) {
if (!addedHeader) {
addedHeader = true;
buf.format(" The object was instantiated here:");
}
// Distinguish from assertion stack trace by using double indent and
// "in" instead of "at" prefix.
buf.format("%n\t\tin %s", e);
}
}
if (addedHeader) {
buf.format("%n");
}
throw new AssertionError(buf.toString());
}
return true;
}
示例15: byteToHex
import java.util.Formatter; //导入方法依赖的package包/类
private static String byteToHex(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}