當前位置: 首頁>>代碼示例>>Java>>正文


Java Formatter.toString方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:19,代碼來源:DefaultPluginRequestApplicator.java

示例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());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:JVMCIVersionCheck.java

示例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;
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:34,代碼來源:MathematicaIO.java

示例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();
}
 
開發者ID:opprop-benchmarks,項目名稱:matrix-toolkits-java,代碼行數:20,代碼來源:AbstractVector.java

示例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;
}
 
開發者ID:SKT-ThingPlug,項目名稱:thingplug-app-android,代碼行數:32,代碼來源:TTVBuilder.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:OptionKey.java

示例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();
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:10,代碼來源:HmacSha1Signature.java

示例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();
}
 
開發者ID:gbl08ma,項目名稱:underlx,代碼行數:11,代碼來源:LobbyView.java

示例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());
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:9,代碼來源:StrictConflictResolver.java

示例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();
}
 
開發者ID:rootkiwi,項目名稱:an2linuxclient,代碼行數:13,代碼來源:Sha256Helper.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:JVMCI.java

示例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;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:10,代碼來源:WeiXinSignUtils.java

示例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;
}
 
開發者ID:fr31b3u73r,項目名稱:JodelAPI,代碼行數:10,代碼來源:JodelHelper.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:DebugContext.java

示例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;
}
 
開發者ID:Yunfeng,項目名稱:weixinpay,代碼行數:11,代碼來源:SignUtil.java


注:本文中的java.util.Formatter.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。